# HG changeset patch # User meillo@marmaro.de # Date 1276677584 -7200 # Node ID 0a5b2e96ade371018b9a0d7707a4b51dff2cc1cf # Parent 9db75b801dc47b58a91878f662ec23038c55ea38 do not reparent the daemon to init if init is already the parent diff -r 9db75b801dc4 -r 0a5b2e96ade3 src/masqmail.c --- 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);