Mercurial > masqmail-0.2
comparison src/masqmail.c @ 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 | 3b344bf57162 |
comparison
equal
deleted
inserted
replaced
73:9db75b801dc4 | 74:0a5b2e96ade3 |
---|---|
147 fprintf(stderr, "must be root or %s for daemon.\n", DEF_MAIL_USER); | 147 fprintf(stderr, "must be root or %s for daemon.\n", DEF_MAIL_USER); |
148 exit(EXIT_FAILURE); | 148 exit(EXIT_FAILURE); |
149 } | 149 } |
150 } | 150 } |
151 | 151 |
152 if ((pid = fork()) > 0) { | 152 /* reparent to init only if init is not already the parent */ |
153 exit(EXIT_SUCCESS); | 153 if (getppid() != 1) { |
154 } else if (pid < 0) { | 154 if ((pid = fork()) > 0) { |
155 logwrite(LOG_ALERT, "could not fork!"); | 155 exit(EXIT_SUCCESS); |
156 exit(EXIT_FAILURE); | 156 } else if (pid < 0) { |
157 logwrite(LOG_ALERT, "could not fork!"); | |
158 exit(EXIT_FAILURE); | |
159 } | |
157 } | 160 } |
158 | 161 |
159 signal(SIGTERM, sigterm_handler); | 162 signal(SIGTERM, sigterm_handler); |
160 write_pidfile(PIDFILEDIR "/masqmail.pid"); | 163 write_pidfile(PIDFILEDIR "/masqmail.pid"); |
161 | 164 |
186 fprintf(stderr, "must be root or %s for daemon.\n", DEF_MAIL_USER); | 189 fprintf(stderr, "must be root or %s for daemon.\n", DEF_MAIL_USER); |
187 exit(EXIT_FAILURE); | 190 exit(EXIT_FAILURE); |
188 } | 191 } |
189 } | 192 } |
190 | 193 |
191 if ((pid = fork()) > 0) { | 194 /* reparent to init only if init is not already the parent */ |
192 exit(EXIT_SUCCESS); | 195 if (getppid() != 1) { |
193 } else if (pid < 0) { | 196 if ((pid = fork()) > 0) { |
194 logwrite(LOG_ALERT, "could not fork!"); | 197 exit(EXIT_SUCCESS); |
195 exit(EXIT_FAILURE); | 198 } else if (pid < 0) { |
199 logwrite(LOG_ALERT, "could not fork!"); | |
200 exit(EXIT_FAILURE); | |
201 } | |
196 } | 202 } |
197 | 203 |
198 signal(SIGTERM, sigterm_handler); | 204 signal(SIGTERM, sigterm_handler); |
199 write_pidfile(PIDFILEDIR "/masqmail-get.pid"); | 205 write_pidfile(PIDFILEDIR "/masqmail-get.pid"); |
200 | 206 |