]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: global: introduce variable pid_bit to avoid shifts with relative_pid
authorWilly Tarreau <w@1wt.eu>
Fri, 10 Nov 2017 18:08:14 +0000 (19:08 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 10 Nov 2017 18:08:14 +0000 (19:08 +0100)
At a number of places, bitmasks are used for process affinity and to map
listeners to processes. Every time 1UL<<(relative_pid-1) is used. Let's
create a "pid_bit" variable corresponding to this value to clean this up.

include/types/global.h
src/haproxy.c
src/listener.c
src/proxy.c

index b3aa29cca46239d24c43d2feee0f952c2a2b47ba..48b6f9d84f2f5875397bb44de2a03b68bae4f046 100644 (file)
@@ -176,6 +176,7 @@ struct global {
 extern struct global global;
 extern int  pid;                /* current process id */
 extern int  relative_pid;       /* process id starting at 1 */
+extern unsigned long pid_bit;   /* bit corresponding to the process id */
 extern int  actconn;            /* # of active sessions */
 extern int  listeners;
 extern int  jobs;               /* # of active jobs (listeners, sessions, open devices) */
index 8993b89511f4f5f109dcb4661f0926297abb8e0b..a22ed321f0392ced492c9f8af1f563d681846c33 100644 (file)
 static struct list cfg_cfgfiles = LIST_HEAD_INIT(cfg_cfgfiles);
 int  pid;                      /* current process id */
 int  relative_pid = 1;         /* process id starting at 1 */
+unsigned long pid_bit = 1;      /* bit corresponding to the process id */
 
 /* global options */
 struct global global = {
@@ -2655,6 +2656,7 @@ int main(int argc, char **argv)
                                shut_your_big_mouth_gcc(write(pidfd, pidstr, strlen(pidstr)));
                        }
                        relative_pid++; /* each child will get a different one */
+                       pid_bit <<= 1;
                }
 
 #ifdef USE_CPU_AFFINITY
index 2ac25fdc67027f7035c249c6d39a92207d816c1f..a6bd4497bded621f6603fadb82bdb0bbb00001df 100644 (file)
@@ -64,7 +64,7 @@ static void enable_listener(struct listener *listener)
        if (listener->state == LI_LISTEN) {
                if ((global.mode & (MODE_DAEMON | MODE_MWORKER)) &&
                    listener->bind_conf->bind_proc &&
-                   !(listener->bind_conf->bind_proc & (1UL << (relative_pid - 1)))) {
+                   !(listener->bind_conf->bind_proc & pid_bit)) {
                        /* we don't want to enable this listener and don't
                         * want any fd event to reach it.
                         */
@@ -168,7 +168,7 @@ static int __resume_listener(struct listener *l)
 
        if ((global.mode & (MODE_DAEMON | MODE_MWORKER)) &&
            l->bind_conf->bind_proc &&
-           !(l->bind_conf->bind_proc & (1UL << (relative_pid - 1))))
+           !(l->bind_conf->bind_proc & pid_bit))
                goto end;
 
        if (l->state == LI_ASSIGNED) {
index 3af01efde5519ed9850084b4637566d0ce88da2d..ccbc7b22e71708cfb9289562017b65be4c09d2a2 100644 (file)
@@ -1431,7 +1431,7 @@ static int dump_servers_state(struct stream_interface *si, struct chunk *buf)
        int bk_f_forced_id, srv_f_forced_id;
 
        /* we don't want to report any state if the backend is not enabled on this process */
-       if (px->bind_proc && !(px->bind_proc & (1UL << (relative_pid - 1))))
+       if (px->bind_proc && !(px->bind_proc & pid_bit))
                return 1;
 
        if (!appctx->ctx.cli.p1)
@@ -1546,7 +1546,7 @@ static int cli_io_handler_show_backend(struct appctx *appctx)
                        continue;
 
                /* we don't want to list a backend which is bound to this process */
-               if (curproxy->bind_proc && !(curproxy->bind_proc & (1UL << (relative_pid - 1))))
+               if (curproxy->bind_proc && !(curproxy->bind_proc & pid_bit))
                        continue;
 
                chunk_appendf(&trash, "%s\n", curproxy->id);