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