From: Willy Tarreau Date: Fri, 10 Nov 2017 18:08:14 +0000 (+0100) Subject: CLEANUP: global: introduce variable pid_bit to avoid shifts with relative_pid X-Git-Tag: v1.8-rc3~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=387bd4f69f675d7e35895ce35d04a8270eec45b6;p=thirdparty%2Fhaproxy.git CLEANUP: global: introduce variable pid_bit to avoid shifts with relative_pid 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. --- diff --git a/include/types/global.h b/include/types/global.h index b3aa29cca4..48b6f9d84f 100644 --- a/include/types/global.h +++ b/include/types/global.h @@ -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) */ diff --git a/src/haproxy.c b/src/haproxy.c index 8993b89511..a22ed321f0 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -118,6 +118,7 @@ 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 diff --git a/src/listener.c b/src/listener.c index 2ac25fdc67..a6bd4497bd 100644 --- a/src/listener.c +++ b/src/listener.c @@ -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) { diff --git a/src/proxy.c b/src/proxy.c index 3af01efde5..ccbc7b22e7 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -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);