changeset 13890:dbad2fa7c9bb

3245 in.ndp daemon should not be session leader Reviewed by: Sebastien Roy <sebastien.roy@delphix.com> Reviewed by: Garrett D'Amore <garrett@damore.org> Approved by: Dan McDonald <danmcd@nexenta.com>
author David Höppner <0xffea@gmail.com>
date Sat, 24 Nov 2012 22:02:34 +0000
parents a67716f16746
children 4a1840e41e13
files usr/src/cmd/cmd-inet/usr.lib/in.ndpd/defs.h usr/src/cmd/cmd-inet/usr.lib/in.ndpd/main.c
diffstat 2 files changed, 1 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/cmd-inet/usr.lib/in.ndpd/defs.h	Fri Oct 26 13:33:52 2012 -0700
+++ b/usr/src/cmd/cmd-inet/usr.lib/in.ndpd/defs.h	Sat Nov 24 22:02:34 2012 +0000
@@ -71,7 +71,6 @@
 
 #define	CURHOP_UNSPECIFIED 0
 #define	PATH_NDPD_CONF	"/etc/inet/ndpd.conf"
-#define	PATH_PID	"/var/run/in.ndpd.pid"
 
 extern int debug, no_loopback;
 
--- a/usr/src/cmd/cmd-inet/usr.lib/in.ndpd/main.c	Fri Oct 26 13:33:52 2012 -0700
+++ b/usr/src/cmd/cmd-inet/usr.lib/in.ndpd/main.c	Sat Nov 24 22:02:34 2012 +0000
@@ -908,8 +908,6 @@
 static void
 daemonize_ndpd(void)
 {
-	FILE *pidfp;
-	mode_t pidmode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); /* 0644 */
 	struct itimerval it;
 	boolean_t timerval = _B_TRUE;
 
@@ -926,38 +924,11 @@
 	}
 
 	/* 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 {
-		(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;
 
 	/*
@@ -1415,7 +1386,6 @@
 
 		logmsg(LOG_ERR, "SIGHUP: restart and reread config file\n");
 		(void) execv(argv0[0], argv0);
-		(void) unlink(PATH_PID);
 		_exit(0177);
 		/* NOTREACHED */
 	case SIGUSR1:
@@ -1433,7 +1403,6 @@
 			phyint_delete(pi);
 		}
 		(void) unlink(NDPD_SNMP_SOCKET);
-		(void) unlink(PATH_PID);
 		exit(0);
 		/* NOTREACHED */
 	case 255: