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