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