Print this page
3245 in.ndp daemon should not be session leader

@@ -923,43 +923,29 @@
                         logmsg(LOG_DEBUG,
                             "daemonize_ndpd: failed to get itimerval\n");
                 timerval = _B_FALSE;
         }
 
+        /* Open pid file, blow away any existing file if it exists. */
+        if ((pidfp = fopen(PATH_PID, "w")) == NULL) {
+                (void) fprintf(stderr, "%s: unable to open " PATH_PID ": %s\n",
+                    argv0[0], strerror(errno));
+        }
+
         /* Daemonize. */
-        switch (fork()) {
-        case 0:
-                /* Child */
-                break;
-        case -1:
+        if (daemon(0, 0) == -1) {
                 logperror("fork");
                 exit(1);
-        default:
-                /* Parent */
-                _exit(0);
         }
 
-        /* Store our process id, blow away any existing file if it exists. */
-        if ((pidfp = fopen(PATH_PID, "w")) == NULL) {
-                (void) fprintf(stderr, "%s: unable to open " PATH_PID ": %s\n",
-                    argv0[0], strerror(errno));
-        } else {
+        /* Store our process id */
+        if (pidfp != NULL) {
                 (void) fprintf(pidfp, "%ld\n", getpid());
                 (void) fclose(pidfp);
                 (void) chmod(PATH_PID, pidmode);
         }
 
-        (void) close(0);
-        (void) close(1);
-        (void) close(2);
-
-        (void) chdir("/");
-        (void) open("/dev/null", O_RDWR);
-        (void) dup2(0, 1);
-        (void) dup2(0, 2);
-        (void) setsid();
-
         already_daemonized = _B_TRUE;
 
         /*
          * Restore timer values, if we were able to save them; if not,
          * check and set the right value by calling run_timeouts().