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