[MEDIUM] fixed call to chroot() during startup
It wasn't very wise to chroot() early during the startup. Also,
the exit() was missing if the chroot() failed.
diff --git a/src/haproxy.c b/src/haproxy.c
index 7b7a691..4e819a3 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -870,16 +870,6 @@
pidfile = fdopen(pidfd, "w");
}
- /* chroot if needed */
- if (global.chroot != NULL) {
- if (chroot(global.chroot) == -1) {
- Alert("[%s.main()] Cannot chroot(%s).\n", argv[0], global.chroot);
- if (nb_oldpids)
- tell_old_pids(SIGTTIN);
- }
- chdir("/");
- }
-
/* ulimits */
if (!global.rlimit_nofile)
global.rlimit_nofile = global.maxsock;
@@ -940,6 +930,17 @@
exit(1);
}
+ /* chroot if needed */
+ if (global.chroot != NULL) {
+ if (chroot(global.chroot) == -1) {
+ Alert("[%s.main()] Cannot chroot(%s).\n", argv[0], global.chroot);
+ if (nb_oldpids)
+ tell_old_pids(SIGTTIN);
+ exit(1);
+ }
+ chdir("/");
+ }
+
if (nb_oldpids)
tell_old_pids(oldpids_sig);