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