Print this page
NEX-19665 Several door servers don't properly handle exiting threads
Review by: Gordon Ross <gordon.ross@nexenta.com>
Review by: Evan Layton <evan.layton@nexenta.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/nscd/nscd_frontend.c
          +++ new/usr/src/cmd/nscd/nscd_frontend.c
↓ open down ↓ 14 lines elided ↑ open up ↑
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
  24   24   * Copyright 2012 Milan Jurik. All rights reserved.
       25 + * Copyright 2019 Nexenta Systems, Inc.
  25   26   */
  26   27  
  27   28  #include <stdlib.h>
  28   29  #include <alloca.h>
  29   30  #include <signal.h>
  30   31  #include <sys/stat.h>
  31   32  #include <unistd.h>
  32   33  #include <pthread.h>
  33   34  #include <time.h>
  34   35  #include <errno.h>
↓ open down ↓ 45 lines elided ↑ open up ↑
  80   81  
  81   82  /*
  82   83   * Bind a TSD value to a server thread. This enables the destructor to
  83   84   * be called if/when this thread exits.  This would be a programming
  84   85   * error, but better safe than sorry.
  85   86   */
  86   87  /*ARGSUSED*/
  87   88  static void *
  88   89  server_tsd_bind(void *arg)
  89   90  {
  90      -        static void *value = 0;
       91 +        static void *value = "NON-NULL TSD";
  91   92  
  92   93          /* disable cancellation to avoid hangs if server threads disappear */
  93   94          (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
  94   95          (void) thr_setspecific(server_key, value);
  95   96          (void) door_return(NULL, 0, NULL, 0);
  96   97  
  97   98          /* make lint happy */
  98   99          return (NULL);
  99  100  }
 100  101  
↓ open down ↓ 18 lines elided ↑ open up ↑
 119  120  /*
 120  121   * Server thread are destroyed here
 121  122   */
 122  123  /*ARGSUSED*/
 123  124  static void
 124  125  server_destroy(void *arg)
 125  126  {
 126  127          (void) mutex_lock(&create_lock);
 127  128          num_servers--;
 128  129          (void) mutex_unlock(&create_lock);
      130 +        (void) thr_setspecific(server_key, NULL);
 129  131  }
 130  132  
 131  133  /*
 132  134   * get clearance
 133  135   */
 134  136  int
 135  137  _nscd_get_clearance(sema_t *sema) {
 136  138          if (sema_trywait(&common_sema) == 0) {
 137  139                  (void) thr_setspecific(lookup_state_key, NULL);
 138  140                  return (0);
↓ open down ↓ 1407 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX