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_smfmonitor.c
+++ new/usr/src/cmd/nscd/nscd_smfmonitor.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
↓ 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 2008 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 + *
25 + * Copyright 2018 Joyent, Inc.
24 26 */
25 27
26 28 #include <stdlib.h>
27 29 #include <libscf.h>
28 30 #include <string.h>
29 31 #include "nscd_switch.h"
30 32 #include "nscd_log.h"
31 33 #include "nscd_door.h"
32 34
33 35 extern int _whoami;
34 36
35 37 /*
36 38 * Service states monitored by nscd. Protected by
37 39 * readers/writer lock nscd_smf_service_state_lock
38 40 */
39 41 nscd_smf_state_t *nscd_smf_service_state;
40 42 static rwlock_t nscd_smf_service_state_lock = DEFAULTRWLOCK;
41 43 /*
42 44 * init service state table
43 45 */
44 46 nscd_rc_t
45 47 _nscd_alloc_service_state_table()
46 48 {
47 49 int i;
48 50
49 51 nscd_smf_service_state = calloc(NSCD_NUM_SMF_FMRI,
50 52 sizeof (nscd_smf_state_t));
51 53
52 54 if (nscd_smf_service_state == NULL)
53 55 return (NSCD_NO_MEMORY);
54 56
55 57 for (i = 1; i < NSCD_NUM_SMF_FMRI; i++)
56 58 NSCD_SMF_SVC_STATE(i) = NSCD_SVC_STATE_UNINITED;
57 59
58 60 return (NSCD_SUCCESS);
59 61 }
60 62
61 63 static int
62 64 query_smf_state(int srci)
63 65 {
64 66
65 67 int ret = NSCD_SVC_STATE_UNINITED;
66 68 char *state = NULL;
67 69 char *me = "query_smf_state";
68 70
69 71 state = smf_get_state(NSCD_SMF_SVC_FMRI(srci));
70 72 if (state == NULL)
71 73 return (ret);
72 74
73 75 _NSCD_LOG(NSCD_LOG_SMF_MONITOR, NSCD_LOG_LEVEL_DEBUG)
74 76 (me, "%s -- %s\n", state, NSCD_SMF_SVC_FMRI(srci));
75 77
76 78 (void) rw_wrlock(&nscd_smf_service_state_lock);
77 79
78 80 if (nscd_smf_service_state[srci].src_name == NULL)
79 81 nscd_smf_service_state[srci].src_name =
80 82 NSCD_NSW_SRC_NAME(srci);
81 83
82 84 if (strcmp(state, SCF_STATE_STRING_UNINIT) == 0)
83 85 NSCD_SMF_SVC_STATE(srci) = SCF_STATE_UNINIT;
84 86 else if (strcmp(state, SCF_STATE_STRING_MAINT) == 0)
85 87 NSCD_SMF_SVC_STATE(srci) = SCF_STATE_MAINT;
86 88 else if (strcmp(state, SCF_STATE_STRING_OFFLINE) == 0)
87 89 NSCD_SMF_SVC_STATE(srci) = SCF_STATE_OFFLINE;
88 90 else if (strcmp(state, SCF_STATE_STRING_DISABLED) == 0)
89 91 NSCD_SMF_SVC_STATE(srci) = SCF_STATE_DISABLED;
90 92 else if (strcmp(state, SCF_STATE_STRING_ONLINE) == 0)
91 93 NSCD_SMF_SVC_STATE(srci) = SCF_STATE_ONLINE;
92 94 else if (strcmp(state, SCF_STATE_STRING_DEGRADED) == 0)
93 95 NSCD_SMF_SVC_STATE(srci) = SCF_STATE_DEGRADED;
94 96
95 97 ret = NSCD_SMF_SVC_STATE(srci);
96 98 (void) rw_unlock(&nscd_smf_service_state_lock);
97 99
98 100 free(state);
99 101 return (ret);
↓ open down ↓ |
66 lines elided |
↑ open up ↑ |
100 102 }
101 103
102 104 /* ARGSUSED */
103 105 static void *
104 106 set_smf_state(void *arg)
105 107 {
106 108
107 109 int i;
108 110 int st;
109 111
112 + (void) thr_setname(thr_self(), "set_smf_state");
113 +
110 114 /*
111 115 * the forker nscd needs not monitor the state
112 116 * of the client services
113 117 */
114 118 if (_whoami == NSCD_FORKER)
115 119 thr_exit(0);
116 120
117 121 /*CONSTCOND*/
118 122 while (1) {
119 123
120 124 /* skip the first service which is nscd */
121 125 for (i = 1; i < NSCD_NUM_SMF_FMRI; i++) {
122 126 st = query_smf_state(i);
123 127 if (st == NSCD_SVC_STATE_UNINITED)
124 128 break;
125 129 }
126 130
127 131 (void) sleep(NSCD_SW_CFG_G.check_smf_state_interval_g);
128 132 }
129 133 /* NOTREACHED */
130 134 /*LINTED E_FUNC_HAS_NO_RETURN_STMT*/
131 135 }
132 136
133 137 nscd_rc_t
134 138 _nscd_init_smf_monitor() {
135 139
136 140 int errnum;
137 141 char *me = "_nscd_init_smf_monitor";
138 142
139 143 _NSCD_LOG(NSCD_LOG_SMF_MONITOR, NSCD_LOG_LEVEL_DEBUG)
140 144 (me, "initializing the smf monitor\n");
141 145
142 146 /*
143 147 * start a thread to check the state of the client services
144 148 */
145 149 if (thr_create(NULL, NULL, set_smf_state,
146 150 NULL, THR_DETACHED, NULL) != 0) {
147 151 errnum = errno;
148 152 _NSCD_LOG(NSCD_LOG_SMF_MONITOR, NSCD_LOG_LEVEL_ERROR)
149 153 (me, "thr_create: %s\n", strerror(errnum));
150 154 return (NSCD_THREAD_CREATE_ERROR);
151 155 }
152 156
153 157 return (NSCD_SUCCESS);
154 158 }
155 159
156 160 int
157 161 _nscd_get_smf_state(int srci, int dbi, int recheck)
158 162 {
159 163 int s;
160 164 char *n;
161 165
162 166 n = NSCD_NSW_SRC_NAME(srci);
163 167
164 168 /* the files, compat, and dns backends are always available */
165 169 if ((*n == 'f' || *n == 'c' || *n == 'd' || *n == 'a') &&
166 170 (strcmp(NSCD_NSW_SRC_NAME(srci), "files") == 0 ||
167 171 strcmp(NSCD_NSW_SRC_NAME(srci), "compat") == 0 ||
168 172 strcmp(NSCD_NSW_SRC_NAME(srci), "ad") == 0 ||
169 173 strcmp(NSCD_NSW_SRC_NAME(srci), "dns") == 0)) {
170 174 return (SCF_STATE_ONLINE);
171 175 }
172 176
173 177 /*
174 178 * for the printer database and user backend, treat the
175 179 * backend as a unsupported one, as nscd can not access
176 180 * the home directory of the user
177 181 */
178 182 if (*n == 'u' && strcmp(NSCD_NSW_SRC_NAME(srci), "user") == 0) {
179 183 if (strcmp(NSCD_NSW_DB_NAME(dbi), NSS_DBNAM_PRINTERS) == 0)
180 184 return (NSCD_SVC_STATE_UNSUPPORTED_SRC);
181 185 else
182 186 return (SCF_STATE_ONLINE);
183 187 }
184 188
185 189 /*
186 190 * Foreign backend is not supported by nscd unless
187 191 * the backend supports the nss2 interface (global
188 192 * symbol _nss_<backname name>_version is present),
189 193 * tell the switch engine to return NSS_TRYLOCAL
190 194 * if needed via rc NSCD_SVC_STATE_FOREIGN_SRC.
191 195 */
192 196 if (srci >= _nscd_cfg_num_nsw_src)
193 197 return (NSCD_SVC_STATE_FOREIGN_SRC);
194 198
195 199 if (recheck == 1)
196 200 return (query_smf_state(srci));
197 201
198 202 (void) rw_rdlock(&nscd_smf_service_state_lock);
199 203 s = NSCD_SMF_SVC_STATE(srci);
200 204 (void) rw_unlock(&nscd_smf_service_state_lock);
201 205
202 206 /*
203 207 * if the state has been queried at least once but is
204 208 * still not online, query one more time
205 209 */
206 210 if (s != NSCD_SVC_STATE_UNINITED && s < SCF_STATE_ONLINE)
207 211 s = query_smf_state(srci);
208 212
209 213 return (s);
210 214 }
↓ open down ↓ |
91 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX