Report proper pid when forking
authorMark Spencer <markster@digium.com>
Thu, 16 Oct 2003 10:27:41 +0000 (10:27 +0000)
committerMark Spencer <markster@digium.com>
Thu, 16 Oct 2003 10:27:41 +0000 (10:27 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@1634 65c4cc65-6c06-0410-ace0-fbb531ad65f3

asterisk.c

index ac7173f..f419ac5 100755 (executable)
@@ -1351,18 +1351,15 @@ int main(int argc, char *argv[])
                ast_log(LOG_WARNING, "Unable to open pid file '%s': %s\n", (char *)ast_config_AST_PID, strerror(errno));
 
        if (!option_verbose && !option_debug && !option_nofork && !option_console) {
-#if 1
                daemon(0,0);
-#else  
-               pid = fork();
-               if (pid < 0) {
-                       ast_log(LOG_ERROR, "Unable to fork(): %s\n", strerror(errno));
-                       printf(term_quit());
-                       exit(1);
-               }
-               if (pid) 
-                       exit(0);
-#endif                 
+               /* Blindly re-write pid file since we are forking */
+               unlink((char *)ast_config_AST_PID);
+               f = fopen((char *)ast_config_AST_PID, "w");
+               if (f) {
+                       fprintf(f, "%d\n", getpid());
+                       fclose(f);
+               } else
+                       ast_log(LOG_WARNING, "Unable to open pid file '%s': %s\n", (char *)ast_config_AST_PID, strerror(errno));
        }
 
        ast_makesocket();