]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: mworker: make mworker_create_master_cli more readable
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Sat, 26 Oct 2024 13:03:19 +0000 (15:03 +0200)
committerValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Sat, 26 Oct 2024 20:26:49 +0000 (22:26 +0200)
Using nested 'if' operator, while checking if we will need to allocate again the
"reload" sockpair, does not degrade performance, as mworker_create_master_cli is
a startup routine.

This nested 'if' (we check one condition in each operator) makes more visible the
fact, that the "reload" sockpair is allocated only once, when the master process
starts and it does not re-allocated again (hence, its FDs are not closed) during
reloads. This way of checking multiple conditions here makes more easy to spot
this fact, while analysing the code in order to investigate FD leaks between
master and worker.

src/mworker.c

index 10f0cb183759846ca0e7a62b3cbd2e0be1962c21..b8daf2935bc1cf3a1031984555fcf39023e0d6b3 100644 (file)
@@ -908,10 +908,11 @@ void mworker_create_master_cli(void)
                 * Both FDs will be kept in the master. The sockets are
                 * created only if they weren't inherited.
                 */
-               if ((proc_self->ipc_fd[1] == -1) &&
-                    socketpair(AF_UNIX, SOCK_STREAM, 0, proc_self->ipc_fd) < 0) {
-                       ha_alert("Can't create the mcli_reload socketpair.\n");
-                       exit(EXIT_FAILURE);
+               if (proc_self->ipc_fd[1] == -1) {
+                       if (socketpair(AF_UNIX, SOCK_STREAM, 0, proc_self->ipc_fd) < 0) {
+                               ha_alert("Can't create the mcli_reload socketpair.\n");
+                               exit(EXIT_FAILURE);
+                       }
                }
 
                /* Create the mcli_reload listener from the proc_self struct */