From: Matthew Jordan Date: Thu, 14 Feb 2013 15:14:53 +0000 (+0000) Subject: Fix astcanary startup problem due to wrong pid value from before daemon call X-Git-Tag: certified/11.2-cert1-rc1~2^2~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8390de25f56bf10a79e6748460eb5e6aa493e2c2;p=thirdparty%2Fasterisk.git 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 git-svn-id: https://origsvn.digium.com/svn/asterisk/certified/branches/11.2@381405 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/main/asterisk.c b/main/asterisk.c index 44ce274d1d..5d1b460479 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -3893,6 +3893,8 @@ int main(int argc, char *argv[]) #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"); @@ -3944,11 +3946,10 @@ int main(int argc, char *argv[]) } /* 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));