xref: /titanic_50/usr/src/cmd/svc/startd/startd.h (revision 015a6ef6781cc3ceba8ad3bfbae98449b6002a1f)
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 2009 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 #define	GV_TOOFFLINE	0x20	/* Services in subtree to offline */
291 #define	GV_TODISABLE	0x40	/* Services in subtree to disable */
292 
293 /* ID must come first to support search */
294 typedef struct graph_vertex {
295 	int				gv_id;
296 	char				*gv_name;
297 	uu_list_node_t			gv_link;
298 
299 	uint_t				gv_flags;
300 	restarter_instance_state_t	gv_state;
301 
302 	gv_type_t			gv_type;
303 
304 	depgroup_type_t			gv_depgroup;
305 	restarter_error_t		gv_restart;
306 
307 	void				(*gv_start_f)(struct graph_vertex *);
308 	void				(*gv_post_online_f)(void);
309 	void				(*gv_post_disable_f)(void);
310 
311 	int				gv_restarter_id;
312 	evchan_t			*gv_restarter_channel;
313 
314 	int				gv_delegate_initialized;
315 	evchan_t			*gv_delegate_channel;
316 
317 	uu_list_t			*gv_dependencies;
318 	uu_list_t			*gv_dependents;
319 
320 	/*
321 	 * gv_refs represents the number of references besides dependencies.
322 	 * The vertex cannot be removed when gv_refs > 0.
323 	 *
324 	 * Currently, only relevant for GVT_SVC and GVT_INST type vertices.
325 	 */
326 	int 				gv_refs;
327 } graph_vertex_t;
328 
329 typedef struct graph_edge {
330 	graph_vertex_t	*ge_vertex;
331 	uu_list_node_t	ge_link;
332 	graph_vertex_t	*ge_parent;
333 } graph_edge_t;
334 
335 /*
336  * Restarter transition outcomes
337  */
338 typedef enum {
339 	MAINT_REQUESTED,
340 	START_REQUESTED,
341 	START_FAILED_REPEATEDLY,
342 	START_FAILED_CONFIGURATION,
343 	START_FAILED_FATAL,
344 	START_FAILED_TIMEOUT_FATAL,
345 	START_FAILED_OTHER
346 } start_outcome_t;
347 
348 typedef void (*instance_hook_t)(void);
349 
350 typedef struct service_hook_assn {
351 	char	*sh_fmri;
352 	instance_hook_t	sh_pre_online_hook;
353 	instance_hook_t	sh_post_online_hook;
354 	instance_hook_t	sh_post_offline_hook;
355 } service_hook_assn_t;
356 
357 /*
358  * Restarter instance stop reasons.
359  */
360 typedef enum {
361 	RSTOP_EXIT = 0x0,	/* exited or empty */
362 	RSTOP_CORE,		/* core dumped */
363 	RSTOP_SIGNAL,		/* external fatal signal received */
364 	RSTOP_HWERR,		/* uncorrectable hardware error */
365 	RSTOP_DEPENDENCY,	/* dependency activity caused stop */
366 	RSTOP_DISABLE,		/* disabled */
367 	RSTOP_RESTART		/* restart requested */
368 } stop_cause_t;
369 
370 /*
371  * Restarter instance maintenance clear reasons.
372  */
373 typedef enum {
374 	RUNMAINT_CLEAR = 0x0,
375 	RUNMAINT_DISABLE
376 } unmaint_cause_t;
377 
378 /*
379  * Restarter instance flags
380  */
381 #define	RINST_CONTRACT		0x00000000	/* progeny constitute inst */
382 #define	RINST_TRANSIENT		0x10000000	/* inst operates momentarily */
383 #define	RINST_WAIT		0x20000000	/* child constitutes inst */
384 #define	RINST_STYLE_MASK	0xf0000000
385 
386 #define	RINST_RETAKE_RUNNING	0x01000000	/* pending running snapshot */
387 #define	RINST_RETAKE_START	0x02000000	/* pending start snapshot */
388 
389 #define	RINST_RETAKE_MASK	0x0f000000
390 
391 #define	RINST_START_TIMES	10		/* failures to consider */
392 #define	RINST_FAILURE_RATE_NS	1000000000LL	/* 1 failure/second */
393 
394 /* Number of events in the queue when we start dropping ADMIN events. */
395 #define	RINST_QUEUE_THRESHOLD	100
396 
397 typedef struct restarter_inst {
398 	int			ri_id;
399 	instance_data_t		ri_i;
400 	char			*ri_common_name; /* template localized name */
401 	char			*ri_C_common_name; /* C locale name */
402 
403 	char			*ri_logstem;	/* logfile name */
404 	char			*ri_utmpx_prefix;
405 	uint_t			ri_flags;
406 	instance_hook_t		ri_pre_online_hook;
407 	instance_hook_t		ri_post_online_hook;
408 	instance_hook_t		ri_post_offline_hook;
409 
410 	hrtime_t		ri_start_time[RINST_START_TIMES];
411 	uint_t			ri_start_index;	/* times started */
412 
413 	uu_list_node_t		ri_link;
414 	pthread_mutex_t		ri_lock;
415 
416 	/*
417 	 * When we start a thread to we execute a method for this instance, we
418 	 * put the thread id in ri_method_thread.  Threads with ids other than
419 	 * this which acquire ri_lock while ri_method_thread is nonzero should
420 	 * wait on ri_method_cv.  ri_method_waiters should be incremented while
421 	 * waiting so the instance won't be deleted.
422 	 */
423 	pthread_t		ri_method_thread;
424 	pthread_cond_t		ri_method_cv;
425 	uint_t			ri_method_waiters;
426 
427 	/*
428 	 * These fields are provided so functions can operate on this structure
429 	 * and the repository without worrying about whether the instance has
430 	 * been deleted from the repository (this is possible because
431 	 * ri_i.i_fmri names the instance this structure represents -- see
432 	 * libscf_reget_inst()).  ri_m_inst is the scf_instance_t for the
433 	 * instance, and ri_mi_deleted is true if the instance has been deleted.
434 	 */
435 	scf_instance_t		*ri_m_inst;
436 	boolean_t		ri_mi_deleted;
437 
438 	/*
439 	 * We maintain a pointer to any pending timeout for this instance
440 	 * for quick reference/deletion.
441 	 */
442 	timeout_entry_t		*ri_timeout;
443 
444 	/*
445 	 * Instance event queue.  Graph events are queued here as a list
446 	 * of restarter_instance_qentry_t's, and the lock is held separately.
447 	 * If both ri_lock and ri_queue_lock are grabbed, ri_lock must be
448 	 * grabbed first.  ri_queue_lock protects all ri_queue_* structure
449 	 * members.
450 	 */
451 	pthread_mutex_t		ri_queue_lock;
452 	pthread_cond_t		ri_queue_cv;
453 	uu_list_t		*ri_queue;
454 	int			ri_queue_thread;
455 
456 } restarter_inst_t;
457 
458 typedef struct restarter_instance_list {
459 	uu_list_t		*ril_instance_list;
460 	pthread_mutex_t		ril_lock;
461 } restarter_instance_list_t;
462 
463 typedef struct restarter_instance_qentry {
464 	restarter_event_type_t	riq_type;
465 	uu_list_node_t		riq_link;
466 } restarter_instance_qentry_t;
467 
468 typedef struct fork_info {
469 	int			sf_id;
470 	int			sf_method_type;
471 	restarter_error_t	sf_event_type;
472 } fork_info_t;
473 
474 typedef struct wait_info {
475 	uu_list_node_t		wi_link;
476 
477 	int			wi_fd;		/* psinfo file descriptor */
478 	id_t			wi_pid;		/* process ID */
479 	const char		*wi_fmri;	/* instance FMRI */
480 	int			wi_parent;	/* startd is parent */
481 	int			wi_ignore;	/* ignore events */
482 } wait_info_t;
483 
484 #define	STARTD_LOG_FILE		0x1
485 #define	STARTD_LOG_TERMINAL	0x2
486 #define	STARTD_LOG_SYSLOG	0x4
487 
488 #define	STARTD_BOOT_QUIET	0x1
489 #define	STARTD_BOOT_VERBOSE	0x2
490 
491 /*
492  * Internal debug flags used to reduce the amount of data sent to the
493  * internal debug buffer. They can be turned on & off dynamically using
494  * internal_debug_flags variable in mdb. By default, they're off.
495  */
496 #define	DEBUG_DEPENDENCIES	0x1
497 
498 typedef struct startd_state {
499 	/* Logging configuration */
500 	char		*st_log_prefix;	/* directory prefix */
501 	char		*st_log_file;	/* startd file in above dir */
502 	uint_t		st_log_flags;	/* message destination */
503 	int		st_log_level_min; /* minimum required to log */
504 	int		st_log_timezone_known; /* timezone is available */
505 	int		st_log_locale_known; /* locale is available */
506 	int		st_log_login_reached; /* login service reached */
507 
508 	/* Boot configuration */
509 	uint_t		st_boot_flags;	/* serial boot, etc. */
510 	uint_t		st_initial;	/* first startd on system */
511 
512 	/* System configuration */
513 	char		*st_subgraph;	/* milestone subgraph request */
514 
515 	uint_t		st_load_complete;  /* graph load completed */
516 	uint_t		st_load_instances; /* restarter instances to load */
517 	pthread_mutex_t	st_load_lock;
518 	pthread_cond_t	st_load_cv;
519 
520 	/* Repository configuration */
521 	pid_t		st_configd_pid;	/* PID of our svc.configd */
522 					/* instance */
523 	int		st_configd_lives; /* configd started */
524 	pthread_mutex_t	st_configd_live_lock;
525 	pthread_cond_t	st_configd_live_cv;
526 
527 	char		*st_door_path;
528 
529 	/* General information */
530 	uint_t		st_flags;
531 	struct timeval	st_start_time;	/* effective system start time */
532 	char		*st_locale;
533 } startd_state_t;
534 
535 extern startd_state_t *st;
536 
537 extern boolean_t booting_to_single_user;
538 
539 extern const char *event_names[];
540 
541 /*
542  * Structures for contract to instance hash table, implemented in
543  * contract.c and used by restarter.c and method.c
544  */
545 typedef struct contract_entry {
546 	ctid_t		ce_ctid;
547 	int		ce_instid;
548 
549 	uu_list_node_t	ce_link;
550 } contract_entry_t;
551 
552 extern volatile uint16_t	storing_contract;
553 
554 uu_list_pool_t *contract_list_pool;
555 
556 /* contract.c */
557 ctid_t contract_init(void);
558 void contract_abandon(ctid_t);
559 int contract_kill(ctid_t, int, const char *);
560 int contract_is_empty(ctid_t);
561 void contract_hash_init();
562 void contract_hash_store(ctid_t, int);
563 void contract_hash_remove(ctid_t);
564 int lookup_inst_by_contract(ctid_t);
565 
566 /* dict.c */
567 void dict_init(void);
568 int dict_lookup_byname(const char *);
569 int dict_insert(const char *);
570 
571 /* expand.c */
572 int expand_method_tokens(const char *, scf_instance_t *,
573     scf_snapshot_t *, int, char **);
574 
575 /* env.c */
576 void init_env(void);
577 char **set_smf_env(char **, size_t, const char *,
578     const restarter_inst_t *, const char *);
579 
580 /* file.c */
581 int file_ready(graph_vertex_t *);
582 
583 /* fork.c */
584 int fork_mount(char *, char *);
585 void fork_sulogin(boolean_t, const char *, ...);
586 void fork_rc_script(char, const char *, boolean_t);
587 
588 void *fork_configd_thread(void *);
589 
590 pid_t startd_fork1(int *);
591 void fork_with_timeout(const char *, uint_t, uint_t);
592 
593 /* graph.c */
594 void graph_init(void);
595 void *single_user_thread(void *);
596 void *graph_thread(void *);
597 void *graph_event_thread(void *);
598 void *repository_event_thread(void *);
599 int dgraph_add_instance(const char *, scf_instance_t *, boolean_t);
600 void graph_engine_start(void);
601 void graph_enable_by_vertex(graph_vertex_t *, int, int);
602 int refresh_vertex(graph_vertex_t *, scf_instance_t *);
603 void vertex_send_event(graph_vertex_t *, restarter_event_type_t);
604 void graph_start_if_satisfied(graph_vertex_t *);
605 int vertex_subgraph_dependencies_shutdown(scf_handle_t *, graph_vertex_t *,
606     restarter_instance_state_t);
607 void graph_transition_sulogin(restarter_instance_state_t,
608     restarter_instance_state_t);
609 void graph_transition_propagate(graph_vertex_t *, propagate_event_t,
610     restarter_error_t);
611 void graph_offline_subtree_leaves(graph_vertex_t *, void *);
612 void offline_vertex(graph_vertex_t *);
613 
614 /* libscf.c - common */
615 char *inst_fmri_to_svc_fmri(const char *);
616 void *libscf_object_create(void *(*)(scf_handle_t *), scf_handle_t *);
617 int libscf_instance_get_fmri(scf_instance_t *, char **);
618 int libscf_fmri_get_instance(scf_handle_t *, const char *, scf_instance_t **);
619 int libscf_lookup_instance(const char *, scf_instance_t *);
620 int libscf_set_reconfig(int);
621 scf_snapshot_t *libscf_get_or_make_running_snapshot(scf_instance_t *,
622     const char *, boolean_t);
623 int libscf_inst_set_count_prop(scf_instance_t *, const char *,
624     const char *pgtype, uint32_t, const char *, uint64_t);
625 
626 /* libscf.c - used by graph.c */
627 int libscf_get_deathrow(scf_handle_t *, scf_instance_t *, int *);
628 int libscf_get_basic_instance_data(scf_handle_t *, scf_instance_t *,
629     const char *, int *, int *, char **);
630 int libscf_inst_get_or_add_pg(scf_instance_t *, const char *, const char *,
631     uint32_t, scf_propertygroup_t *);
632 int libscf_read_states(const scf_propertygroup_t *,
633     restarter_instance_state_t *, restarter_instance_state_t *);
634 int depgroup_empty(scf_handle_t *, scf_propertygroup_t *);
635 gv_type_t depgroup_read_scheme(scf_handle_t *, scf_propertygroup_t *);
636 depgroup_type_t depgroup_read_grouping(scf_handle_t *, scf_propertygroup_t *);
637 restarter_error_t depgroup_read_restart(scf_handle_t *, scf_propertygroup_t *);
638 int libscf_set_enable_ovr(scf_instance_t *, int);
639 int libscf_set_deathrow(scf_instance_t *, int);
640 int libscf_delete_enable_ovr(scf_instance_t *);
641 int libscf_get_milestone(scf_instance_t *, scf_property_t *, scf_value_t *,
642     char *, size_t);
643 int libscf_extract_runlevel(scf_property_t *, char *);
644 int libscf_clear_runlevel(scf_propertygroup_t *, const char *milestone);
645 
646 typedef int (*callback_t)(void *, void *);
647 
648 int walk_dependency_pgs(scf_instance_t *, callback_t, void *);
649 int walk_property_astrings(scf_property_t *, callback_t, void *);
650 
651 /* libscf.c - used by restarter.c/method.c/expand.c */
652 char *libscf_get_method(scf_handle_t *, int, restarter_inst_t *,
653     scf_snapshot_t *, method_restart_t *, uint_t *, uint8_t *, uint64_t *,
654     uint8_t *);
655 void libscf_populate_graph(scf_handle_t *h);
656 int update_fault_count(restarter_inst_t *, int);
657 int libscf_unset_action(scf_handle_t *, scf_propertygroup_t *, admin_action_t,
658     int64_t);
659 int libscf_get_startd_properties(scf_instance_t *, scf_snapshot_t *, uint_t *,
660     char **);
661 int libscf_get_template_values(scf_instance_t *, scf_snapshot_t *, char **,
662     char **);
663 
664 int libscf_read_method_ids(scf_handle_t *, scf_instance_t *, const char *,
665     ctid_t *, ctid_t *, pid_t *);
666 int libscf_write_start_pid(scf_instance_t *, pid_t);
667 int libscf_write_method_status(scf_instance_t *, const char *, int);
668 int libscf_note_method_log(scf_instance_t *, const char *, const char *);
669 
670 scf_handle_t *libscf_handle_create_bound(scf_version_t);
671 void libscf_handle_rebind(scf_handle_t *);
672 scf_handle_t *libscf_handle_create_bound_loop(void);
673 
674 scf_snapshot_t *libscf_get_running_snapshot(scf_instance_t *);
675 int libscf_snapshots_poststart(scf_handle_t *, const char *, boolean_t);
676 int libscf_snapshots_refresh(scf_instance_t *, const char *);
677 
678 int instance_is_transient_style(restarter_inst_t *);
679 int instance_is_wait_style(restarter_inst_t *);
680 
681 int libscf_create_self(scf_handle_t *);
682 
683 void libscf_reget_instance(restarter_inst_t *);
684 
685 /* log.c */
686 void log_init();
687 void log_error(int, const char *, ...);
688 void log_framework(int, const char *, ...);
689 void log_framework2(int, int, const char *, ...);
690 void log_console(int, const char *, ...);
691 void log_preexec(void);
692 void setlog(const char *);
693 void log_transition(const restarter_inst_t *, start_outcome_t);
694 void log_instance(const restarter_inst_t *, boolean_t, const char *, ...);
695 void log_instance_fmri(const char *, const char *, boolean_t,
696     const char *, ...);
697 
698 /* method.c */
699 void *method_thread(void *);
700 void method_remove_contract(restarter_inst_t *, boolean_t, boolean_t);
701 
702 /* misc.c */
703 void startd_close(int);
704 void startd_fclose(FILE *);
705 int fmri_canonify(const char *, char **, boolean_t);
706 int fs_is_read_only(char *, ulong_t *);
707 int fs_remount(char *);
708 void xstr_sanitize(char *);
709 
710 /* restarter.c */
711 void restarter_init(void);
712 void restarter_start(void);
713 int instance_in_transition(restarter_inst_t *);
714 int restarter_instance_update_states(scf_handle_t *, restarter_inst_t *,
715     restarter_instance_state_t, restarter_instance_state_t, restarter_error_t,
716     char *);
717 int stop_instance_fmri(scf_handle_t *, const char *, uint_t);
718 restarter_inst_t *inst_lookup_by_id(int);
719 void restarter_mark_pending_snapshot(const char *, uint_t);
720 void *restarter_post_fsminimal_thread(void *);
721 void timeout_insert(restarter_inst_t *, ctid_t, uint64_t);
722 void timeout_remove(restarter_inst_t *, ctid_t);
723 void timeout_init(void);
724 int is_timeout_ovr(restarter_inst_t *);
725 
726 /* startd.c */
727 void *safe_realloc(void *, size_t);
728 char *safe_strdup(const char *s);
729 void *startd_alloc_retry(void *(*)(size_t, int), size_t);
730 void startd_free(void *, size_t);
731 uu_list_pool_t *startd_list_pool_create(const char *, size_t, size_t,
732     uu_compare_fn_t *, uint32_t);
733 uu_list_t *startd_list_create(uu_list_pool_t *, void *, uint32_t);
734 pthread_t startd_thread_create(void *(*)(void *), void *);
735 
736 /* special.c */
737 void special_null_transition(void);
738 void special_online_hooks_get(const char *, instance_hook_t *,
739     instance_hook_t *, instance_hook_t *);
740 
741 /* transition.c */
742 int gt_transition(scf_handle_t *, graph_vertex_t *, restarter_error_t,
743     restarter_instance_state_t);
744 
745 /* utmpx.c */
746 void utmpx_init(void);
747 void utmpx_clear_old(void);
748 int utmpx_mark_init(pid_t, char *);
749 void utmpx_mark_dead(pid_t, int, boolean_t);
750 char utmpx_get_runlevel(void);
751 void utmpx_set_runlevel(char, char, boolean_t);
752 void utmpx_write_boottime(void);
753 
754 /* wait.c */
755 void wait_init(void);
756 void wait_prefork(void);
757 void wait_postfork(pid_t);
758 int wait_register(pid_t, const char *, int, int);
759 void *wait_thread(void *);
760 void wait_ignore_by_fmri(const char *);
761 
762 /* proc.c */
763 ctid_t proc_get_ctid();
764 
765 /* deathrow.c */
766 extern void deathrow_init();
767 extern void deathrow_fini();
768 extern boolean_t is_fmri_in_deathrow(const char *);
769 
770 #ifdef	__cplusplus
771 }
772 #endif
773 
774 #endif	/* _STARTD_H */
775