From: Russell Bryant Date: Tue, 30 Jan 2007 17:12:04 +0000 (+0000) Subject: The SIGHUP handler was implemented to allow admins to send SIGHUP to a running X-Git-Tag: 1.2.15~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=65a8360531ca77d66eca15699d5880b3896a4a1a;p=thirdparty%2Fasterisk.git 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. git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.2@52903 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/asterisk.c b/asterisk.c index d3b3989dea..763f56a888 100644 --- a/asterisk.c +++ b/asterisk.c @@ -234,6 +234,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 { AST_LIST_ENTRY(file_version) list; @@ -747,8 +749,7 @@ static void hup_handler(int num) 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 @@ static void ast_remotecontrol(char * data) } } } + + if (need_reload) { + need_reload = 0; + ast_module_reload(NULL); + } } printf("\nDisconnected from Asterisk server\n"); } @@ -2433,13 +2439,21 @@ int main(int argc, char *argv[]) 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; }