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


   3  *
   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 (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.


  23  */
  24 
  25 #include <assert.h>
  26 #include <errno.h>
  27 #include <memory.h>
  28 #include <signal.h>
  29 #include <stdlib.h>
  30 #include <stdio.h>
  31 #include <string.h>
  32 #include <libintl.h>
  33 #include <syslog.h>
  34 #include <sys/door.h>
  35 #include <sys/stat.h>
  36 #include <sys/time.h>
  37 #include <sys/types.h>
  38 #include <sys/wait.h>
  39 #include <synch.h>
  40 #include <pthread.h>
  41 #include <unistd.h>
  42 #include <lber.h>


1614         static mutex_t          info_mutex;
1615         static cond_t           info_cond;
1616         static int              creating = FALSE;
1617         static int              refresh_ttl = 0;
1618         static int              sec_to_refresh = 0;
1619         static int              in_no_server_mode = FALSE;
1620 
1621         static server_info_t    *serverInfo = NULL;
1622         static server_info_t    *serverInfo_old = NULL;
1623         server_info_t           *serverInfo_1;
1624         int                     is_creating;
1625         int                     err, no_server_good = FALSE;
1626         int                     server_removed = FALSE;
1627         int                     fall_thru = FALSE;
1628         static struct timespec  timeout;
1629         struct timespec         new_timeout;
1630         struct timeval          tp;
1631         static time_t           prev_refresh = 0, next_refresh = 0;
1632         ns_server_status_t              changed = 0;
1633 


1634         if (current_admin.debug_level >= DBG_ALL) {
1635                 logit("getldap_serverInfo_op()...\n");
1636         }
1637         switch (op) {
1638         case INFO_OP_CREATE:
1639                 if (current_admin.debug_level >= DBG_ALL) {
1640                         logit("operation is INFO_OP_CREATE...\n");
1641                 }
1642 
1643                 /*
1644                  * indicate that the server info is being
1645                  * (re)created, so that the refresh thread
1646                  * will not refresh the info list right
1647                  * after the list got (re)created
1648                  */
1649                 (void) mutex_lock(&info_mutex);
1650                 is_creating = creating;
1651                 creating = TRUE;
1652                 (void) mutex_unlock(&info_mutex);
1653 


2525                 return;
2526         }
2527 
2528         (void) rw_unlock(&ldap_lock);
2529 }
2530 
2531 void
2532 getldap_refresh()
2533 {
2534         struct timespec timeout;
2535         int             sleeptime;
2536         struct timeval  tp;
2537         long            expire = 0;
2538         void            **paramVal = NULL;
2539         ns_ldap_error_t *errorp;
2540         int             always = 1, err;
2541         int             first_time = 1;
2542         int             sig_done = 0;
2543         int             dbg_level;
2544 


2545         if (current_admin.debug_level >= DBG_ALL) {
2546                 logit("getldap_refresh()...\n");
2547         }
2548 
2549         /*
2550          * wait for an available server
2551          */
2552         while (sig_done == 0) {
2553                 (void) mutex_lock(&sig_mutex);
2554                 sig_done = signal_done;
2555                 (void) mutex_unlock(&sig_mutex);
2556         }
2557 
2558         (void) __ns_ldap_setServer(TRUE);
2559         while (always) {
2560                 dbg_level = current_admin.debug_level;
2561                 (void) rw_rdlock(&ldap_lock);
2562                 sleeptime = current_admin.ldap_stat.ldap_ttl;
2563                 if (dbg_level >= DBG_PROFILE_REFRESH) {
2564                         logit("getldap_refresh: current profile TTL is %d "


2875                 (void) __ns_ldap_freeError(&error);
2876 
2877         return (rc);
2878 }
2879 
2880 /*
2881  * The thread is spawned to do contact_server() so it won't be blocking
2882  * getldap_serverInfo_op(INFO_OP_GETSERVER, ...) case.
2883  * After contact_server() is done, it calls
2884  * getldap_serverInfo_op(INFO_OP_REMOVESERVER, ...) to return to the remaining
2885  * program flow. It's meant to maintain the original program flow yet be
2886  * non-blocking when it's contacting server.
2887  */
2888 static void *
2889 remove_server_thread(void *arg)
2890 {
2891         char *addr = (char *)arg, *out = NULL;
2892         int up;
2893         rm_svr_t rms;
2894 


2895         up = contact_server(addr);
2896 
2897         rms.addr = addr;
2898         rms.up = up;
2899 
2900         (void) getldap_serverInfo_op(INFO_OP_REMOVESERVER, (char *)&rms, &out);
2901 
2902         free(addr);
2903 
2904         thr_exit(NULL);
2905         return (NULL);
2906 }
2907 /*
2908  * addr is allocated and is freed by remove_server_thread
2909  * It starts a thread to contact server and remove server to avoid long wait
2910  * or recursion.
2911  */
2912 static void
2913 remove_server(char *addr)
2914 {




   3  *
   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 (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
  23  *
  24  * Copyright 2018 Joyent, Inc.
  25  */
  26 
  27 #include <assert.h>
  28 #include <errno.h>
  29 #include <memory.h>
  30 #include <signal.h>
  31 #include <stdlib.h>
  32 #include <stdio.h>
  33 #include <string.h>
  34 #include <libintl.h>
  35 #include <syslog.h>
  36 #include <sys/door.h>
  37 #include <sys/stat.h>
  38 #include <sys/time.h>
  39 #include <sys/types.h>
  40 #include <sys/wait.h>
  41 #include <synch.h>
  42 #include <pthread.h>
  43 #include <unistd.h>
  44 #include <lber.h>


1616         static mutex_t          info_mutex;
1617         static cond_t           info_cond;
1618         static int              creating = FALSE;
1619         static int              refresh_ttl = 0;
1620         static int              sec_to_refresh = 0;
1621         static int              in_no_server_mode = FALSE;
1622 
1623         static server_info_t    *serverInfo = NULL;
1624         static server_info_t    *serverInfo_old = NULL;
1625         server_info_t           *serverInfo_1;
1626         int                     is_creating;
1627         int                     err, no_server_good = FALSE;
1628         int                     server_removed = FALSE;
1629         int                     fall_thru = FALSE;
1630         static struct timespec  timeout;
1631         struct timespec         new_timeout;
1632         struct timeval          tp;
1633         static time_t           prev_refresh = 0, next_refresh = 0;
1634         ns_server_status_t              changed = 0;
1635 
1636         (void) pthread_setname_np(pthread_self(), "getldap_serverinfo");
1637 
1638         if (current_admin.debug_level >= DBG_ALL) {
1639                 logit("getldap_serverInfo_op()...\n");
1640         }
1641         switch (op) {
1642         case INFO_OP_CREATE:
1643                 if (current_admin.debug_level >= DBG_ALL) {
1644                         logit("operation is INFO_OP_CREATE...\n");
1645                 }
1646 
1647                 /*
1648                  * indicate that the server info is being
1649                  * (re)created, so that the refresh thread
1650                  * will not refresh the info list right
1651                  * after the list got (re)created
1652                  */
1653                 (void) mutex_lock(&info_mutex);
1654                 is_creating = creating;
1655                 creating = TRUE;
1656                 (void) mutex_unlock(&info_mutex);
1657 


2529                 return;
2530         }
2531 
2532         (void) rw_unlock(&ldap_lock);
2533 }
2534 
2535 void
2536 getldap_refresh()
2537 {
2538         struct timespec timeout;
2539         int             sleeptime;
2540         struct timeval  tp;
2541         long            expire = 0;
2542         void            **paramVal = NULL;
2543         ns_ldap_error_t *errorp;
2544         int             always = 1, err;
2545         int             first_time = 1;
2546         int             sig_done = 0;
2547         int             dbg_level;
2548 
2549         (void) pthread_setname_np(pthread_self(), "getldap_refresh");
2550 
2551         if (current_admin.debug_level >= DBG_ALL) {
2552                 logit("getldap_refresh()...\n");
2553         }
2554 
2555         /*
2556          * wait for an available server
2557          */
2558         while (sig_done == 0) {
2559                 (void) mutex_lock(&sig_mutex);
2560                 sig_done = signal_done;
2561                 (void) mutex_unlock(&sig_mutex);
2562         }
2563 
2564         (void) __ns_ldap_setServer(TRUE);
2565         while (always) {
2566                 dbg_level = current_admin.debug_level;
2567                 (void) rw_rdlock(&ldap_lock);
2568                 sleeptime = current_admin.ldap_stat.ldap_ttl;
2569                 if (dbg_level >= DBG_PROFILE_REFRESH) {
2570                         logit("getldap_refresh: current profile TTL is %d "


2881                 (void) __ns_ldap_freeError(&error);
2882 
2883         return (rc);
2884 }
2885 
2886 /*
2887  * The thread is spawned to do contact_server() so it won't be blocking
2888  * getldap_serverInfo_op(INFO_OP_GETSERVER, ...) case.
2889  * After contact_server() is done, it calls
2890  * getldap_serverInfo_op(INFO_OP_REMOVESERVER, ...) to return to the remaining
2891  * program flow. It's meant to maintain the original program flow yet be
2892  * non-blocking when it's contacting server.
2893  */
2894 static void *
2895 remove_server_thread(void *arg)
2896 {
2897         char *addr = (char *)arg, *out = NULL;
2898         int up;
2899         rm_svr_t rms;
2900 
2901         (void) pthread_setname_np(pthread_self(), "remove_server");
2902 
2903         up = contact_server(addr);
2904 
2905         rms.addr = addr;
2906         rms.up = up;
2907 
2908         (void) getldap_serverInfo_op(INFO_OP_REMOVESERVER, (char *)&rms, &out);
2909 
2910         free(addr);
2911 
2912         thr_exit(NULL);
2913         return (NULL);
2914 }
2915 /*
2916  * addr is allocated and is freed by remove_server_thread
2917  * It starts a thread to contact server and remove server to avoid long wait
2918  * or recursion.
2919  */
2920 static void
2921 remove_server(char *addr)
2922 {