masqmail-0.2

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 diff
     1.1 --- a/src/masqmail.c	Wed Jun 16 10:35:13 2010 +0200
     1.2 +++ b/src/masqmail.c	Wed Jun 16 10:39:44 2010 +0200
     1.3 @@ -149,11 +149,14 @@
     1.4  		}
     1.5  	}
     1.6  
     1.7 -	if ((pid = fork()) > 0) {
     1.8 -		exit(EXIT_SUCCESS);
     1.9 -	} else if (pid < 0) {
    1.10 -		logwrite(LOG_ALERT, "could not fork!");
    1.11 -		exit(EXIT_FAILURE);
    1.12 +	/* reparent to init only if init is not already the parent */
    1.13 +	if (getppid() != 1) {
    1.14 +		if ((pid = fork()) > 0) {
    1.15 +			exit(EXIT_SUCCESS);
    1.16 +		} else if (pid < 0) {
    1.17 +			logwrite(LOG_ALERT, "could not fork!");
    1.18 +			exit(EXIT_FAILURE);
    1.19 +		}
    1.20  	}
    1.21  
    1.22  	signal(SIGTERM, sigterm_handler);
    1.23 @@ -188,11 +191,14 @@
    1.24  		}
    1.25  	}
    1.26  
    1.27 -	if ((pid = fork()) > 0) {
    1.28 -		exit(EXIT_SUCCESS);
    1.29 -	} else if (pid < 0) {
    1.30 -		logwrite(LOG_ALERT, "could not fork!");
    1.31 -		exit(EXIT_FAILURE);
    1.32 +	/* reparent to init only if init is not already the parent */
    1.33 +	if (getppid() != 1) {
    1.34 +		if ((pid = fork()) > 0) {
    1.35 +			exit(EXIT_SUCCESS);
    1.36 +		} else if (pid < 0) {
    1.37 +			logwrite(LOG_ALERT, "could not fork!");
    1.38 +			exit(EXIT_FAILURE);
    1.39 +		}
    1.40  	}
    1.41  
    1.42  	signal(SIGTERM, sigterm_handler);