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

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/cmd-inet/usr.lib/in.ndpd/main.c
          +++ new/usr/src/cmd/cmd-inet/usr.lib/in.ndpd/main.c
↓ open down ↓ 917 lines elided ↑ open up ↑
 918  918           * after the fork(), as the it_value and it_interval values for
 919  919           * the ITIMER_REAL timer are reset to 0 in the child process.
 920  920           */
 921  921          if (getitimer(ITIMER_REAL, &it) < 0) {
 922  922                  if (debug & D_TIMER)
 923  923                          logmsg(LOG_DEBUG,
 924  924                              "daemonize_ndpd: failed to get itimerval\n");
 925  925                  timerval = _B_FALSE;
 926  926          }
 927  927  
      928 +        /* Open pid file, blow away any existing file if it exists. */
      929 +        if ((pidfp = fopen(PATH_PID, "w")) == NULL) {
      930 +                (void) fprintf(stderr, "%s: unable to open " PATH_PID ": %s\n",
      931 +                    argv0[0], strerror(errno));
      932 +        }
      933 +
 928  934          /* Daemonize. */
 929      -        switch (fork()) {
 930      -        case 0:
 931      -                /* Child */
 932      -                break;
 933      -        case -1:
      935 +        if (daemon(0, 0) == -1) {
 934  936                  logperror("fork");
 935  937                  exit(1);
 936      -        default:
 937      -                /* Parent */
 938      -                _exit(0);
 939  938          }
 940  939  
 941      -        /* Store our process id, blow away any existing file if it exists. */
 942      -        if ((pidfp = fopen(PATH_PID, "w")) == NULL) {
 943      -                (void) fprintf(stderr, "%s: unable to open " PATH_PID ": %s\n",
 944      -                    argv0[0], strerror(errno));
 945      -        } else {
      940 +        /* Store our process id */
      941 +        if (pidfp != NULL) {
 946  942                  (void) fprintf(pidfp, "%ld\n", getpid());
 947  943                  (void) fclose(pidfp);
 948  944                  (void) chmod(PATH_PID, pidmode);
 949  945          }
 950  946  
 951      -        (void) close(0);
 952      -        (void) close(1);
 953      -        (void) close(2);
 954      -
 955      -        (void) chdir("/");
 956      -        (void) open("/dev/null", O_RDWR);
 957      -        (void) dup2(0, 1);
 958      -        (void) dup2(0, 2);
 959      -        (void) setsid();
 960      -
 961  947          already_daemonized = _B_TRUE;
 962  948  
 963  949          /*
 964  950           * Restore timer values, if we were able to save them; if not,
 965  951           * check and set the right value by calling run_timeouts().
 966  952           */
 967  953          if (timerval) {
 968  954                  if (setitimer(ITIMER_REAL, &it, NULL) < 0) {
 969  955                          logperror("daemonize_ndpd: setitimer");
 970  956                          exit(2);
↓ open down ↓ 1647 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX