]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: startup: close pidfd and free global.pidfile in handle_pidfile()
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Mon, 2 Dec 2024 15:04:56 +0000 (16:04 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 2 Dec 2024 16:28:04 +0000 (17:28 +0100)
After master-worker mode refactoring, global.pidfile is only used in
handle_pidfile(), which opens the provided file and writes the PID into it. So,
it's more appropriate to perform the close(pidfd) and ha_free(&global.pidfile)
also in this function.

This commit prepares the fix of the pidfile creation, as it's created now very
early, when we are not sure, that process has successfully started. In
master-worker mode handle_pidfile() can be called in the master process context.
So, let's make it accessible from other compilation units via global.h.

This should be backported only in 3.1.

include/haproxy/global.h
src/haproxy.c

index 72370c62dd3aa40bddc7238c350c35d9d0e456a1..13fbe7c7cd70cb258bfebdf679931bf93d9d36a0 100644 (file)
@@ -68,6 +68,7 @@ void hap_register_feature(const char *name);
 int split_version(const char *version, unsigned int *value);
 int compare_current_version(const char *version);
 void display_version();
+void handle_pidfile(void);
 
 void mworker_accept_wrapper(int fd);
 
index 06eaf61ffac0f3492a9a6e2503891f671f923d27..fd77f35454f0bdb6f4c75a8c3b3325b9defe7b45 100644 (file)
@@ -1777,7 +1777,7 @@ static void apply_daemon_mode()
 }
 
 /* Only returns if everything is OK. If something fails, it exits. */
-static void handle_pidfile()
+void handle_pidfile(void)
 {
        char pidstr[100];
 
@@ -1792,6 +1792,9 @@ static void handle_pidfile()
        }
        snprintf(pidstr, sizeof(pidstr), "%d\n", (int)getpid());
        DISGUISE(write(pidfd, pidstr, strlen(pidstr)));
+       close(pidfd);
+       /* We won't ever use this anymore */
+       ha_free(&global.pidfile);
 }
 
 static void get_listeners_fd()
@@ -2568,14 +2571,6 @@ static void step_init_4(void)
        clock_update_date(0, 1);
        clock_adjust_now_offset();
        ready_date = date;
-
-       /* close the pidfile both in children and father */
-       if (pidfd >= 0) {
-               //lseek(pidfd, 0, SEEK_SET);  /* debug: emulate eglibc bug */
-               close(pidfd);
-       }
-       /* We won't ever use this anymore */
-       ha_free(&global.pidfile);
 }
 
 /* This function sets verbosity modes. Should be called after the first