[asterisk-commits] russell: branch 1.2 r52903 - /branches/1.2/asterisk.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Jan 30 10:12:04 MST 2007


Author: russell
Date: Tue Jan 30 11:12:04 2007
New Revision: 52903

URL: http://svn.digium.com/view/asterisk?view=rev&rev=52903
Log:
The SIGHUP handler was implemented to allow admins to send SIGHUP to a running
Asterisk process to reload the configuration.  However, doing the actual reload
in the signal handler itself is a very bad thing to do, because the reload
process includes calling non-reentrant functions such as malloc/calloc/etc.
If Asterisk is running in the background, then the reload will happen
immediately.  However, if running in console mode, the reload doesn't work
until something is typed at the console.  That sort of defeats the purpose,
but I don't see an easy way to get around it at this point.

Modified:
    branches/1.2/asterisk.c

Modified: branches/1.2/asterisk.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/asterisk.c?view=diff&rev=52903&r1=52902&r2=52903
==============================================================================
--- branches/1.2/asterisk.c (original)
+++ branches/1.2/asterisk.c Tue Jan 30 11:12:04 2007
@@ -233,6 +233,8 @@
 static int shuttingdown = 0;
 static int restartnow = 0;
 static pthread_t consolethread = AST_PTHREADT_NULL;
+
+static unsigned int need_reload;
 
 #if !defined(LOW_MEMORY)
 struct file_version {
@@ -747,8 +749,7 @@
 		printf("Received HUP signal -- Reloading configs\n");
 	if (restartnow)
 		execvp(_argv[0], _argv);
-	/* XXX This could deadlock XXX */
-	ast_module_reload(NULL);
+	need_reload = 1;
 	signal(num, hup_handler);
 }
 
@@ -1816,6 +1817,11 @@
 				}
 			}
 		}
+
+		if (need_reload) {
+			need_reload = 0;
+			ast_module_reload(NULL);
+		}
 	}
 	printf("\nDisconnected from Asterisk server\n");
 }
@@ -2433,13 +2439,21 @@
 					break;
 				}
 			}
-		}
-
+			if (need_reload) {
+				need_reload = 0;
+				ast_module_reload(NULL);
+			}
+		}
 	}
 	/* Do nothing */
 	for(;;)  {	/* apparently needed for the MACos */
 		struct pollfd p = { -1 /* no descriptor */, 0, 0 };
 		poll(&p, 0, -1);
+		/* SIGHUP will cause this to break out of poll() */
+		if (need_reload) {
+			need_reload = 0;
+			ast_module_reload(NULL);
+		}
 	}
 	return 0;
 }



More information about the asterisk-commits mailing list