Print this page
8158 Want named threads API
9857 proc manpages should have LIBRARY section

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 2018 Joyent, 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 ↓ 47 lines elided ↑ open up ↑
  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   91          static void *value = 0;
  91   92  
       93 +        (void) thr_setname(thr_self(), "server_tsd_bind");
       94 +
  92   95          /* disable cancellation to avoid hangs if server threads disappear */
  93   96          (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
  94   97          (void) thr_setspecific(server_key, value);
  95   98          (void) door_return(NULL, 0, NULL, 0);
  96   99  
  97  100          /* make lint happy */
  98  101          return (NULL);
  99  102  }
 100  103  
 101  104  /*
↓ open down ↓ 23 lines elided ↑ open up ↑
 125  128  {
 126  129          (void) mutex_lock(&create_lock);
 127  130          num_servers--;
 128  131          (void) mutex_unlock(&create_lock);
 129  132  }
 130  133  
 131  134  /*
 132  135   * get clearance
 133  136   */
 134  137  int
 135      -_nscd_get_clearance(sema_t *sema) {
      138 +_nscd_get_clearance(sema_t *sema)
      139 +{
 136  140          if (sema_trywait(&common_sema) == 0) {
 137  141                  (void) thr_setspecific(lookup_state_key, NULL);
 138  142                  return (0);
 139  143          }
 140  144  
 141  145          if (sema_trywait(sema) == 0) {
 142  146                  (void) thr_setspecific(lookup_state_key, (void*)1);
 143  147                  return (0);
 144  148          }
 145  149  
 146  150          return (1);
 147  151  }
 148  152  
 149  153  
 150  154  /*
 151  155   * release clearance
 152  156   */
 153  157  int
 154      -_nscd_release_clearance(sema_t *sema) {
      158 +_nscd_release_clearance(sema_t *sema)
      159 +{
 155  160          int     which;
 156  161  
 157  162          (void) thr_getspecific(lookup_state_key, (void**)&which);
 158  163          if (which == 0) /* from common pool */ {
 159  164                  (void) sema_post(&common_sema);
 160  165                  return (0);
 161  166          }
 162  167  
 163  168          (void) sema_post(sema);
 164  169          return (1);
↓ open down ↓ 25 lines elided ↑ open up ↑
 190  195   */
 191  196  void
 192  197  _nscd_restart_if_cfgfile_changed()
 193  198  {
 194  199  
 195  200          static mutex_t          nsswitch_lock = DEFAULTMUTEX;
 196  201          static timestruc_t      last_nsswitch_check = { 0 };
 197  202          static timestruc_t      last_nsswitch_modified = { 0 };
 198  203          static timestruc_t      last_resolv_modified = { -1, 0 };
 199  204          static mutex_t          restarting_lock = DEFAULTMUTEX;
 200      -        static int              restarting = 0;
      205 +        static int              restarting = 0;
 201  206          int                     restart = 0;
 202  207          time_t                  now = time(NULL);
 203  208          char                    *me = "_nscd_restart_if_cfgfile_changed";
 204  209  
 205  210  #define FLAG_RESTART_REQUIRED   if (restarting == 0) {\
 206  211                                          (void) mutex_lock(&restarting_lock);\
 207  212                                          if (restarting == 0) {\
 208  213                                                  restarting = 1;\
 209  214                                                  restart = 1;\
 210  215                                          }\
↓ open down ↓ 1259 lines elided ↑ open up ↑
1470 1475                  struct {
1471 1476                          struct rt_msghdr rtm;
1472 1477                          struct sockaddr_storage addrs[RTA_NUMBITS];
1473 1478                  } r;
1474 1479                  struct if_msghdr ifm;
1475 1480                  struct ifa_msghdr ifam;
1476 1481          } mbuf;
1477 1482          struct ifa_msghdr *ifam = &mbuf.ifam;
1478 1483          char    *me = "rts_mon";
1479 1484  
     1485 +        (void) thr_setname(thr_self(), me);
     1486 +
1480 1487          rt_sock = socket(PF_ROUTE, SOCK_RAW, 0);
1481 1488          if (rt_sock < 0) {
1482 1489                  _NSCD_LOG(NSCD_LOG_FRONT_END, NSCD_LOG_LEVEL_ERROR)
1483 1490                  (me, "Failed to open routing socket: %s\n", strerror(errno));
1484 1491                  thr_exit(0);
1485 1492          }
1486 1493  
1487 1494          for (;;) {
1488 1495                  rdlen = read(rt_sock, &mbuf, sizeof (mbuf));
1489 1496                  if (rdlen <= 0) {
↓ open down ↓ 56 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX