[asterisk-commits] mjordan: trunk r379518 - in /trunk: ./ main/asterisk.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jan 18 18:19:23 CST 2013


Author: mjordan
Date: Fri Jan 18 18:19:19 2013
New Revision: 379518

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=379518
Log:
Fix astcanary startup problem due to wrong pid value from before daemon call

When Asterisk forks itself into the background via a call to daemon, it must
re-set the pid value of the new process. Otherwise, astcanary gets the pid
value of the process before the fork, which prevents it from running. Asterisk
eventually starts lowering its priority, as it can no longer communicate
with the proverbial canary in the coal mine.

This patch ensures that the correct process identifier is used by astcanary.

Note that this is getting committed to 10 as a regression fix.

(closes issue ASTERISK-20947)
Reported by: Jakob Hirsch
Tested by: mjordan
patches:
  asterisk-10.12.0.astcanary_ppid.diff uploaded by Jakob Hirsch (license 6113)
........

Merged revisions 379509 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 379510 from http://svn.asterisk.org/svn/asterisk/branches/10
........

Merged revisions 379513 from http://svn.asterisk.org/svn/asterisk/branches/11

Modified:
    trunk/   (props changed)
    trunk/main/asterisk.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-11-merged' - no diff available.

Modified: trunk/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/asterisk.c?view=diff&rev=379518&r1=379517&r2=379518
==============================================================================
--- trunk/main/asterisk.c (original)
+++ trunk/main/asterisk.c Fri Jan 18 18:19:19 2013
@@ -3984,6 +3984,8 @@
 #ifndef HAVE_SBIN_LAUNCHD
 		if (daemon(1, 0) < 0) {
 			fprintf(stderr, "daemon() failed: %s\n", strerror(errno));
+		} else {
+			ast_mainpid = getpid();
 		}
 #else
 		fprintf(stderr, "Mac OS X detected.  Use 'launchctl load /Library/LaunchDaemon/org.asterisk.asterisk.plist'.\n");
@@ -4035,11 +4037,10 @@
 	}
 
 	/* Blindly write the PID file. */
-	ast_mainpid = getpid();
 	unlink(ast_config_AST_PID);
 	f = fopen(ast_config_AST_PID, "w");
 	if (f) {
-		fprintf(f, "%ld\n", (long)getpid());
+		fprintf(f, "%ld\n", (long)ast_mainpid);
 		fclose(f);
 	} else {
 		fprintf(stderr, "Unable to open pid file '%s': %s\n", ast_config_AST_PID, strerror(errno));




More information about the asterisk-commits mailing list