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