aboutsummaryrefslogtreecommitdiffstats
path: root/asterisk.c
diff options
context:
space:
mode:
authorcitats <citats@f38db490-d61c-443f-a65b-d21fe96a405b>2004-02-23 03:43:21 +0000
committercitats <citats@f38db490-d61c-443f-a65b-d21fe96a405b>2004-02-23 03:43:21 +0000
commit2c362e444631b2183fbe0223a93120e1191a434f (patch)
tree103511308cda5b62eacd8107a86fb2537527beb3 /asterisk.c
parentaf3fd0b55d9dea49bc0b8170c396f86b3aa87901 (diff)
Fix restarting when not called from the main console (bug #830 and #864)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@2217 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'asterisk.c')
-rwxr-xr-xasterisk.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/asterisk.c b/asterisk.c
index b1be8c046..16dd17951 100755
--- a/asterisk.c
+++ b/asterisk.c
@@ -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);