]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: init/threads: make the threads array global
authorWilly Tarreau <w@1wt.eu>
Fri, 3 May 2019 07:22:44 +0000 (09:22 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 3 May 2019 08:16:30 +0000 (10:16 +0200)
Currently the thread array is a local variable inside a function block
and there is no access to it from outside, which often complicates
debugging. Let's make it global and export it. Also the allocation
return is now checked.

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

index b2e79693bbae38adb00d647fd98a5a665e9f8e65..2df0da9b4045cb7383d179bc3b7372b2d72737db 100644 (file)
@@ -242,6 +242,7 @@ extern int master; /* 1 if in master, 0 otherwise */
 extern unsigned int rlim_fd_cur_at_boot;
 extern unsigned int rlim_fd_max_at_boot;
 extern int atexit_flag;
+__decl_hathreads(extern pthread_t *threads);
 
 /* bit values to go with "warned" above */
 #define WARN_BLOCK_DEPRECATED       0x00000001
index 43b2118e99aa361e8f736b202cfccf13cc732f0d..33f9453622c64e4745404c2783157df239562ff8 100644 (file)
@@ -139,6 +139,8 @@ int  relative_pid = 1;              /* process id starting at 1 */
 unsigned long pid_bit = 1;      /* bit corresponding to the process id */
 unsigned long all_proc_mask = 1; /* mask of all processes */
 
+__decl_hathreads(pthread_t *threads = NULL);
+
 volatile unsigned long sleeping_thread_mask; /* Threads that are about to sleep in poll() */
 /* global options */
 struct global global = {
@@ -3125,9 +3127,15 @@ int main(int argc, char **argv)
         */
 #ifdef USE_THREAD
        {
-               pthread_t    *threads = calloc(global.nbthread, sizeof(pthread_t));
-               int          i;
                sigset_t     blocked_sig, old_sig;
+               int          i;
+
+               threads = calloc(global.nbthread, sizeof(*threads));
+               if (!threads) {
+                       ha_alert("Cannot allocate memory for threads.\n");
+                       protocol_unbind_all();
+                       exit(1);
+               }
 
                /* ensure the signals will be blocked in every thread */
                sigfillset(&blocked_sig);
@@ -3182,6 +3190,7 @@ int main(int argc, char **argv)
                        pthread_join(threads[i], NULL);
 
                free(threads);
+               threads = NULL;
 
 #if defined(DEBUG_THREAD) || defined(DEBUG_FULL)
                show_lock_stats();