[Asterisk-cvs] asterisk asterisk.c,1.51,1.52

citats at lists.digium.com citats at lists.digium.com
Sun Feb 22 22:55:14 CST 2004


Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv18226

Modified Files:
	asterisk.c 
Log Message:
Fix restarting when not called from the main console (bug #830 and #864)


Index: asterisk.c
===================================================================
RCS file: /usr/cvsroot/asterisk/asterisk.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- asterisk.c	28 Jan 2004 21:32:48 -0000	1.51
+++ asterisk.c	23 Feb 2004 03:43:21 -0000	1.52
@@ -106,6 +106,11 @@
 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 @@
 {
 	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 @@
 	return 0;
 }
 
-static char *_argv[256];
-
-static int shuttingdown = 0;
-
 static void ast_run_atexits(void)
 {
 	struct ast_atexit *ae;
@@ -536,7 +539,14 @@
 		}
 		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 @@
 	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 @@
 	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 @@
 		set_title(title);
 	    ast_cli_register(&quit);
 	    ast_cli_register(&astexit);
-		consolethread = pthread_self();
 
 		for (;;) {
 			buf = (char *)el_gets(el, &num);




More information about the svn-commits mailing list