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