changeset 74:0a5b2e96ade3

do not reparent the daemon to init if init is already the parent
author meillo@marmaro.de
date Wed, 16 Jun 2010 10:39:44 +0200
parents 9db75b801dc4
children 257a9e6d1a8e
files src/masqmail.c
diffstat 1 files changed, 16 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/masqmail.c	Wed Jun 16 10:35:13 2010 +0200
+++ b/src/masqmail.c	Wed Jun 16 10:39:44 2010 +0200
@@ -149,11 +149,14 @@
 		}
 	}
 
-	if ((pid = fork()) > 0) {
-		exit(EXIT_SUCCESS);
-	} else if (pid < 0) {
-		logwrite(LOG_ALERT, "could not fork!");
-		exit(EXIT_FAILURE);
+	/* reparent to init only if init is not already the parent */
+	if (getppid() != 1) {
+		if ((pid = fork()) > 0) {
+			exit(EXIT_SUCCESS);
+		} else if (pid < 0) {
+			logwrite(LOG_ALERT, "could not fork!");
+			exit(EXIT_FAILURE);
+		}
 	}
 
 	signal(SIGTERM, sigterm_handler);
@@ -188,11 +191,14 @@
 		}
 	}
 
-	if ((pid = fork()) > 0) {
-		exit(EXIT_SUCCESS);
-	} else if (pid < 0) {
-		logwrite(LOG_ALERT, "could not fork!");
-		exit(EXIT_FAILURE);
+	/* reparent to init only if init is not already the parent */
+	if (getppid() != 1) {
+		if ((pid = fork()) > 0) {
+			exit(EXIT_SUCCESS);
+		} else if (pid < 0) {
+			logwrite(LOG_ALERT, "could not fork!");
+			exit(EXIT_FAILURE);
+		}
 	}
 
 	signal(SIGTERM, sigterm_handler);