Commits

Bryan O'Sullivan committed 1284c66

Fix longstanding pid writing bug.
Reported by many people; fix actually prompted by mail from
Philipp Matthias Hahn <pmhahn@debian.org>.

Comments (0)

Files changed (1)

     if (!foreground) {
         use_syslog = 1;
         openlog("netplugd", LOG_PID, LOG_DAEMON);
-
-        if (pid_file) {
-            atexit(tidy_pid);
-            write_pid();
-        }
     }
 
     if (pipe(child_handler_pipe) == -1) {
         exit(1);
     }
 
-    if (!foreground && daemon(0, 0) == -1) {
-        do_log(LOG_ERR, "daemon: %m");
-        exit(1);
+    if (!foreground) {
+	if (daemon(0, 0) == -1) {
+	    do_log(LOG_ERR, "daemon: %m");
+	    exit(1);
+	}
+
+        if (pid_file) {
+            atexit(tidy_pid);
+            write_pid();
+        }
     }
 
     struct pollfd fds[] = {