]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Bad things happen when we mask all the signals
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 11 Jul 2018 20:13:54 +0000 (16:13 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 11 Jul 2018 20:13:54 +0000 (16:13 -0400)
Threads stick around forever if their parent dies ungracefully

src/lib/io/schedule.c

index 91c4d0c6fc5e7551b1442852bf25564161626c32..83cdf485249a0f48e36eb442e66bdb5aba16c213 100644 (file)
@@ -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;
        }