From 02af1fe067f73cece99cf92386b3551b3932b665 Mon Sep 17 00:00:00 2001 From: Valentine Krasnobaeva Date: Thu, 4 Jul 2024 15:51:12 +0200 Subject: [PATCH] MEDIUM: startup: call chroot() if needed in one place There are two 'chroot' code blocks, both under quite same: 'if ((global.mode & (MODE_MWORKER|MODE_DAEMON...)...' The first block serves to perform chroot only for process in the foreground mode. The second comes after master-worker fork and allows to do chroot in daemon and in worker modes. Due to moving the master-worker fork in init() in some previous commit, the second 'chroot' code block now is no longer under the 'if'. So, it is executed for all modes, except MODE_MWORKER. Now in MODE_MWORKER process enters in its wait polling loop just after forking a worker and it terminates almost immediately, if it exits this loop. Worker, daemon and process in a foreground mode will perform the chroot as before, but now it will be done in a one place at main(). --- src/haproxy.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/haproxy.c b/src/haproxy.c index 8b2ba8934..79e417a6f 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -3502,21 +3502,6 @@ int main(int argc, char **argv) } } - - if ((global.mode & (MODE_MWORKER|MODE_DAEMON)) == 0) { - - /* chroot if needed */ - if (global.chroot != NULL) { - if (chroot(global.chroot) == -1 || chdir("/") == -1) { - ha_alert("[%s.main()] Cannot chroot(%s).\n", argv[0], global.chroot); - if (nb_oldpids) - tell_old_pids(SIGTTIN); - protocol_unbind_all(); - exit(1); - } - } - } - if (nb_oldpids && !(global.mode & MODE_MWORKER_WAIT)) nb_oldpids = tell_old_pids(oldpids_sig);