mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 06:11:32 +02:00
MINOR: startup: refactor "daemonization" fork
Let's put "daemonization" fork into a switch-case. This is more readable and we don't need to allocate memory for the fork() return value here.
This commit is contained in:
parent
90b8181c0a
commit
95c19be2ab
@ -2121,14 +2121,22 @@ static void init(int argc, char **argv)
|
|||||||
if ((getenv("HAPROXY_MWORKER_REEXEC") == NULL) &&
|
if ((getenv("HAPROXY_MWORKER_REEXEC") == NULL) &&
|
||||||
(global.mode & MODE_DAEMON)) {
|
(global.mode & MODE_DAEMON)) {
|
||||||
ret = fork();
|
ret = fork();
|
||||||
if (ret < 0) {
|
switch(ret) {
|
||||||
|
case -1:
|
||||||
ha_alert("[%s.main()] Cannot fork.\n", argv[0]);
|
ha_alert("[%s.main()] Cannot fork.\n", argv[0]);
|
||||||
protocol_unbind_all();
|
protocol_unbind_all();
|
||||||
exit(1); /* there has been an error */
|
exit(1); /* there has been an error */
|
||||||
} else if (ret > 0) { /* parent leave to daemonize */
|
case 0:
|
||||||
exit(0);
|
/* in child, change the process group ID, in the master-worker
|
||||||
} else /* change the process group ID in the child (master process) */
|
* mode, this will be the master process
|
||||||
|
*/
|
||||||
setsid();
|
setsid();
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
/* in parent, which leaves to daemonize */
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (global.mode & (MODE_MWORKER|MODE_MWORKER_WAIT))
|
if (global.mode & (MODE_MWORKER|MODE_MWORKER_WAIT))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user