1 /*
2 * CDDL HEADER START
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 /*
23 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
25 * Copyright 2016 RackTop Systems.
26 */
27
28 #ifndef _STARTD_H
29 #define _STARTD_H
30
31 #include <sys/time.h>
32 #include <librestart.h>
33 #include <librestart_priv.h>
34 #include <libscf.h>
35 #include <libsysevent.h>
36 #include <libuutil.h>
37 #include <pthread.h>
38 #include <synch.h>
39 #include <stdio.h>
40 #include <syslog.h>
41 #include <umem.h>
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47 /*
48 * We want MUTEX_HELD, but we also want pthreads. So we're stuck with this
49 * for the native build, at least until the build machines can catch up
50 * with the latest version of MUTEX_HELD() in <synch.h>.
51 */
52 #if defined(NATIVE_BUILD)
53 #undef MUTEX_HELD
54 #define MUTEX_HELD(m) _mutex_held((mutex_t *)(m))
55 #endif
56
57 #ifndef NDEBUG
58
59 #define MUTEX_LOCK(mp) { \
60 int err; \
61 if ((err = pthread_mutex_lock((mp))) != 0) { \
62 (void) fprintf(stderr, \
63 "pthread_mutex_lock() failed on %s:%d: %s\n", \
64 __FILE__, __LINE__, strerror(err)); \
65 abort(); \
66 } \
67 }
68
69 #define MUTEX_UNLOCK(mp) { \
70 int err; \
71 if ((err = pthread_mutex_unlock((mp))) != 0) { \
72 (void) fprintf(stderr, \
73 "pthread_mutex_unlock() failed on %s:%d: %s\n", \
74 __FILE__, __LINE__, strerror(err)); \
75 abort(); \
76 } \
77 }
78
79 #else
80
81 #define MUTEX_LOCK(mp) (void) pthread_mutex_lock((mp))
82 #define MUTEX_UNLOCK(mp) (void) pthread_mutex_unlock((mp))
83
84 #endif
85
86 #ifndef NDEBUG
87 #define bad_error(func, err) { \
88 (void) fprintf(stderr, "%s:%d: %s() failed with unexpected " \
89 "error %d. Aborting.\n", __FILE__, __LINE__, (func), (err)); \
90 abort(); \
91 }
92 #else
93 #define bad_error(func, err) abort()
94 #endif
95
96
97 #define min(a, b) (((a) < (b)) ? (a) : (b))
98
99 #define FAULT_COUNT_INCR 0
100 #define FAULT_COUNT_RESET 1
101
102 #define FAULT_THRESHOLD 3
103
104 #define MAX_CONFIGD_RETRIES 5
105 #define MAX_EMI_RETRIES 5
106 #define MAX_MOUNT_RETRIES 5
107 #define MAX_SULOGIN_RETRIES 5
108
109 #define RETURN_SUCCESS 0
110 #define RETURN_RETRY -1
111 #define RETURN_FATAL -2
112
113 #define LIBSCF_SUCCESS 0
114 #define LIBSCF_PROPERTY_ABSENT -1
115 #define LIBSCF_PGROUP_ABSENT -2
116 #define LIBSCF_PROPERTY_ERROR -3
117
118 #define METHOD_START 0
119 #define METHOD_STOP 1
120 #define METHOD_REFRESH 2
121
122 #define METHOD_TIMEOUT_INFINITE 0
123
124 /*
125 * Contract cookies used by startd.
126 */
127 #define CONFIGD_COOKIE 0x10
128 #define SULOGIN_COOKIE 0x11
129 #define METHOD_START_COOKIE 0x20
130 #define METHOD_OTHER_COOKIE 0x21
131 #define MONITOR_COOKIE 0x30
132 #define EMI_COOKIE 0x31
133
134
135 #define ALLOC_RETRY 3
136 #define ALLOC_DELAY 10
137 #define ALLOC_DELAY_MULT 10
138
139 #define safe_scf_scope_create(h) \
140 libscf_object_create((void *(*)(scf_handle_t *))scf_scope_create, (h))
141 #define safe_scf_service_create(h) \
142 libscf_object_create((void *(*)(scf_handle_t *))scf_service_create, (h))
143 #define safe_scf_instance_create(h) libscf_object_create( \
144 (void *(*)(scf_handle_t *))scf_instance_create, (h))
145 #define safe_scf_snapshot_create(h) libscf_object_create( \
146 (void *(*)(scf_handle_t *))scf_snapshot_create, (h))
147 #define safe_scf_snaplevel_create(h) libscf_object_create( \
148 (void *(*)(scf_handle_t *))scf_snaplevel_create, (h))
149 #define safe_scf_pg_create(h) \
150 libscf_object_create((void *(*)(scf_handle_t *))scf_pg_create, (h))
151 #define safe_scf_property_create(h) libscf_object_create( \
152 (void *(*)(scf_handle_t *))scf_property_create, (h))
153 #define safe_scf_value_create(h) \
154 libscf_object_create((void *(*)(scf_handle_t *))scf_value_create, (h))
155 #define safe_scf_iter_create(h) \
156 libscf_object_create((void *(*)(scf_handle_t *))scf_iter_create, (h))
157 #define safe_scf_transaction_create(h) libscf_object_create( \
158 (void *(*)(scf_handle_t *)) scf_transaction_create, (h))
159 #define safe_scf_entry_create(h) \
160 libscf_object_create((void *(*)(scf_handle_t *))scf_entry_create, (h))
161
162 #define startd_alloc(sz) \
163 startd_alloc_retry((void *(*)(size_t, int))umem_alloc, (sz))
164 #define startd_zalloc(sz) \
165 startd_alloc_retry((void *(*)(size_t, int))umem_zalloc, (sz))
166
167
168 extern pthread_mutexattr_t mutex_attrs;
169
170 /*
171 * Definitions for administrative actions.
172 * Note that the ordering in admin_action_t, admin_actions, and admin_events
173 * must match. admin_actions and admin_events are defined in startd.c.
174 */
175 #define NACTIONS 6
176
177 typedef enum {
178 ADMIN_EVENT_DEGRADED = 0x0,
179 ADMIN_EVENT_MAINT_OFF,
180 ADMIN_EVENT_MAINT_ON,
181 ADMIN_EVENT_MAINT_ON_IMMEDIATE,
182 ADMIN_EVENT_REFRESH,
183 ADMIN_EVENT_RESTART
184 } admin_action_t;
185
186 extern const char * const admin_actions[NACTIONS];
187 extern const int admin_events[NACTIONS];
188
189 #define LOG_DATE_SIZE 32 /* Max size of timestamp in log output */
190
191 extern ssize_t max_scf_name_size;
192 extern ssize_t max_scf_value_size;
193 extern ssize_t max_scf_fmri_size;
194
195 extern mode_t fmask;
196 extern mode_t dmask;
197
198 #define LOG_PREFIX_EARLY "/etc/svc/volatile/"
199 #define LOG_PREFIX_NORMAL "/var/svc/log/"
200
201 #define LOG_SUFFIX ".log"
202
203 #define STARTD_DEFAULT_LOG "svc.startd.log"
204 #define EMI_LOG ((const char *) "system-early-manifest-import:default.log")
205
206 extern const char *log_directory; /* Current log directory path */
207
208 #define FS_TIMEZONE_DIR "/usr/share/lib/zoneinfo"
209 #define FS_LOCALE_DIR "/usr/lib/locale"
210
211 /*
212 * Simple dictionary representation.
213 */
214 typedef struct dictionary {
215 uu_list_t *dict_list;
216 int dict_new_id;
217 pthread_mutex_t dict_lock;
218 } dictionary_t;
219
220 typedef struct dict_entry {
221 int de_id;
222 const char *de_name;
223 uu_list_node_t de_link;
224 } dict_entry_t;
225
226 extern dictionary_t *dictionary;
227
228 typedef struct timeout_queue {
229 uu_list_t *tq_list;
230 pthread_mutex_t tq_lock;
231 } timeout_queue_t;
232
233 typedef struct timeout_entry {
234 hrtime_t te_timeout; /* timeout expiration time */
235 ctid_t te_ctid;
236 char *te_fmri;
237 char *te_logstem;
238 volatile int te_fired;
239 uu_list_node_t te_link;
240 } timeout_entry_t;
241
242 extern timeout_queue_t *timeouts;
243
244 /*
245 * State definitions.
246 */
247 typedef enum {
248 STATE_NONE = 0x0,
249 STATE_UNINIT,
250 STATE_MAINT,
251 STATE_OFFLINE,
252 STATE_DISABLED,
253 STATE_ONLINE,
254 STATE_DEGRADED
255 } instance_state_t;
256
257 #define STATE_MAX (STATE_DEGRADED + 1)
258
259 extern const char * const instance_state_str[STATE_MAX];
260
261 typedef enum {
262 GVT_UNSUPPORTED = -1,
263 GVT_UNKNOWN = 0,
264 GVT_SVC, /* service */
265 GVT_INST, /* instance */
266 GVT_FILE, /* file: */
267 GVT_GROUP /* dependency group */
268 } gv_type_t;
269
270 typedef enum {
271 DEPGRP_UNSUPPORTED = -1,
272 DEPGRP_REQUIRE_ANY = 1,
273 DEPGRP_REQUIRE_ALL,
274 DEPGRP_EXCLUDE_ALL,
275 DEPGRP_OPTIONAL_ALL
276 } depgroup_type_t;
277
278 typedef enum {
279 METHOD_RESTART_UNKNOWN = -1,
280 METHOD_RESTART_ALL = 0,
281 METHOD_RESTART_EXTERNAL_FAULT,
282 METHOD_RESTART_ANY_FAULT,
283 METHOD_RESTART_OTHER
284 } method_restart_t;
285
286 typedef enum {
287 PROPAGATE_START,
288 PROPAGATE_STOP,
289 PROPAGATE_SAT
290 } propagate_event_t;
291
292 /*
293 * Graph representation.
294 */
295 #define GV_CONFIGURED 0x01 /* Service exists in repository, ready */
296 #define GV_ENABLED 0x02 /* Service should be online */
297 #define GV_ENBLD_NOOVR 0x04 /* GV_ENABLED, ignoring override */
298 #define GV_INSUBGRAPH 0x08 /* Current milestone depends on service */
299 #define GV_DEATHROW 0x10 /* Service is on deathrow */
300 #define GV_TOOFFLINE 0x20 /* Services in subtree to offline */
301 #define GV_TODISABLE 0x40 /* Services in subtree to disable */
302
303 /* ID must come first to support search */
304 typedef struct graph_vertex {
305 int gv_id;
306 char *gv_name;
307 uu_list_node_t gv_link;
308
309 uint_t gv_flags;
310 restarter_instance_state_t gv_state;
311
312 gv_type_t gv_type;
313
314 depgroup_type_t gv_depgroup;
315 restarter_error_t gv_restart;
316
317 void (*gv_start_f)(struct graph_vertex *);
318 void (*gv_post_online_f)(void);
319 void (*gv_post_disable_f)(void);
320
321 int gv_restarter_id;
322 evchan_t *gv_restarter_channel;
323
324 int gv_delegate_initialized;
325 evchan_t *gv_delegate_channel;
326
327 uu_list_t *gv_dependencies;
328 uu_list_t *gv_dependents;
329
330 /*
331 * gv_refs represents the number of references besides dependencies.
332 * The vertex cannot be removed when gv_refs > 0.
333 *
334 * Currently, only relevant for GVT_SVC and GVT_INST type vertices.
335 */
336 int gv_refs;
337
338 int32_t gv_stn_tset;
339 int32_t gv_reason;
340 } graph_vertex_t;
341
342 typedef struct graph_edge {
343 graph_vertex_t *ge_vertex;
344 uu_list_node_t ge_link;
345 graph_vertex_t *ge_parent;
346 } graph_edge_t;
347
348 int libscf_get_info_events_all(scf_propertygroup_t *);
349 int32_t libscf_get_stn_tset(scf_instance_t *);
350
351 /*
352 * Restarter transition outcomes
353 */
354 typedef enum {
355 MAINT_REQUESTED,
356 START_REQUESTED,
357 START_FAILED_REPEATEDLY,
358 START_FAILED_CONFIGURATION,
359 START_FAILED_FATAL,
360 START_FAILED_TIMEOUT_FATAL,
361 START_FAILED_OTHER
362 } start_outcome_t;
363
364 typedef void (*instance_hook_t)(void);
365
366 typedef struct service_hook_assn {
367 char *sh_fmri;
368 instance_hook_t sh_pre_online_hook;
369 instance_hook_t sh_post_online_hook;
370 instance_hook_t sh_post_offline_hook;
371 } service_hook_assn_t;
372
373 /*
374 * Restarter instance stop reasons.
375 */
376 typedef enum {
377 RSTOP_EXIT = 0x0, /* exited or empty */
378 RSTOP_CORE, /* core dumped */
379 RSTOP_SIGNAL, /* external fatal signal received */
380 RSTOP_HWERR, /* uncorrectable hardware error */
381 RSTOP_DEPENDENCY, /* dependency activity caused stop */
382 RSTOP_DISABLE, /* disabled */
383 RSTOP_RESTART, /* restart requested */
384 RSTOP_ERR_CFG, /* wait svc exited with a config. error */
385 RSTOP_ERR_EXIT /* wait svc exited with an error */
386 } stop_cause_t;
387
388 /*
389 * Restarter instance maintenance clear reasons.
390 */
391 typedef enum {
392 RUNMAINT_CLEAR = 0x0,
393 RUNMAINT_DISABLE
394 } unmaint_cause_t;
395
396 /*
397 * Restarter instance flags
398 */
399 #define RINST_CONTRACT 0x00000000 /* progeny constitute inst */
400 #define RINST_TRANSIENT 0x10000000 /* inst operates momentarily */
401 #define RINST_WAIT 0x20000000 /* child constitutes inst */
402 #define RINST_STYLE_MASK 0xf0000000
403
404 #define RINST_RETAKE_RUNNING 0x01000000 /* pending running snapshot */
405 #define RINST_RETAKE_START 0x02000000 /* pending start snapshot */
406
407 #define RINST_RETAKE_MASK 0x0f000000
408
409 #define RINST_START_TIMES 5 /* failures to consider */
410 #define RINST_FAILURE_RATE_NS 600000000000LL /* 1 failure/10 minutes */
411 #define RINST_WT_SVC_FAILURE_RATE_NS NANOSEC /* 1 failure/second */
412
413 /* Number of events in the queue when we start dropping ADMIN events. */
414 #define RINST_QUEUE_THRESHOLD 100
415
416 typedef struct restarter_inst {
417 int ri_id;
418 instance_data_t ri_i;
419 char *ri_common_name; /* template localized name */
420 char *ri_C_common_name; /* C locale name */
421
422 char *ri_logstem; /* logfile name */
423 char *ri_utmpx_prefix;
424 uint_t ri_flags;
425 instance_hook_t ri_pre_online_hook;
426 instance_hook_t ri_post_online_hook;
427 instance_hook_t ri_post_offline_hook;
428
429 hrtime_t ri_start_time[RINST_START_TIMES];
430 uint_t ri_start_index; /* times started */
431
432 uu_list_node_t ri_link;
433 pthread_mutex_t ri_lock;
434
435 /*
436 * When we start a thread to we execute a method for this instance, we
437 * put the thread id in ri_method_thread. Threads with ids other than
438 * this which acquire ri_lock while ri_method_thread is nonzero should
439 * wait on ri_method_cv. ri_method_waiters should be incremented while
440 * waiting so the instance won't be deleted.
441 */
442 pthread_t ri_method_thread;
443 pthread_cond_t ri_method_cv;
444 uint_t ri_method_waiters;
445
446 /*
447 * These fields are provided so functions can operate on this structure
448 * and the repository without worrying about whether the instance has
449 * been deleted from the repository (this is possible because
450 * ri_i.i_fmri names the instance this structure represents -- see
451 * libscf_reget_inst()). ri_m_inst is the scf_instance_t for the
452 * instance, and ri_mi_deleted is true if the instance has been deleted.
453 */
454 scf_instance_t *ri_m_inst;
455 boolean_t ri_mi_deleted;
456
457 /*
458 * We maintain a pointer to any pending timeout for this instance
459 * for quick reference/deletion.
460 */
461 timeout_entry_t *ri_timeout;
462
463 /*
464 * Instance event queue. Graph events are queued here as a list
465 * of restarter_instance_qentry_t's, and the lock is held separately.
466 * If both ri_lock and ri_queue_lock are grabbed, ri_lock must be
467 * grabbed first. ri_queue_lock protects all ri_queue_* structure
468 * members.
469 */
470 pthread_mutex_t ri_queue_lock;
471 pthread_cond_t ri_queue_cv;
472 uu_list_t *ri_queue;
473 int ri_queue_thread;
474
475 } restarter_inst_t;
476
477 typedef struct restarter_instance_list {
478 uu_list_t *ril_instance_list;
479 pthread_mutex_t ril_lock;
480 } restarter_instance_list_t;
481
482 typedef struct restarter_instance_qentry {
483 restarter_event_type_t riq_type;
484 int32_t riq_reason;
485 uu_list_node_t riq_link;
486 } restarter_instance_qentry_t;
487
488 typedef struct fork_info {
489 int sf_id;
490 int sf_method_type;
491 restarter_error_t sf_event_type;
492 restarter_str_t sf_reason;
493 } fork_info_t;
494
495 typedef struct wait_info {
496 uu_list_node_t wi_link;
497
498 int wi_fd; /* psinfo file descriptor */
499 id_t wi_pid; /* process ID */
500 const char *wi_fmri; /* instance FMRI */
501 int wi_parent; /* startd is parent */
502 int wi_ignore; /* ignore events */
503 } wait_info_t;
504
505 #define STARTD_LOG_FILE 0x1
506 #define STARTD_LOG_TERMINAL 0x2
507 #define STARTD_LOG_SYSLOG 0x4
508
509 #define STARTD_BOOT_QUIET 0x1
510 #define STARTD_BOOT_VERBOSE 0x2
511
512 /*
513 * Internal debug flags used to reduce the amount of data sent to the
514 * internal debug buffer. They can be turned on & off dynamically using
515 * internal_debug_flags variable in mdb. By default, they're off.
516 */
517 #define DEBUG_DEPENDENCIES 0x1
518
519 typedef struct startd_state {
520 /* Logging configuration */
521 char *st_log_prefix; /* directory prefix */
522 char *st_log_file; /* startd file in above dir */
523 uint_t st_log_flags; /* message destination */
524 int st_log_level_min; /* minimum required to log */
525 int st_log_timezone_known; /* timezone is available */
526 int st_log_locale_known; /* locale is available */
527 int st_log_login_reached; /* login service reached */
528
529 /* Boot configuration */
530 uint_t st_boot_flags; /* serial boot, etc. */
531 uint_t st_initial; /* first startd on system */
532
533 /* System configuration */
534 char *st_subgraph; /* milestone subgraph request */
535
536 uint_t st_load_complete; /* graph load completed */
537 uint_t st_load_instances; /* restarter instances to load */
538 pthread_mutex_t st_load_lock;
539 pthread_cond_t st_load_cv;
540
541 /* Repository configuration */
542 pid_t st_configd_pid; /* PID of our svc.configd */
543 /* instance */
544 int st_configd_lives; /* configd started */
545 pthread_mutex_t st_configd_live_lock;
546 pthread_cond_t st_configd_live_cv;
547
548 char *st_door_path;
549
550 /* General information */
551 uint_t st_flags;
552 struct timeval st_start_time; /* effective system start time */
553 char *st_locale;
554 } startd_state_t;
555
556 extern startd_state_t *st;
557
558 extern boolean_t booting_to_single_user;
559
560 extern const char *event_names[];
561
562 /*
563 * Structures for contract to instance hash table, implemented in
564 * contract.c and used by restarter.c and method.c
565 */
566 typedef struct contract_entry {
567 ctid_t ce_ctid;
568 int ce_instid;
569
570 uu_list_node_t ce_link;
571 } contract_entry_t;
572
573 extern volatile uint16_t storing_contract;
574
575 uu_list_pool_t *contract_list_pool;
576
577 /* contract.c */
578 ctid_t contract_init(void);
579 void contract_abandon(ctid_t);
580 int contract_kill(ctid_t, int, const char *);
581 int contract_is_empty(ctid_t);
582 void contract_hash_init();
583 void contract_hash_store(ctid_t, int);
584 void contract_hash_remove(ctid_t);
585 int lookup_inst_by_contract(ctid_t);
586
587 /* dict.c */
588 void dict_init(void);
589 int dict_lookup_byname(const char *);
590 int dict_insert(const char *);
591
592 /* expand.c */
593 int expand_method_tokens(const char *, scf_instance_t *,
594 scf_snapshot_t *, int, char **);
595
596 /* env.c */
597 void init_env(void);
598 char **set_smf_env(char **, size_t, const char *,
599 const restarter_inst_t *, const char *);
600
601 /* file.c */
602 int file_ready(graph_vertex_t *);
603
604 /* fork.c */
605 int fork_mount(char *, char *);
606 void fork_sulogin(boolean_t, const char *, ...);
607 void fork_rc_script(char, const char *, boolean_t);
608
609 void *fork_configd_thread(void *);
610
611 pid_t startd_fork1(int *);
612 void fork_with_timeout(const char *, uint_t, uint_t);
613 void fork_emi();
614
615 /* graph.c */
616 void graph_init(void);
617 void *single_user_thread(void *);
618 void *graph_thread(void *);
619 void *graph_event_thread(void *);
620 void *repository_event_thread(void *);
621 int dgraph_add_instance(const char *, scf_instance_t *, boolean_t);
622 void graph_engine_start(void);
623 void graph_enable_by_vertex(graph_vertex_t *, int, int);
624 int refresh_vertex(graph_vertex_t *, scf_instance_t *);
625 void vertex_send_event(graph_vertex_t *, restarter_event_type_t);
626 void graph_start_if_satisfied(graph_vertex_t *);
627 int vertex_subgraph_dependencies_shutdown(scf_handle_t *, graph_vertex_t *,
628 restarter_instance_state_t);
629 void graph_transition_sulogin(restarter_instance_state_t,
630 restarter_instance_state_t);
631 void graph_transition_propagate(graph_vertex_t *, propagate_event_t,
632 restarter_error_t);
633 void graph_offline_subtree_leaves(graph_vertex_t *, void *);
634 void offline_vertex(graph_vertex_t *);
635 boolean_t insubtree_dependents_down(graph_vertex_t *);
636
637 /* libscf.c - common */
638 char *inst_fmri_to_svc_fmri(const char *);
639 void *libscf_object_create(void *(*)(scf_handle_t *), scf_handle_t *);
640 int libscf_instance_get_fmri(scf_instance_t *, char **);
641 int libscf_fmri_get_instance(scf_handle_t *, const char *, scf_instance_t **);
642 int libscf_lookup_instance(const char *, scf_instance_t *);
643 int libscf_set_reconfig(int);
644 scf_snapshot_t *libscf_get_or_make_running_snapshot(scf_instance_t *,
645 const char *, boolean_t);
646 int libscf_inst_set_count_prop(scf_instance_t *, const char *,
647 const char *pgtype, uint32_t, const char *, uint64_t);
648
649 /* libscf.c - used by graph.c */
650 int libscf_get_deathrow(scf_handle_t *, scf_instance_t *, int *);
651 int libscf_get_basic_instance_data(scf_handle_t *, scf_instance_t *,
652 const char *, int *, int *, char **);
653 int libscf_inst_get_or_add_pg(scf_instance_t *, const char *, const char *,
654 uint32_t, scf_propertygroup_t *);
655 int libscf_read_states(const scf_propertygroup_t *,
656 restarter_instance_state_t *, restarter_instance_state_t *);
657 int depgroup_empty(scf_handle_t *, scf_propertygroup_t *);
658 gv_type_t depgroup_read_scheme(scf_handle_t *, scf_propertygroup_t *);
659 depgroup_type_t depgroup_read_grouping(scf_handle_t *, scf_propertygroup_t *);
660 restarter_error_t depgroup_read_restart(scf_handle_t *, scf_propertygroup_t *);
661 int libscf_set_enable_ovr(scf_instance_t *, int);
662 int libscf_set_deathrow(scf_instance_t *, int);
663 int libscf_delete_enable_ovr(scf_instance_t *);
664 int libscf_get_milestone(scf_instance_t *, scf_property_t *, scf_value_t *,
665 char *, size_t);
666 int libscf_extract_runlevel(scf_property_t *, char *);
667 int libscf_clear_runlevel(scf_propertygroup_t *, const char *milestone);
668
669 typedef int (*callback_t)(void *, void *);
670
671 int walk_dependency_pgs(scf_instance_t *, callback_t, void *);
672 int walk_property_astrings(scf_property_t *, callback_t, void *);
673 void libscf_reset_start_times(restarter_inst_t *, int);
674
675 /* libscf.c - used by restarter.c/method.c/expand.c */
676 char *libscf_get_method(scf_handle_t *, int, restarter_inst_t *,
677 scf_snapshot_t *, method_restart_t *, uint_t *, uint8_t *, uint64_t *,
678 uint8_t *);
679 void libscf_populate_graph(scf_handle_t *h);
680 int update_fault_count(restarter_inst_t *, int);
681 int libscf_unset_action(scf_handle_t *, scf_propertygroup_t *, admin_action_t,
682 int64_t);
683 int libscf_get_startd_properties(scf_instance_t *, scf_snapshot_t *, uint_t *,
684 char **);
685 int libscf_get_template_values(scf_instance_t *, scf_snapshot_t *, char **,
686 char **);
687
688 int libscf_read_method_ids(scf_handle_t *, scf_instance_t *, const char *,
689 ctid_t *, ctid_t *, pid_t *);
690 int libscf_write_start_pid(scf_instance_t *, pid_t);
691 int libscf_write_method_status(scf_instance_t *, const char *, int);
692 int libscf_note_method_log(scf_instance_t *, const char *, const char *);
693
694 scf_handle_t *libscf_handle_create_bound(scf_version_t);
695 void libscf_handle_rebind(scf_handle_t *);
696 scf_handle_t *libscf_handle_create_bound_loop(void);
697
698 scf_snapshot_t *libscf_get_running_snapshot(scf_instance_t *);
699 int libscf_snapshots_poststart(scf_handle_t *, const char *, boolean_t);
700 int libscf_snapshots_refresh(scf_instance_t *, const char *);
701
702 int instance_is_transient_style(restarter_inst_t *);
703 int instance_is_wait_style(restarter_inst_t *);
704
705 int libscf_create_self(scf_handle_t *);
706
707 void libscf_reget_instance(restarter_inst_t *);
708
709 /* log.c */
710 void log_init();
711 void log_error(int, const char *, ...);
712 void log_framework(int, const char *, ...);
713 void log_framework2(int, int, const char *, ...);
714 void log_console(int, const char *, ...);
715 void log_preexec(void);
716 void setlog(const char *);
717 void log_transition(const restarter_inst_t *, start_outcome_t);
718 void log_instance(const restarter_inst_t *, boolean_t, const char *, ...);
719 void log_instance_fmri(const char *, const char *, boolean_t,
720 const char *, ...);
721
722 /* method.c */
723 void *method_thread(void *);
724 void method_remove_contract(restarter_inst_t *, boolean_t, boolean_t);
725 int method_rate_critical(restarter_inst_t *);
726
727 /* misc.c */
728 void startd_close(int);
729 void startd_fclose(FILE *);
730 int fmri_canonify(const char *, char **, boolean_t);
731 int fs_is_read_only(char *, ulong_t *);
732 int fs_remount(char *);
733 void xstr_sanitize(char *);
734
735 /* restarter.c */
736 void restarter_init(void);
737 void restarter_start(void);
738 int instance_in_transition(restarter_inst_t *);
739 int restarter_instance_update_states(scf_handle_t *, restarter_inst_t *,
740 restarter_instance_state_t, restarter_instance_state_t, restarter_error_t,
741 restarter_str_t);
742 int stop_instance_fmri(scf_handle_t *, const char *, uint_t);
743 restarter_inst_t *inst_lookup_by_id(int);
744 void restarter_mark_pending_snapshot(const char *, uint_t);
745 void *restarter_post_fsminimal_thread(void *);
746 void timeout_insert(restarter_inst_t *, ctid_t, uint64_t);
747 void timeout_remove(restarter_inst_t *, ctid_t);
748 void timeout_init(void);
749 int is_timeout_ovr(restarter_inst_t *);
750
751 /* startd.c */
752 void *safe_realloc(void *, size_t);
753 char *safe_strdup(const char *s);
754 void *startd_alloc_retry(void *(*)(size_t, int), size_t);
755 void startd_free(void *, size_t);
756 uu_list_pool_t *startd_list_pool_create(const char *, size_t, size_t,
757 uu_compare_fn_t *, uint32_t);
758 uu_list_t *startd_list_create(uu_list_pool_t *, void *, uint32_t);
759 pthread_t startd_thread_create(void *(*)(void *), void *);
760
761 /* special.c */
762 void special_null_transition(void);
763 void special_online_hooks_get(const char *, instance_hook_t *,
764 instance_hook_t *, instance_hook_t *);
765
766 /* transition.c */
767 int gt_transition(scf_handle_t *, graph_vertex_t *, restarter_error_t,
768 restarter_instance_state_t);
769
770 /* utmpx.c */
771 void utmpx_init(void);
772 void utmpx_clear_old(void);
773 int utmpx_mark_init(pid_t, char *);
774 void utmpx_mark_dead(pid_t, int, boolean_t);
775 char utmpx_get_runlevel(void);
776 void utmpx_set_runlevel(char, char, boolean_t);
777 void utmpx_write_boottime(void);
778 void utmpx_prefork(void);
779 void utmpx_postfork(void);
780
781 /* wait.c */
782 void wait_init(void);
783 void wait_prefork(void);
784 void wait_postfork(pid_t);
785 int wait_register(pid_t, const char *, int, int);
786 void *wait_thread(void *);
787 void wait_ignore_by_fmri(const char *);
788
789 /* proc.c */
790 ctid_t proc_get_ctid();
791
792 /* deathrow.c */
793 extern void deathrow_init();
794 extern void deathrow_fini();
795 extern boolean_t is_fmri_in_deathrow(const char *);
796
797 #ifdef __cplusplus
798 }
799 #endif
800
801 #endif /* _STARTD_H */