BUG/MINOR: init: fix set-dumpable when using uid/gid

in mworker mode used with uid/gid settings, it was not possible to get
a coredump despite the set-dumpable option.
indeed prctl(2) manual page specifies the dumpable attribute is reverted
to `/proc/sys/fs/suid_dumpable` in a few conditions such as process
effective user and group are changed.

this patch moves the whole set-dumpable logic before the polling code in
order to catch all possible cases where we could have changed the
uid/gid. It however does not cover the possible segfault at startup.

this patch should be backported in 2.0.

Signed-off-by: William Dauchy <w.dauchy@criteo.com>
[wt: commit e039f26ba4 upstream]
Signed-off-by: Willy Tarreau <w@1wt.eu>
diff --git a/src/haproxy.c b/src/haproxy.c
index fa3fbad..a0e630d 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -2946,31 +2946,6 @@
 		}
 	}
 
-	/* try our best to re-enable core dumps depending on system capabilities.
-	 * What is addressed here :
-	 *   - remove file size limits
-	 *   - remove core size limits
-	 *   - mark the process dumpable again if it lost it due to user/group
-	 */
-	if (global.tune.options & GTUNE_SET_DUMPABLE) {
-		limit.rlim_cur = limit.rlim_max = RLIM_INFINITY;
-
-#if defined(RLIMIT_FSIZE)
-		if (setrlimit(RLIMIT_FSIZE, &limit) == -1)
-			ha_warning("[%s.main()] Failed to set the raise the maximum file size.\n", argv[0]);
-#endif
-
-#if defined(RLIMIT_CORE)
-		if (setrlimit(RLIMIT_CORE, &limit) == -1)
-			ha_warning("[%s.main()] Failed to set the raise the core dump size.\n", argv[0]);
-#endif
-
-#if defined(USE_PRCTL)
-		if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1)
-			ha_warning("[%s.main()] Failed to set the dumpable flag, no core will be dumped.\n", argv[0]);
-#endif
-	}
-
 	/* check ulimits */
 	limit.rlim_cur = limit.rlim_max = 0;
 	getrlimit(RLIMIT_NOFILE, &limit);
@@ -3253,6 +3228,31 @@
 		fork_poller();
 	}
 
+	/* try our best to re-enable core dumps depending on system capabilities.
+	 * What is addressed here :
+	 *   - remove file size limits
+	 *   - remove core size limits
+	 *   - mark the process dumpable again if it lost it due to user/group
+	 */
+	if (global.tune.options & GTUNE_SET_DUMPABLE) {
+		limit.rlim_cur = limit.rlim_max = RLIM_INFINITY;
+
+#if defined(RLIMIT_FSIZE)
+		if (setrlimit(RLIMIT_FSIZE, &limit) == -1)
+			ha_warning("[%s.main()] Failed to set the raise the maximum file size.\n", argv[0]);
+#endif
+
+#if defined(RLIMIT_CORE)
+		if (setrlimit(RLIMIT_CORE, &limit) == -1)
+			ha_warning("[%s.main()] Failed to set the raise the core dump size.\n", argv[0]);
+#endif
+
+#if defined(USE_PRCTL)
+		if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1)
+			ha_warning("[%s.main()] Failed to set the dumpable flag, no core will be dumped.\n", argv[0]);
+#endif
+	}
+
 	global.mode &= ~MODE_STARTING;
 	/*
 	 * That's it : the central polling loop. Run until we stop.