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/ldapcachemgr/cachemgr.c
          +++ new/usr/src/cmd/ldapcachemgr/cachemgr.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  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 + * Copyright 2019 Nexenta Systems, Inc.
  24   25   */
  25   26  
  26   27  /*
  27   28   * Simple doors ldap cache daemon
  28   29   */
  29   30  
  30   31  #include <stdio.h>
  31   32  #include <stdlib.h>
  32   33  #include <signal.h>
  33   34  #include <door.h>
↓ open down ↓ 184 lines elided ↑ open up ↑
 218  219  /*
 219  220   * Bind a TSD value to a server thread. This enables the destructor to
 220  221   * be called if/when this thread exits.  This would be a programming error,
 221  222   * but better safe than sorry.
 222  223   */
 223  224  
 224  225  /*ARGSUSED*/
 225  226  static void *
 226  227  server_tsd_bind(void *arg)
 227  228  {
 228      -        static void     *value = 0;
      229 +        static void *value = "NON-NULL TSD";
 229  230  
 230  231          /*
 231  232           * disable cancellation to prevent hangs when server
 232  233           * threads disappear
 233  234           */
 234      -
      235 +        (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
 235  236          (void) thr_setspecific(server_key, value);
 236  237          (void) door_return(NULL, 0, NULL, 0);
 237  238  
 238  239          return (value);
 239  240  }
 240  241  
 241  242  /*
 242  243   * Server threads are created here.
 243  244   */
 244  245  
↓ open down ↓ 16 lines elided ↑ open up ↑
 261  262   * Server thread are destroyed here
 262  263   */
 263  264  
 264  265  /*ARGSUSED*/
 265  266  static void
 266  267  server_destroy(void *arg)
 267  268  {
 268  269          (void) mutex_lock(&create_lock);
 269  270          num_servers--;
 270  271          (void) mutex_unlock(&create_lock);
      272 +        (void) thr_setspecific(server_key, NULL);
 271  273  }
 272  274  
 273  275  static void             client_killserver();
 274  276  
 275  277  int
 276  278  main(int argc, char ** argv)
 277  279  {
 278  280          int                     did;
 279  281          int                     opt;
 280  282          int                     errflg = 0;
↓ open down ↓ 1570 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX