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


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.


  24  */
  25 
  26 #include <sys/ccompile.h>
  27 
  28 #include <stdlib.h>
  29 #include <assert.h>
  30 #include <string.h>
  31 #include <errno.h>
  32 #include <fcntl.h>
  33 
  34 #include "nscd_db.h"
  35 #include "nscd_log.h"
  36 #include "nscd_switch.h"
  37 #include "nscd_door.h"
  38 
  39 extern int              _whoami;
  40 static mutex_t          getent_monitor_mutex = DEFAULTMUTEX;
  41 static int              getent_monitor_started = 0;
  42 
  43 static rwlock_t         getent_ctxDB_rwlock = DEFAULTRWLOCK;


 641                 (void) close(fd);
 642                 return (0);
 643         }
 644 }
 645 
 646 /*
 647  * FUNCTION: reclaim_getent_ctx
 648  */
 649 /*ARGSUSED*/
 650 static void * __NORETURN
 651 reclaim_getent_ctx(void *arg)
 652 {
 653         void                    *cookie = NULL;
 654         nscd_db_entry_t         *ep;
 655         nscd_getent_ctx_t       *ctx;
 656         nscd_getent_context_t   *gctx, *c;
 657         nscd_getent_context_t   *first = NULL, *last = NULL;
 658         nss_getent_t            nssctx = { 0 };
 659         char                    *me = "reclaim_getent_ctx";
 660 


 661         /*CONSTCOND*/
 662         while (1) {
 663 
 664                 (void) sleep(60);
 665 
 666                 (void) rw_rdlock(&getent_ctxDB_rwlock);
 667 
 668                 for (ep = _nscd_walk_db(getent_ctxDB, &cookie); ep != NULL;
 669                     ep = _nscd_walk_db(getent_ctxDB, &cookie)) {
 670 
 671                         ctx = (nscd_getent_ctx_t *)*(ep->data_array);
 672 
 673                         gctx = ctx->ptr;
 674 
 675                         /*
 676                          * if the client process, which did the setent,
 677                          * exited, add the context to the orphan list
 678                          */
 679                         if (gctx->pid != -1 && process_exited(gctx->pid)) {
 680 


 727                         (void) mutex_unlock(&gctx->getent_mutex);
 728 
 729                         if (in_use == 0) {
 730                                 _NSCD_LOG(NSCD_LOG_GETENT_CTX,
 731                                     NSCD_LOG_LEVEL_DEBUG)
 732                                 (me, "process  %d exited, "
 733                                     "freeing getent context = %p\n",
 734                                     gctx->pid, gctx);
 735                                 nssctx.ctx = (struct nss_getent_context *)gctx;
 736                                 nss_endent(NULL, NULL, &nssctx);
 737                         }
 738                         gctx = c;
 739                 }
 740                 first = last = NULL;
 741         }
 742         /*NOTREACHED*/
 743         /*LINTED E_FUNC_HAS_NO_RETURN_STMT*/
 744 }
 745 
 746 static nscd_rc_t
 747 _nscd_init_getent_ctx_monitor() {

 748 
 749         int     errnum;
 750         char    *me = "_nscd_init_getent_ctx_monitor";
 751 
 752         _NSCD_LOG(NSCD_LOG_GETENT_CTX, NSCD_LOG_LEVEL_DEBUG)
 753         (me, "initializing the getent context monitor\n");
 754 
 755         /*
 756          * the forker nscd does not process getent requests
 757          * so no need to monitor orphan getent contexts
 758          */
 759         if (_whoami == NSCD_FORKER)
 760                 return (NSCD_SUCCESS);
 761 
 762         /*
 763          * start a thread to reclaim unused getent contexts
 764          */
 765         if (thr_create(NULL, NULL, reclaim_getent_ctx,
 766                 NULL, THR_DETACHED, NULL) != 0) {
 767                 errnum = errno;


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  *
  25  * Copyright 2018 Joyent, Inc.
  26  */
  27 
  28 #include <sys/ccompile.h>
  29 
  30 #include <stdlib.h>
  31 #include <assert.h>
  32 #include <string.h>
  33 #include <errno.h>
  34 #include <fcntl.h>
  35 
  36 #include "nscd_db.h"
  37 #include "nscd_log.h"
  38 #include "nscd_switch.h"
  39 #include "nscd_door.h"
  40 
  41 extern int              _whoami;
  42 static mutex_t          getent_monitor_mutex = DEFAULTMUTEX;
  43 static int              getent_monitor_started = 0;
  44 
  45 static rwlock_t         getent_ctxDB_rwlock = DEFAULTRWLOCK;


 643                 (void) close(fd);
 644                 return (0);
 645         }
 646 }
 647 
 648 /*
 649  * FUNCTION: reclaim_getent_ctx
 650  */
 651 /*ARGSUSED*/
 652 static void * __NORETURN
 653 reclaim_getent_ctx(void *arg)
 654 {
 655         void                    *cookie = NULL;
 656         nscd_db_entry_t         *ep;
 657         nscd_getent_ctx_t       *ctx;
 658         nscd_getent_context_t   *gctx, *c;
 659         nscd_getent_context_t   *first = NULL, *last = NULL;
 660         nss_getent_t            nssctx = { 0 };
 661         char                    *me = "reclaim_getent_ctx";
 662 
 663         (void) thr_setname(thr_self(), me);
 664 
 665         /*CONSTCOND*/
 666         while (1) {
 667 
 668                 (void) sleep(60);
 669 
 670                 (void) rw_rdlock(&getent_ctxDB_rwlock);
 671 
 672                 for (ep = _nscd_walk_db(getent_ctxDB, &cookie); ep != NULL;
 673                     ep = _nscd_walk_db(getent_ctxDB, &cookie)) {
 674 
 675                         ctx = (nscd_getent_ctx_t *)*(ep->data_array);
 676 
 677                         gctx = ctx->ptr;
 678 
 679                         /*
 680                          * if the client process, which did the setent,
 681                          * exited, add the context to the orphan list
 682                          */
 683                         if (gctx->pid != -1 && process_exited(gctx->pid)) {
 684 


 731                         (void) mutex_unlock(&gctx->getent_mutex);
 732 
 733                         if (in_use == 0) {
 734                                 _NSCD_LOG(NSCD_LOG_GETENT_CTX,
 735                                     NSCD_LOG_LEVEL_DEBUG)
 736                                 (me, "process  %d exited, "
 737                                     "freeing getent context = %p\n",
 738                                     gctx->pid, gctx);
 739                                 nssctx.ctx = (struct nss_getent_context *)gctx;
 740                                 nss_endent(NULL, NULL, &nssctx);
 741                         }
 742                         gctx = c;
 743                 }
 744                 first = last = NULL;
 745         }
 746         /*NOTREACHED*/
 747         /*LINTED E_FUNC_HAS_NO_RETURN_STMT*/
 748 }
 749 
 750 static nscd_rc_t
 751 _nscd_init_getent_ctx_monitor()
 752 {
 753 
 754         int     errnum;
 755         char    *me = "_nscd_init_getent_ctx_monitor";
 756 
 757         _NSCD_LOG(NSCD_LOG_GETENT_CTX, NSCD_LOG_LEVEL_DEBUG)
 758         (me, "initializing the getent context monitor\n");
 759 
 760         /*
 761          * the forker nscd does not process getent requests
 762          * so no need to monitor orphan getent contexts
 763          */
 764         if (_whoami == NSCD_FORKER)
 765                 return (NSCD_SUCCESS);
 766 
 767         /*
 768          * start a thread to reclaim unused getent contexts
 769          */
 770         if (thr_create(NULL, NULL, reclaim_getent_ctx,
 771             NULL, THR_DETACHED, NULL) != 0) {
 772                 errnum = errno;