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