]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Fix astcanary startup problem due to wrong pid value from before daemon call
authorMatthew Jordan <mjordan@digium.com>
Fri, 18 Jan 2013 23:26:02 +0000 (23:26 +0000)
committerMatthew Jordan <mjordan@digium.com>
Fri, 18 Jan 2013 23:26:02 +0000 (23:26 +0000)
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.

(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)

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@379509 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/asterisk.c

index afbc0ad3a86515a048810a2e408ea7542362beba..a0476d3bc8da7f357a98631c2b18823aae682738 100644 (file)
@@ -3756,6 +3756,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");
@@ -3812,11 +3814,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));