Fix restarting when not called from the main console (bug #830 and #864)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@2217 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
James Golovich 2004-02-23 03:43:21 +00:00
parent c278f09897
commit a06b48ccc6
1 changed files with 17 additions and 8 deletions

View File

@ -106,6 +106,11 @@ char ast_config_AST_PID[AST_CONFIG_MAX_PATH];
char ast_config_AST_SOCKET[AST_CONFIG_MAX_PATH];
char ast_config_AST_RUN_DIR[AST_CONFIG_MAX_PATH];
static char *_argv[256];
static int shuttingdown = 0;
static int restartnow = 0;
static pthread_t consolethread = (pthread_t) -1;
int ast_register_atexit(void (*func)(void))
{
int res = -1;
@ -365,6 +370,8 @@ static void hup_handler(int num)
{
if (option_verbose > 1)
printf("Received HUP signal -- Reloading configs\n");
if (restartnow)
execvp(_argv[0], _argv);
/* XXX This could deadlock XXX */
ast_module_reload();
}
@ -436,10 +443,6 @@ static int set_priority(int pri)
return 0;
}
static char *_argv[256];
static int shuttingdown = 0;
static void ast_run_atexits(void)
{
struct ast_atexit *ae;
@ -536,7 +539,14 @@ static void quit_handler(int num, int nice, int safeshutdown, int restart)
}
if (option_verbose || option_console)
ast_verbose("Restarting Asterisk NOW...\n");
execvp(_argv[0], _argv);
restartnow = 1;
/* If there is a consolethread running send it a SIGHUP
so it can execvp, otherwise we can do it ourselves */
if (consolethread != (pthread_t) -1)
pthread_kill(consolethread, SIGHUP);
else
execvp(_argv[0], _argv);
}
exit(0);
}
@ -546,8 +556,6 @@ static void __quit_handler(int num)
quit_handler(num, 0, 1, 0);
}
static pthread_t consolethread = (pthread_t) -1;
static const char *fix_header(char *outbuf, int maxout, const char *s, char *cmp)
{
const char *c;
@ -1476,6 +1484,8 @@ int main(int argc, char *argv[])
ast_cli_register(&astshutdownwhenconvenient);
ast_cli_register(&aborthalt);
ast_cli_register(&astbang);
if (option_nofork)
consolethread = pthread_self();
if (option_console) {
/* Console stuff now... */
/* Register our quit function */
@ -1485,7 +1495,6 @@ int main(int argc, char *argv[])
set_title(title);
ast_cli_register(&quit);
ast_cli_register(&astexit);
consolethread = pthread_self();
for (;;) {
buf = (char *)el_gets(el, &num);