BUG/MINOR: mworker: does not erase the pidfile upon reload
authorWilliam Lallemand <wlallemand@haproxy.org>
Mon, 14 Feb 2022 08:02:14 +0000 (09:02 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 25 Feb 2022 13:23:56 +0000 (14:23 +0100)
When started in master-worker mode combined with daemon mode, HAProxy
will open() with O_TRUNC the pidfile when switching to wait mode.

In 2.5, it happens  everytime after trying to load the configuration,
since we switch to wait mode.

In previous version this happens upon a failure of the configuration
loading.

Fixes bug #1545.

Must be backported in every supported branches.

(cherry picked from commit 7b820a6191736cdf4167d624b7bcab9957dd0697)
Signed-off-by: William Lallemand <wlallemand@haproxy.org>
(cherry picked from commit c468633a3ad12d33bf9bf3d7ac139b22bf0997bb)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit 7af8e1da1abf31612cb8df448853ba9ee38d3113)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

src/haproxy.c

index 9ed19c7..179c96c 100644 (file)
@@ -3325,7 +3325,8 @@ int main(int argc, char **argv)
        }
 
        /* open log & pid files before the chroot */
-       if ((global.mode & MODE_DAEMON || global.mode & MODE_MWORKER) && global.pidfile != NULL) {
+       if ((global.mode & MODE_DAEMON || global.mode & MODE_MWORKER) &&
+           !(global.mode & MODE_MWORKER_WAIT) && global.pidfile != NULL) {
                unlink(global.pidfile);
                pidfd = open(global.pidfile, O_CREAT | O_WRONLY | O_TRUNC, 0644);
                if (pidfd < 0) {