[asterisk-commits] tilghman: branch 1.6.1 r178344 - in /branches/1.6.1: ./ main/ utils/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Feb 24 14:08:20 CST 2009


Author: tilghman
Date: Tue Feb 24 14:08:19 2009
New Revision: 178344

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=178344
Log:
Merged revisions 178342 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

........
  r178342 | tilghman | 2009-02-24 14:06:48 -0600 (Tue, 24 Feb 2009) | 2 lines
  
  Use a SIGPIPE to kill the process, instead of depending upon the astcanary process being inherited by init.
........

Modified:
    branches/1.6.1/   (props changed)
    branches/1.6.1/main/asterisk.c
    branches/1.6.1/utils/astcanary.c

Propchange: branches/1.6.1/
------------------------------------------------------------------------------
Binary property 'trunk-merged' - no diff available.

Modified: branches/1.6.1/main/asterisk.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.6.1/main/asterisk.c?view=diff&rev=178344&r1=178343&r2=178344
==============================================================================
--- branches/1.6.1/main/asterisk.c (original)
+++ branches/1.6.1/main/asterisk.c Tue Feb 24 14:08:19 2009
@@ -259,6 +259,7 @@
 static pthread_t consolethread = AST_PTHREADT_NULL;
 static int canary_pid = 0;
 static char canary_filename[128];
+static int canary_pipe = -1;
 
 static char randompool[256];
 
@@ -3139,7 +3140,16 @@
 	if (isroot) {
 		ast_set_priority(ast_opt_high_priority);
 		if (ast_opt_high_priority) {
+			int cpipe[2];
+
+			/* PIPE signal ensures that astcanary dies when Asterisk dies */
+			pipe(cpipe);
+			canary_pipe = cpipe[0];
+
 			snprintf(canary_filename, sizeof(canary_filename), "%s/alt.asterisk.canary.tweet.tweet.tweet", ast_config_AST_RUN_DIR);
+
+			/* Don't let the canary child kill Asterisk, if it dies immediately */
+			signal(SIGPIPE, SIG_IGN);
 
 			canary_pid = fork();
 			if (canary_pid == 0) {
@@ -3148,9 +3158,14 @@
 
 				/* Reset signal handler */
 				signal(SIGCHLD, SIG_DFL);
-
-				for (fd = 0; fd < 100; fd++)
+				signal(SIGPIPE, SIG_DFL);
+
+				dup2(cpipe[1], 100);
+				close(cpipe[1]);
+
+				for (fd = 0; fd < 100; fd++) {
 					close(fd);
+				}
 
 				execlp("astcanary", "astcanary", canary_filename, (char *)NULL);
 
@@ -3165,6 +3180,7 @@
 				_exit(1);
 			} else if (canary_pid > 0) {
 				pthread_t dont_care;
+				close(cpipe[1]);
 				ast_pthread_create_detached(&dont_care, NULL, canary_thread, NULL);
 			}
 

Modified: branches/1.6.1/utils/astcanary.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.6.1/utils/astcanary.c?view=diff&rev=178344&r1=178343&r2=178344
==============================================================================
--- branches/1.6.1/utils/astcanary.c (original)
+++ branches/1.6.1/utils/astcanary.c Tue Feb 24 14:08:19 2009
@@ -89,7 +89,7 @@
 	int fd;
 	/* Run at normal priority */
 	setpriority(PRIO_PROCESS, 0, 0);
-	for (; getppid() != 1;) {
+	for (;;) {
 		/* Update the modification times (checked from Asterisk) */
 		if (utime(argv[1], NULL)) {
 			/* Recreate the file if it doesn't exist */
@@ -108,7 +108,7 @@
 		sleep(5);
 	}
 
-	/* Reached if asterisk (our parent process) dies - its chldren are inherited by the init process (pid is 1). */
+	/* Never reached */
 	return 0;
 }
 




More information about the asterisk-commits mailing list