From: Arran Cudbard-Bell Date: Wed, 11 Jul 2018 20:13:54 +0000 (-0400) Subject: Bad things happen when we mask all the signals X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7bc1223744eec618ccb09d981dd87969bab176b7;p=thirdparty%2Ffreeradius-server.git Bad things happen when we mask all the signals Threads stick around forever if their parent dies ungracefully --- diff --git a/src/lib/io/schedule.c b/src/lib/io/schedule.c index 91c4d0c6fc5..83cdf485249 100644 --- a/src/lib/io/schedule.c +++ b/src/lib/io/schedule.c @@ -139,11 +139,6 @@ struct fr_schedule_t { fr_schedule_network_t *sn; //!< pointer to the (one) network thread }; -typedef struct { - void *(*func)(void *); - void *arg; -} fr_schedule_entry_point_t; - static _Thread_local int worker_id; //!< Internal ID of the current worker thread. /** Return the worker id for the current thread @@ -307,34 +302,6 @@ fail: return NULL; } -/** Wrapper to set the signal mask on newly created threads - * - */ -static void *schedule_pthread_entry(void *arg) -{ - fr_schedule_entry_point_t *ep = arg; - sigset_t sig_mask; /* signals to block */ - void *ret; - - /* - * We generally use kqueue to signal threads so we - * need to mask all the signals to prevent them from - * being delivered to something that shouldn't be - * processing them. - */ - sigfillset(&sig_mask); - - if (pthread_sigmask(SIG_BLOCK, &sig_mask, NULL) != 0) { - free(arg); /* Free memory our parent allocated */ - return NULL; - } - - ret = ep->func(ep->arg); - free(arg); /* Free memory our parent allocated */ - - return ret; -} - /** Creates a new thread using our standard set of options * * New threads are: @@ -352,7 +319,6 @@ int fr_schedule_pthread_create(pthread_t *thread, void *(*func)(void *), void *a { pthread_attr_t attr; int ret; - fr_schedule_entry_point_t *ep; /* * Set the thread to wait around after it's exited @@ -364,13 +330,8 @@ int fr_schedule_pthread_create(pthread_t *thread, void *(*func)(void *), void *a pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); - ep = malloc(sizeof(fr_schedule_entry_point_t)); /* MUST be malloc - would corrupt NULL ctx */ - ep->func = func; - ep->arg = arg; - - ret = pthread_create(thread, &attr, schedule_pthread_entry, ep); + ret = pthread_create(thread, &attr, func, arg); if (ret != 0) { - free(ep); fr_strerror_printf("Failed creating thread: %s", fr_syserror(ret)); return -1; }