Print this page
smf: switch to a tri-state for process-security properties true=on,false=off,nil=default
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/librestart/common/librestart.h
+++ new/usr/src/lib/librestart/common/librestart.h
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
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 (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 */
24 24
25 25 #ifndef _LIBRESTART_H
26 26 #define _LIBRESTART_H
27 27
28 28 #include <libsysevent.h>
29 29 #include <libcontract.h>
30 30 #include <libscf.h>
31 31 #include <limits.h>
32 32 #include <priv.h>
33 33 #include <pwd.h>
34 34 #include <sys/types.h>
35 35 #include <sys/secflags.h>
36 36
37 37 #ifdef __cplusplus
38 38 extern "C" {
39 39 #endif
40 40
41 41 /*
42 42 * There are 3 parts to librestart.
43 43 * 1) The event protocol from the master restarter to its delegates.
44 44 * 2) A functional interface for updating the repository.
45 45 * 3) Convenience functions for common restarter tasks.
46 46 *
47 47 * Event protocol
48 48 * We need a reliable event protocol, as there's no way to define
49 49 * restarter events as idempotent.
50 50 *
51 51 * Currently using sysevent channels as the reliable event implementation.
52 52 * This could change if the implementation proves unsuitable, but
53 53 * the API defined here should abstract anything but a change in
54 54 * the fundamental event model.
55 55 *
56 56 * We offer functions to tease apart the event rather than generic
57 57 * nvpair interfaces. This is because each event type has a well-
58 58 * defined set of fields.
59 59 */
60 60
61 61 /*
62 62 * Some of the functions have external contracted consumers, review contracts
63 63 * when making incompatible changes.
64 64 */
65 65
66 66 typedef struct restarter_event_handle restarter_event_handle_t;
67 67 typedef struct restarter_event restarter_event_t;
68 68
69 69 typedef uint32_t restarter_event_type_t;
70 70
71 71 /*
72 72 * Define an event protocol version. In theory, we could use this in
73 73 * the future to support delegated restarters which use an older
74 74 * protocol. In practice, increment RESTARTER_EVENT_VERSION whenever the
75 75 * protocol might have changed.
76 76 */
77 77 #define RESTARTER_EVENT_VERSION 5
78 78
79 79 #define RESTARTER_FLAG_DEBUG 1
80 80
81 81 #define RESTARTER_ERRMSGSZ 1024
82 82
83 83 /*
84 84 * Event types
85 85 * RESTARTER_EVENT_TYPE_ADD_INSTANCE
86 86 * responsible for a new (stopped) instance
87 87 * RESTARTER_EVENT_TYPE_REMOVE_INSTANCE
88 88 * no longer responsible for this instance; stop it and return
89 89 * RESTARTER_EVENT_TYPE_ENABLE
90 90 * no guarantee that dependencies are met; see
91 91 * RESTARTER_EVENT_TYPE_START
92 92 * RESTARTER_EVENT_TYPE_DISABLE
93 93 * no guarantee that instance was running
94 94 * RESTARTER_EVENT_TYPE_ADMIN_DEGRADED
95 95 * RESTARTER_EVENT_TYPE_ADMIN_REFRESH
96 96 * RESTARTER_EVENT_TYPE_ADMIN_RESTART
97 97 * RESTARTER_EVENT_TYPE_ADMIN_MAINT_OFF
98 98 * RESTARTER_EVENT_TYPE_ADMIN_MAINT_ON
99 99 * RESTARTER_EVENT_TYPE_ADMIN_MAINT_ON_IMMEDIATE
100 100 * RESTARTER_EVENT_TYPE_ADMIN_MAINT_OFF
101 101 * RESTARTER_EVENT_TYPE_STOP
102 102 * dependencies are, or are becoming, unsatisfied
103 103 * RESTARTER_EVENT_TYPE_START
104 104 * dependencies have become satisfied
105 105 * RESTARTER_EVENT_TYPE_DEPENDENCY_CYCLE
106 106 * instance caused a dependency cycle
107 107 * RESTARTER_EVENT_TYPE_INVALID_DEPENDENCY
108 108 * instance has an invalid dependency
109 109 */
110 110
111 111 #define RESTARTER_EVENT_TYPE_INVALID 0
112 112 #define RESTARTER_EVENT_TYPE_ADD_INSTANCE 1
113 113 #define RESTARTER_EVENT_TYPE_REMOVE_INSTANCE 2
114 114 #define RESTARTER_EVENT_TYPE_ENABLE 3
115 115 #define RESTARTER_EVENT_TYPE_DISABLE 4
116 116 #define RESTARTER_EVENT_TYPE_ADMIN_DEGRADED 5
117 117 #define RESTARTER_EVENT_TYPE_ADMIN_REFRESH 6
118 118 #define RESTARTER_EVENT_TYPE_ADMIN_RESTART 7
119 119 #define RESTARTER_EVENT_TYPE_ADMIN_MAINT_OFF 8
120 120 #define RESTARTER_EVENT_TYPE_ADMIN_MAINT_ON 9
121 121 #define RESTARTER_EVENT_TYPE_ADMIN_MAINT_ON_IMMEDIATE 10
122 122 #define RESTARTER_EVENT_TYPE_STOP 11
123 123 #define RESTARTER_EVENT_TYPE_START 12
124 124 #define RESTARTER_EVENT_TYPE_DEPENDENCY_CYCLE 13
125 125 #define RESTARTER_EVENT_TYPE_INVALID_DEPENDENCY 14
126 126 #define RESTARTER_EVENT_TYPE_ADMIN_DISABLE 15
127 127 #define RESTARTER_EVENT_TYPE_STOP_RESET 16
128 128
129 129 #define RESTARTER_EVENT_ERROR -1
130 130
131 131 #define RESTARTER_EVENT_INSTANCE_DISABLED 0
132 132 #define RESTARTER_EVENT_INSTANCE_ENABLED 1
133 133
134 134 typedef enum {
135 135 RESTARTER_STATE_NONE,
136 136 RESTARTER_STATE_UNINIT,
137 137 RESTARTER_STATE_MAINT,
138 138 RESTARTER_STATE_OFFLINE,
139 139 RESTARTER_STATE_DISABLED,
140 140 RESTARTER_STATE_ONLINE,
141 141 RESTARTER_STATE_DEGRADED
142 142 } restarter_instance_state_t;
143 143
144 144 /*
145 145 * These values are ordered by severity of required restart, as we use
146 146 * integer comparisons to determine error flow.
147 147 */
148 148 typedef enum {
149 149 RERR_UNSUPPORTED = -1,
150 150 RERR_NONE = 0, /* no error, restart, refresh */
151 151 RERR_FAULT, /* fault occurred */
152 152 RERR_RESTART, /* transition due to restart */
153 153 RERR_REFRESH /* transition due to refresh */
154 154 } restarter_error_t;
155 155 /*
156 156 * restarter_store_contract() and restarter_remove_contract() types
157 157 */
158 158 typedef enum {
159 159 RESTARTER_CONTRACT_PRIMARY,
160 160 RESTARTER_CONTRACT_TRANSIENT
161 161 } restarter_contract_type_t;
162 162
163 163 /*
164 164 * restarter_bind_handle() registers a delegate with svc.startd to
165 165 * begin consuming events.
166 166 *
167 167 * On initial bind, the delgated restarter receives an event for each
168 168 * instance it is responsible for, as if that instance was new.
169 169 *
170 170 * callers must have superuser privileges
171 171 *
172 172 * The event handler can return 0 for success, or EAGAIN to request
173 173 * retry of event delivery. EAGAIN may be returned 3 times before the
174 174 * event is discarded.
175 175 */
176 176 int restarter_bind_handle(uint32_t, const char *,
177 177 int (*event_handler)(restarter_event_t *), int,
178 178 restarter_event_handle_t **);
179 179
180 180 restarter_event_type_t restarter_event_get_type(restarter_event_t *);
181 181 uint64_t restarter_event_get_seq(restarter_event_t *);
182 182 void restarter_event_get_time(restarter_event_t *, hrtime_t *);
183 183 ssize_t restarter_event_get_instance(restarter_event_t *, char *, size_t);
184 184 restarter_event_handle_t *restarter_event_get_handle(restarter_event_t *);
185 185
186 186 /*
187 187 * The following functions work only on certain types of events.
188 188 * They fail with a return of -1 if they're called on an inappropriate event.
189 189 */
190 190 int restarter_event_get_enabled(restarter_event_t *);
191 191 int restarter_event_get_current_states(restarter_event_t *,
192 192 restarter_instance_state_t *, restarter_instance_state_t *);
193 193
194 194 /*
195 195 * State transition reasons
196 196 */
197 197
198 198 typedef enum {
199 199 restarter_str_none,
200 200 restarter_str_administrative_request,
201 201 restarter_str_bad_repo_state,
202 202 restarter_str_clear_request,
203 203 restarter_str_ct_ev_core,
204 204 restarter_str_ct_ev_exit,
205 205 restarter_str_ct_ev_hwerr,
206 206 restarter_str_ct_ev_signal,
207 207 restarter_str_dependencies_satisfied,
208 208 restarter_str_dependency_activity,
209 209 restarter_str_dependency_cycle,
210 210 restarter_str_disable_request,
211 211 restarter_str_enable_request,
212 212 restarter_str_fault_threshold_reached,
213 213 restarter_str_insert_in_graph,
214 214 restarter_str_invalid_dependency,
215 215 restarter_str_invalid_restarter,
216 216 restarter_str_method_failed,
217 217 restarter_str_per_configuration,
218 218 restarter_str_refresh,
219 219 restarter_str_restart_request,
220 220 restarter_str_restarting_too_quickly,
221 221 restarter_str_service_request,
222 222 restarter_str_startd_restart
223 223 } restarter_str_t;
224 224
225 225 struct restarter_state_transition_reason {
226 226 restarter_str_t str_key;
227 227 const char *str_short;
228 228 const char *str_long;
229 229 };
230 230
231 231 /*
232 232 * Functions for updating the repository.
233 233 */
234 234
235 235 /*
236 236 * When setting state to "maintenance", callers of restarter_set_states() can
237 237 * set aux_state to "service_request" to communicate that another service has
238 238 * requested maintenance state for the target service.
239 239 *
240 240 * Callers should use restarter_inst_validate_aux_fmri() to validate the fmri
241 241 * of the requested service and pass "service_request" for aux_state when
242 242 * calling restarter_set_states(). See inetd and startd for examples.
243 243 */
244 244 int restarter_set_states(restarter_event_handle_t *, const char *,
245 245 restarter_instance_state_t, restarter_instance_state_t,
246 246 restarter_instance_state_t, restarter_instance_state_t, restarter_error_t,
247 247 restarter_str_t);
248 248 int restarter_event_publish_retry(evchan_t *, const char *, const char *,
249 249 const char *, const char *, nvlist_t *, uint32_t);
250 250
251 251 /*
252 252 * functions for retrieving the state transition reason messages
253 253 */
254 254
255 255 #define RESTARTER_STRING_VERSION 1
256 256
257 257 uint32_t restarter_str_version(void);
258 258 const char *restarter_get_str_short(restarter_str_t);
259 259 const char *restarter_get_str_long(restarter_str_t);
260 260
261 261 int restarter_store_contract(scf_instance_t *, ctid_t,
262 262 restarter_contract_type_t);
263 263 int restarter_remove_contract(scf_instance_t *, ctid_t,
264 264 restarter_contract_type_t);
265 265
266 266 ssize_t restarter_state_to_string(restarter_instance_state_t, char *, size_t);
↓ open down ↓ |
266 lines elided |
↑ open up ↑ |
267 267 restarter_instance_state_t restarter_string_to_state(char *);
268 268
269 269 #define RESTARTER_METHOD_CONTEXT_VERSION 8
270 270
271 271 struct method_context {
272 272 /* Stable */
273 273 uid_t uid, euid;
274 274 gid_t gid, egid;
275 275 int ngroups; /* -1 means use initgroups(). */
276 276 gid_t groups[NGROUPS_MAX];
277 - psecflags_t def_secflags;
277 + scf_secflags_t def_secflags;
278 278 secflagdelta_t secflag_delta;
279 279 priv_set_t *lpriv_set, *priv_set;
280 280 char *corefile_pattern; /* Optional. */
281 281 char *project; /* NULL for no change */
282 282 char *resource_pool; /* NULL for project default */
283 283 char *working_dir; /* NULL for :default */
284 284 char **env; /* NULL for no env */
285 285 size_t env_sz; /* size of env array */
286 286
287 287 /* Private */
288 288 char *vbuf;
289 289 ssize_t vbuf_sz;
290 290 struct passwd pwd;
291 291 char *pwbuf;
292 292 ssize_t pwbufsz;
293 293 };
294 294
295 295 /*
296 296 * An error structure that contains a message string, and a type
297 297 * that can be used to determine course of action by the reciever
298 298 * of the error structure.
299 299 *
300 300 * type - usually will be an errno equivalent but could contain
301 301 * defined error types for exampe SCF_ERROR_XXX
302 302 * msg - must be at the end of the structure as if the message is
303 303 * longer than EMSGSIZE we will reallocate the structure to
304 304 * handle the overflow
305 305 */
306 306 typedef struct mc_error {
307 307 int destroy; /* Flag to indicate destruction steps */
308 308 int type; /* Type of error for decision making */
309 309 int size; /* The size of the error message string */
310 310 char msg[RESTARTER_ERRMSGSZ];
311 311 } mc_error_t;
312 312
313 313 int restarter_rm_libs_loadable(void);
314 314 /* instance, restarter name, method name, command line, structure pointer */
315 315 mc_error_t *restarter_get_method_context(uint_t, scf_instance_t *,
316 316 scf_snapshot_t *, const char *, const char *, struct method_context **);
317 317 void restarter_mc_error_destroy(mc_error_t *);
318 318 int restarter_set_method_context(struct method_context *, const char **);
319 319 void restarter_free_method_context(struct method_context *);
320 320
321 321
322 322 int restarter_is_null_method(const char *);
323 323 int restarter_is_kill_method(const char *);
324 324 int restarter_is_kill_proc_method(const char *);
325 325
326 326 /* Validate the inst fmri specified in restarter_actions/auxiliary_fmri */
327 327 int restarter_inst_validate_ractions_aux_fmri(scf_instance_t *);
328 328
329 329 /* Delete instance's restarter_actions/auxiliary_fmri property */
330 330 int restarter_inst_reset_ractions_aux_fmri(scf_instance_t *);
331 331
332 332 /* Get boolean value from instance's restarter_actions/auxiliary_tty */
333 333 int restarter_inst_ractions_from_tty(scf_instance_t *);
334 334
335 335 /* Delete instance's restarter/auxiliary_fmri property */
336 336 int restarter_inst_reset_aux_fmri(scf_instance_t *);
337 337
338 338 /* Get boolean value from instance's restarter_actions/do_dump */
339 339 int restarter_inst_dump(scf_instance_t *);
340 340
341 341 /*
342 342 * Set instance's restarter/auxiliary_fmri, value come from
343 343 * restarter_actions/auxliary_fmri
344 344 */
345 345 int restarter_inst_set_aux_fmri(scf_instance_t *);
346 346
347 347 #ifdef __cplusplus
348 348 }
349 349 #endif
350 350
351 351 #endif /* _LIBRESTART_H */
↓ open down ↓ |
64 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX