xref: /onnv-gate/usr/src/cmd/svc/startd/startd.h (revision 12967:ab9ae749152f)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51712Srm88369  * Common Development and Distribution License (the "License").
61712Srm88369  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
2111466SRoger.Faulkner@Sun.COM 
220Sstevel@tonic-gate /*
23*12967Sgavin.maltby@oracle.com  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_STARTD_H
270Sstevel@tonic-gate #define	_STARTD_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <sys/time.h>
300Sstevel@tonic-gate #include <librestart.h>
310Sstevel@tonic-gate #include <librestart_priv.h>
320Sstevel@tonic-gate #include <libscf.h>
330Sstevel@tonic-gate #include <libsysevent.h>
340Sstevel@tonic-gate #include <libuutil.h>
350Sstevel@tonic-gate #include <pthread.h>
3611466SRoger.Faulkner@Sun.COM #include <synch.h>
370Sstevel@tonic-gate #include <stdio.h>
380Sstevel@tonic-gate #include <syslog.h>
390Sstevel@tonic-gate #include <umem.h>
400Sstevel@tonic-gate 
410Sstevel@tonic-gate #ifdef	__cplusplus
420Sstevel@tonic-gate extern "C" {
430Sstevel@tonic-gate #endif
440Sstevel@tonic-gate 
450Sstevel@tonic-gate /*
4611466SRoger.Faulkner@Sun.COM  * We want MUTEX_HELD, but we also want pthreads.  So we're stuck with this
4711466SRoger.Faulkner@Sun.COM  * for the native build, at least until the build machines can catch up
4811466SRoger.Faulkner@Sun.COM  * with the latest version of MUTEX_HELD() in <synch.h>.
490Sstevel@tonic-gate  */
5011466SRoger.Faulkner@Sun.COM #if defined(NATIVE_BUILD)
5111466SRoger.Faulkner@Sun.COM #undef	MUTEX_HELD
5211466SRoger.Faulkner@Sun.COM #define	MUTEX_HELD(m)		_mutex_held((mutex_t *)(m))
5311466SRoger.Faulkner@Sun.COM #endif
540Sstevel@tonic-gate 
550Sstevel@tonic-gate #ifndef NDEBUG
560Sstevel@tonic-gate 
570Sstevel@tonic-gate #define	MUTEX_LOCK(mp)	{						\
580Sstevel@tonic-gate 	int err;							\
590Sstevel@tonic-gate 	if ((err = pthread_mutex_lock((mp))) != 0) {			\
600Sstevel@tonic-gate 		(void) fprintf(stderr,					\
610Sstevel@tonic-gate 		    "pthread_mutex_lock() failed on %s:%d: %s\n",	\
620Sstevel@tonic-gate 		    __FILE__, __LINE__, strerror(err));			\
630Sstevel@tonic-gate 		abort();						\
640Sstevel@tonic-gate 	}								\
650Sstevel@tonic-gate }
660Sstevel@tonic-gate 
670Sstevel@tonic-gate #define	MUTEX_UNLOCK(mp)	{					\
680Sstevel@tonic-gate 	int err;							\
690Sstevel@tonic-gate 	if ((err = pthread_mutex_unlock((mp))) != 0) {			\
700Sstevel@tonic-gate 		(void) fprintf(stderr,					\
710Sstevel@tonic-gate 		    "pthread_mutex_unlock() failed on %s:%d: %s\n",	\
720Sstevel@tonic-gate 		    __FILE__, __LINE__, strerror(err));			\
730Sstevel@tonic-gate 		abort();						\
740Sstevel@tonic-gate 	}								\
750Sstevel@tonic-gate }
760Sstevel@tonic-gate 
770Sstevel@tonic-gate #else
780Sstevel@tonic-gate 
790Sstevel@tonic-gate #define	MUTEX_LOCK(mp)		(void) pthread_mutex_lock((mp))
800Sstevel@tonic-gate #define	MUTEX_UNLOCK(mp)	(void) pthread_mutex_unlock((mp))
810Sstevel@tonic-gate 
820Sstevel@tonic-gate #endif
830Sstevel@tonic-gate 
840Sstevel@tonic-gate #ifndef NDEBUG
850Sstevel@tonic-gate #define	bad_error(func, err)	{					\
860Sstevel@tonic-gate 	(void) fprintf(stderr, "%s:%d: %s() failed with unexpected "	\
870Sstevel@tonic-gate 	    "error %d.  Aborting.\n", __FILE__, __LINE__, (func), (err)); \
880Sstevel@tonic-gate 	abort();							\
890Sstevel@tonic-gate }
900Sstevel@tonic-gate #else
910Sstevel@tonic-gate #define	bad_error(func, err)	abort()
920Sstevel@tonic-gate #endif
930Sstevel@tonic-gate 
940Sstevel@tonic-gate 
950Sstevel@tonic-gate #define	min(a, b)	(((a) < (b)) ? (a) : (b))
960Sstevel@tonic-gate 
970Sstevel@tonic-gate #define	FAULT_COUNT_INCR	0
980Sstevel@tonic-gate #define	FAULT_COUNT_RESET	1
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate #define	FAULT_THRESHOLD		3
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate #define	MAX_CONFIGD_RETRIES	5
10311996SThomas.Whitten@Sun.COM #define	MAX_EMI_RETRIES		5
1040Sstevel@tonic-gate #define	MAX_MOUNT_RETRIES	5
1050Sstevel@tonic-gate #define	MAX_SULOGIN_RETRIES	5
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate #define	RETURN_SUCCESS		0
1080Sstevel@tonic-gate #define	RETURN_RETRY		-1
1090Sstevel@tonic-gate #define	RETURN_FATAL		-2
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate #define	LIBSCF_SUCCESS		0
1120Sstevel@tonic-gate #define	LIBSCF_PROPERTY_ABSENT	-1
1130Sstevel@tonic-gate #define	LIBSCF_PGROUP_ABSENT	-2
1140Sstevel@tonic-gate #define	LIBSCF_PROPERTY_ERROR	-3
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate #define	METHOD_START		0
1170Sstevel@tonic-gate #define	METHOD_STOP		1
1180Sstevel@tonic-gate #define	METHOD_REFRESH		2
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate #define	METHOD_TIMEOUT_INFINITE	0
1210Sstevel@tonic-gate 
1220Sstevel@tonic-gate /*
1230Sstevel@tonic-gate  * Contract cookies used by startd.
1240Sstevel@tonic-gate  */
1250Sstevel@tonic-gate #define	CONFIGD_COOKIE		0x10
1260Sstevel@tonic-gate #define	SULOGIN_COOKIE		0x11
1270Sstevel@tonic-gate #define	METHOD_START_COOKIE	0x20
1280Sstevel@tonic-gate #define	METHOD_OTHER_COOKIE	0x21
1290Sstevel@tonic-gate #define	MONITOR_COOKIE		0x30
13011996SThomas.Whitten@Sun.COM #define	EMI_COOKIE		0x31
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate #define	ALLOC_RETRY		3
1340Sstevel@tonic-gate #define	ALLOC_DELAY		10
1350Sstevel@tonic-gate #define	ALLOC_DELAY_MULT	10
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate #define	safe_scf_scope_create(h)	\
1380Sstevel@tonic-gate 	libscf_object_create((void *(*)(scf_handle_t *))scf_scope_create, (h))
1390Sstevel@tonic-gate #define	safe_scf_service_create(h)	\
1400Sstevel@tonic-gate 	libscf_object_create((void *(*)(scf_handle_t *))scf_service_create, (h))
1410Sstevel@tonic-gate #define	safe_scf_instance_create(h)	libscf_object_create(	\
1420Sstevel@tonic-gate 	(void *(*)(scf_handle_t *))scf_instance_create, (h))
1430Sstevel@tonic-gate #define	safe_scf_snapshot_create(h)	libscf_object_create(	\
1440Sstevel@tonic-gate 	(void *(*)(scf_handle_t *))scf_snapshot_create, (h))
1450Sstevel@tonic-gate #define	safe_scf_snaplevel_create(h)	libscf_object_create(	\
1460Sstevel@tonic-gate 	(void *(*)(scf_handle_t *))scf_snaplevel_create, (h))
1470Sstevel@tonic-gate #define	safe_scf_pg_create(h)		\
1480Sstevel@tonic-gate 	libscf_object_create((void *(*)(scf_handle_t *))scf_pg_create, (h))
1490Sstevel@tonic-gate #define	safe_scf_property_create(h)	libscf_object_create(	\
1500Sstevel@tonic-gate 	(void *(*)(scf_handle_t *))scf_property_create, (h))
1510Sstevel@tonic-gate #define	safe_scf_value_create(h)	\
1520Sstevel@tonic-gate 	libscf_object_create((void *(*)(scf_handle_t *))scf_value_create, (h))
1530Sstevel@tonic-gate #define	safe_scf_iter_create(h)		\
1540Sstevel@tonic-gate 	libscf_object_create((void *(*)(scf_handle_t *))scf_iter_create, (h))
1550Sstevel@tonic-gate #define	safe_scf_transaction_create(h)	libscf_object_create(	\
1560Sstevel@tonic-gate 	(void *(*)(scf_handle_t *))	scf_transaction_create, (h))
1570Sstevel@tonic-gate #define	safe_scf_entry_create(h)	\
1580Sstevel@tonic-gate 	libscf_object_create((void *(*)(scf_handle_t *))scf_entry_create, (h))
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate #define	startd_alloc(sz)	\
1610Sstevel@tonic-gate 	startd_alloc_retry((void *(*)(size_t, int))umem_alloc, (sz))
1620Sstevel@tonic-gate #define	startd_zalloc(sz)	\
1630Sstevel@tonic-gate 	startd_alloc_retry((void *(*)(size_t, int))umem_zalloc, (sz))
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate extern pthread_mutexattr_t mutex_attrs;
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate /*
1690Sstevel@tonic-gate  * Definitions for administrative actions.
1700Sstevel@tonic-gate  *   Note that the ordering in admin_action_t, admin_actions, and admin_events
1710Sstevel@tonic-gate  *   must match.  admin_actions and admin_events are defined in startd.c.
1720Sstevel@tonic-gate  */
1730Sstevel@tonic-gate #define	NACTIONS			6
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate typedef enum {
1760Sstevel@tonic-gate 	ADMIN_EVENT_DEGRADED = 0x0,
1770Sstevel@tonic-gate 	ADMIN_EVENT_MAINT_OFF,
1780Sstevel@tonic-gate 	ADMIN_EVENT_MAINT_ON,
1790Sstevel@tonic-gate 	ADMIN_EVENT_MAINT_ON_IMMEDIATE,
1800Sstevel@tonic-gate 	ADMIN_EVENT_REFRESH,
1810Sstevel@tonic-gate 	ADMIN_EVENT_RESTART
1820Sstevel@tonic-gate } admin_action_t;
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate extern const char * const admin_actions[NACTIONS];
1850Sstevel@tonic-gate extern const int admin_events[NACTIONS];
1860Sstevel@tonic-gate 
1870Sstevel@tonic-gate #define	LOG_DATE_SIZE	32	/* Max size of timestamp in log output */
1880Sstevel@tonic-gate 
1890Sstevel@tonic-gate extern ssize_t max_scf_name_size;
1900Sstevel@tonic-gate extern ssize_t max_scf_value_size;
1910Sstevel@tonic-gate extern ssize_t max_scf_fmri_size;
1920Sstevel@tonic-gate 
1930Sstevel@tonic-gate extern mode_t fmask;
1940Sstevel@tonic-gate extern mode_t dmask;
1950Sstevel@tonic-gate 
1960Sstevel@tonic-gate #define	LOG_PREFIX_EARLY	"/etc/svc/volatile/"
1970Sstevel@tonic-gate #define	LOG_PREFIX_NORMAL	"/var/svc/log/"
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate #define	LOG_SUFFIX		".log"
2000Sstevel@tonic-gate 
2010Sstevel@tonic-gate #define	STARTD_DEFAULT_LOG	"svc.startd.log"
20211996SThomas.Whitten@Sun.COM #define	EMI_LOG ((const char *) "system-early-manifest-import:default.log")
2030Sstevel@tonic-gate 
2040Sstevel@tonic-gate extern const char *log_directory;	/* Current log directory path */
2050Sstevel@tonic-gate 
2060Sstevel@tonic-gate #define	FS_TIMEZONE_DIR		"/usr/share/lib/zoneinfo"
2070Sstevel@tonic-gate #define	FS_LOCALE_DIR		"/usr/lib/locale"
2080Sstevel@tonic-gate 
2090Sstevel@tonic-gate /*
2100Sstevel@tonic-gate  * Simple dictionary representation.
2110Sstevel@tonic-gate  */
2120Sstevel@tonic-gate typedef struct dictionary {
2130Sstevel@tonic-gate 	uu_list_t		*dict_list;
2140Sstevel@tonic-gate 	int			dict_new_id;
2150Sstevel@tonic-gate 	pthread_mutex_t		dict_lock;
2160Sstevel@tonic-gate } dictionary_t;
2170Sstevel@tonic-gate 
2180Sstevel@tonic-gate typedef struct dict_entry {
2190Sstevel@tonic-gate 	int			de_id;
2200Sstevel@tonic-gate 	const char		*de_name;
2210Sstevel@tonic-gate 	uu_list_node_t		de_link;
2220Sstevel@tonic-gate } dict_entry_t;
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate extern dictionary_t *dictionary;
2250Sstevel@tonic-gate 
2260Sstevel@tonic-gate typedef struct timeout_queue {
2270Sstevel@tonic-gate 	uu_list_t		*tq_list;
2280Sstevel@tonic-gate 	pthread_mutex_t		tq_lock;
2290Sstevel@tonic-gate } timeout_queue_t;
2300Sstevel@tonic-gate 
2310Sstevel@tonic-gate typedef struct timeout_entry {
2320Sstevel@tonic-gate 	hrtime_t		te_timeout;	/* timeout expiration time */
2330Sstevel@tonic-gate 	ctid_t			te_ctid;
2340Sstevel@tonic-gate 	char			*te_fmri;
2350Sstevel@tonic-gate 	char			*te_logstem;
2360Sstevel@tonic-gate 	volatile int		te_fired;
2370Sstevel@tonic-gate 	uu_list_node_t		te_link;
2380Sstevel@tonic-gate } timeout_entry_t;
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate extern timeout_queue_t *timeouts;
2410Sstevel@tonic-gate 
2420Sstevel@tonic-gate /*
2430Sstevel@tonic-gate  * State definitions.
2440Sstevel@tonic-gate  */
2450Sstevel@tonic-gate typedef enum {
2460Sstevel@tonic-gate 	STATE_NONE = 0x0,
2470Sstevel@tonic-gate 	STATE_UNINIT,
2480Sstevel@tonic-gate 	STATE_MAINT,
2490Sstevel@tonic-gate 	STATE_OFFLINE,
2500Sstevel@tonic-gate 	STATE_DISABLED,
2510Sstevel@tonic-gate 	STATE_ONLINE,
2520Sstevel@tonic-gate 	STATE_DEGRADED
2530Sstevel@tonic-gate } instance_state_t;
2540Sstevel@tonic-gate 
2550Sstevel@tonic-gate #define	STATE_MAX	(STATE_DEGRADED + 1)
2560Sstevel@tonic-gate 
2570Sstevel@tonic-gate extern const char * const instance_state_str[STATE_MAX];
2580Sstevel@tonic-gate 
2590Sstevel@tonic-gate typedef enum {
2600Sstevel@tonic-gate 	GVT_UNSUPPORTED = -1,
2610Sstevel@tonic-gate 	GVT_UNKNOWN = 0,
2620Sstevel@tonic-gate 	GVT_SVC,		/* service */
2630Sstevel@tonic-gate 	GVT_INST,		/* instance */
2640Sstevel@tonic-gate 	GVT_FILE,		/* file: */
2650Sstevel@tonic-gate 	GVT_GROUP		/* dependency group */
2660Sstevel@tonic-gate } gv_type_t;
2670Sstevel@tonic-gate 
2680Sstevel@tonic-gate typedef enum {
2690Sstevel@tonic-gate 	DEPGRP_UNSUPPORTED = -1,
2700Sstevel@tonic-gate 	DEPGRP_REQUIRE_ANY = 1,
2710Sstevel@tonic-gate 	DEPGRP_REQUIRE_ALL,
2720Sstevel@tonic-gate 	DEPGRP_EXCLUDE_ALL,
2730Sstevel@tonic-gate 	DEPGRP_OPTIONAL_ALL
2740Sstevel@tonic-gate } depgroup_type_t;
2750Sstevel@tonic-gate 
2760Sstevel@tonic-gate typedef enum {
2770Sstevel@tonic-gate 	METHOD_RESTART_UNKNOWN = -1,
2780Sstevel@tonic-gate 	METHOD_RESTART_ALL = 0,
2790Sstevel@tonic-gate 	METHOD_RESTART_EXTERNAL_FAULT,
2800Sstevel@tonic-gate 	METHOD_RESTART_ANY_FAULT,
2810Sstevel@tonic-gate 	METHOD_RESTART_OTHER
2820Sstevel@tonic-gate } method_restart_t;
2830Sstevel@tonic-gate 
2842339Slianep typedef enum {
2852339Slianep 	PROPAGATE_START,
2862339Slianep 	PROPAGATE_STOP,
2872339Slianep 	PROPAGATE_SAT
2882339Slianep } propagate_event_t;
2892339Slianep 
2900Sstevel@tonic-gate /*
2910Sstevel@tonic-gate  * Graph representation.
2920Sstevel@tonic-gate  */
2930Sstevel@tonic-gate #define	GV_CONFIGURED	0x01	/* Service exists in repository, ready */
2940Sstevel@tonic-gate #define	GV_ENABLED	0x02	/* Service should be online */
2950Sstevel@tonic-gate #define	GV_ENBLD_NOOVR	0x04	/* GV_ENABLED, ignoring override */
2960Sstevel@tonic-gate #define	GV_INSUBGRAPH	0x08	/* Current milestone depends on service */
2977475SPhilippe.Jung@Sun.COM #define	GV_DEATHROW	0x10	/* Service is on deathrow */
2987630SRenaud.Manus@Sun.COM #define	GV_TOOFFLINE	0x20	/* Services in subtree to offline */
2997630SRenaud.Manus@Sun.COM #define	GV_TODISABLE	0x40	/* Services in subtree to disable */
3000Sstevel@tonic-gate 
3010Sstevel@tonic-gate /* ID must come first to support search */
3020Sstevel@tonic-gate typedef struct graph_vertex {
3030Sstevel@tonic-gate 	int				gv_id;
3040Sstevel@tonic-gate 	char				*gv_name;
3050Sstevel@tonic-gate 	uu_list_node_t			gv_link;
3060Sstevel@tonic-gate 
3070Sstevel@tonic-gate 	uint_t				gv_flags;
3080Sstevel@tonic-gate 	restarter_instance_state_t	gv_state;
3090Sstevel@tonic-gate 
3100Sstevel@tonic-gate 	gv_type_t			gv_type;
3110Sstevel@tonic-gate 
3120Sstevel@tonic-gate 	depgroup_type_t			gv_depgroup;
3130Sstevel@tonic-gate 	restarter_error_t		gv_restart;
3140Sstevel@tonic-gate 
3150Sstevel@tonic-gate 	void				(*gv_start_f)(struct graph_vertex *);
3160Sstevel@tonic-gate 	void				(*gv_post_online_f)(void);
3170Sstevel@tonic-gate 	void				(*gv_post_disable_f)(void);
3180Sstevel@tonic-gate 
3190Sstevel@tonic-gate 	int				gv_restarter_id;
3200Sstevel@tonic-gate 	evchan_t			*gv_restarter_channel;
3210Sstevel@tonic-gate 
3220Sstevel@tonic-gate 	int				gv_delegate_initialized;
3230Sstevel@tonic-gate 	evchan_t			*gv_delegate_channel;
3240Sstevel@tonic-gate 
3250Sstevel@tonic-gate 	uu_list_t			*gv_dependencies;
3260Sstevel@tonic-gate 	uu_list_t			*gv_dependents;
3271712Srm88369 
3281712Srm88369 	/*
3291712Srm88369 	 * gv_refs represents the number of references besides dependencies.
3301712Srm88369 	 * The vertex cannot be removed when gv_refs > 0.
3311712Srm88369 	 *
3321712Srm88369 	 * Currently, only relevant for GVT_SVC and GVT_INST type vertices.
3331712Srm88369 	 */
3341712Srm88369 	int 				gv_refs;
335*12967Sgavin.maltby@oracle.com 
336*12967Sgavin.maltby@oracle.com 	int32_t				gv_stn_tset;
337*12967Sgavin.maltby@oracle.com 	int32_t				gv_reason;
3380Sstevel@tonic-gate } graph_vertex_t;
3390Sstevel@tonic-gate 
3400Sstevel@tonic-gate typedef struct graph_edge {
3410Sstevel@tonic-gate 	graph_vertex_t	*ge_vertex;
3420Sstevel@tonic-gate 	uu_list_node_t	ge_link;
3430Sstevel@tonic-gate 	graph_vertex_t	*ge_parent;
3440Sstevel@tonic-gate } graph_edge_t;
3450Sstevel@tonic-gate 
346*12967Sgavin.maltby@oracle.com int libscf_get_info_events_all(scf_propertygroup_t *);
347*12967Sgavin.maltby@oracle.com int32_t libscf_get_stn_tset(scf_instance_t *);
348*12967Sgavin.maltby@oracle.com 
3490Sstevel@tonic-gate /*
3501958Slianep  * Restarter transition outcomes
3510Sstevel@tonic-gate  */
3520Sstevel@tonic-gate typedef enum {
3531958Slianep 	MAINT_REQUESTED,
3540Sstevel@tonic-gate 	START_REQUESTED,
3550Sstevel@tonic-gate 	START_FAILED_REPEATEDLY,
3560Sstevel@tonic-gate 	START_FAILED_CONFIGURATION,
3570Sstevel@tonic-gate 	START_FAILED_FATAL,
3580Sstevel@tonic-gate 	START_FAILED_TIMEOUT_FATAL,
3590Sstevel@tonic-gate 	START_FAILED_OTHER
3600Sstevel@tonic-gate } start_outcome_t;
3610Sstevel@tonic-gate 
3620Sstevel@tonic-gate typedef void (*instance_hook_t)(void);
3630Sstevel@tonic-gate 
3640Sstevel@tonic-gate typedef struct service_hook_assn {
3650Sstevel@tonic-gate 	char	*sh_fmri;
3660Sstevel@tonic-gate 	instance_hook_t	sh_pre_online_hook;
3670Sstevel@tonic-gate 	instance_hook_t	sh_post_online_hook;
3680Sstevel@tonic-gate 	instance_hook_t	sh_post_offline_hook;
3690Sstevel@tonic-gate } service_hook_assn_t;
3700Sstevel@tonic-gate 
3710Sstevel@tonic-gate /*
3720Sstevel@tonic-gate  * Restarter instance stop reasons.
3730Sstevel@tonic-gate  */
3740Sstevel@tonic-gate typedef enum {
3750Sstevel@tonic-gate 	RSTOP_EXIT = 0x0,	/* exited or empty */
3760Sstevel@tonic-gate 	RSTOP_CORE,		/* core dumped */
3770Sstevel@tonic-gate 	RSTOP_SIGNAL,		/* external fatal signal received */
3780Sstevel@tonic-gate 	RSTOP_HWERR,		/* uncorrectable hardware error */
3790Sstevel@tonic-gate 	RSTOP_DEPENDENCY,	/* dependency activity caused stop */
3800Sstevel@tonic-gate 	RSTOP_DISABLE,		/* disabled */
3810Sstevel@tonic-gate 	RSTOP_RESTART		/* restart requested */
3820Sstevel@tonic-gate } stop_cause_t;
3830Sstevel@tonic-gate 
3840Sstevel@tonic-gate /*
3850Sstevel@tonic-gate  * Restarter instance maintenance clear reasons.
3860Sstevel@tonic-gate  */
3870Sstevel@tonic-gate typedef enum {
3880Sstevel@tonic-gate 	RUNMAINT_CLEAR = 0x0,
3890Sstevel@tonic-gate 	RUNMAINT_DISABLE
3900Sstevel@tonic-gate } unmaint_cause_t;
3910Sstevel@tonic-gate 
3920Sstevel@tonic-gate /*
3930Sstevel@tonic-gate  * Restarter instance flags
3940Sstevel@tonic-gate  */
3950Sstevel@tonic-gate #define	RINST_CONTRACT		0x00000000	/* progeny constitute inst */
3960Sstevel@tonic-gate #define	RINST_TRANSIENT		0x10000000	/* inst operates momentarily */
3970Sstevel@tonic-gate #define	RINST_WAIT		0x20000000	/* child constitutes inst */
3980Sstevel@tonic-gate #define	RINST_STYLE_MASK	0xf0000000
3990Sstevel@tonic-gate 
4000Sstevel@tonic-gate #define	RINST_RETAKE_RUNNING	0x01000000	/* pending running snapshot */
4010Sstevel@tonic-gate #define	RINST_RETAKE_START	0x02000000	/* pending start snapshot */
4020Sstevel@tonic-gate 
4030Sstevel@tonic-gate #define	RINST_RETAKE_MASK	0x0f000000
4040Sstevel@tonic-gate 
40511482SSean.Wilcox@Sun.COM #define	RINST_START_TIMES	5		/* failures to consider */
40611482SSean.Wilcox@Sun.COM #define	RINST_FAILURE_RATE_NS	600000000000LL	/* 1 failure/10 minutes */
4070Sstevel@tonic-gate 
4080Sstevel@tonic-gate /* Number of events in the queue when we start dropping ADMIN events. */
4090Sstevel@tonic-gate #define	RINST_QUEUE_THRESHOLD	100
4100Sstevel@tonic-gate 
4110Sstevel@tonic-gate typedef struct restarter_inst {
4120Sstevel@tonic-gate 	int			ri_id;
4130Sstevel@tonic-gate 	instance_data_t		ri_i;
4140Sstevel@tonic-gate 	char			*ri_common_name; /* template localized name */
4150Sstevel@tonic-gate 	char			*ri_C_common_name; /* C locale name */
4160Sstevel@tonic-gate 
4170Sstevel@tonic-gate 	char			*ri_logstem;	/* logfile name */
4180Sstevel@tonic-gate 	char			*ri_utmpx_prefix;
4190Sstevel@tonic-gate 	uint_t			ri_flags;
4200Sstevel@tonic-gate 	instance_hook_t		ri_pre_online_hook;
4210Sstevel@tonic-gate 	instance_hook_t		ri_post_online_hook;
4220Sstevel@tonic-gate 	instance_hook_t		ri_post_offline_hook;
4230Sstevel@tonic-gate 
4240Sstevel@tonic-gate 	hrtime_t		ri_start_time[RINST_START_TIMES];
4250Sstevel@tonic-gate 	uint_t			ri_start_index;	/* times started */
4260Sstevel@tonic-gate 
4270Sstevel@tonic-gate 	uu_list_node_t		ri_link;
4280Sstevel@tonic-gate 	pthread_mutex_t		ri_lock;
4290Sstevel@tonic-gate 
4300Sstevel@tonic-gate 	/*
4310Sstevel@tonic-gate 	 * When we start a thread to we execute a method for this instance, we
4320Sstevel@tonic-gate 	 * put the thread id in ri_method_thread.  Threads with ids other than
4330Sstevel@tonic-gate 	 * this which acquire ri_lock while ri_method_thread is nonzero should
4340Sstevel@tonic-gate 	 * wait on ri_method_cv.  ri_method_waiters should be incremented while
4350Sstevel@tonic-gate 	 * waiting so the instance won't be deleted.
4360Sstevel@tonic-gate 	 */
4370Sstevel@tonic-gate 	pthread_t		ri_method_thread;
4380Sstevel@tonic-gate 	pthread_cond_t		ri_method_cv;
4390Sstevel@tonic-gate 	uint_t			ri_method_waiters;
4400Sstevel@tonic-gate 
4410Sstevel@tonic-gate 	/*
4420Sstevel@tonic-gate 	 * These fields are provided so functions can operate on this structure
4430Sstevel@tonic-gate 	 * and the repository without worrying about whether the instance has
4440Sstevel@tonic-gate 	 * been deleted from the repository (this is possible because
4450Sstevel@tonic-gate 	 * ri_i.i_fmri names the instance this structure represents -- see
4460Sstevel@tonic-gate 	 * libscf_reget_inst()).  ri_m_inst is the scf_instance_t for the
4470Sstevel@tonic-gate 	 * instance, and ri_mi_deleted is true if the instance has been deleted.
4480Sstevel@tonic-gate 	 */
4490Sstevel@tonic-gate 	scf_instance_t		*ri_m_inst;
4500Sstevel@tonic-gate 	boolean_t		ri_mi_deleted;
4510Sstevel@tonic-gate 
4520Sstevel@tonic-gate 	/*
4530Sstevel@tonic-gate 	 * We maintain a pointer to any pending timeout for this instance
4540Sstevel@tonic-gate 	 * for quick reference/deletion.
4550Sstevel@tonic-gate 	 */
4560Sstevel@tonic-gate 	timeout_entry_t		*ri_timeout;
4570Sstevel@tonic-gate 
4580Sstevel@tonic-gate 	/*
4590Sstevel@tonic-gate 	 * Instance event queue.  Graph events are queued here as a list
4600Sstevel@tonic-gate 	 * of restarter_instance_qentry_t's, and the lock is held separately.
4610Sstevel@tonic-gate 	 * If both ri_lock and ri_queue_lock are grabbed, ri_lock must be
4620Sstevel@tonic-gate 	 * grabbed first.  ri_queue_lock protects all ri_queue_* structure
4630Sstevel@tonic-gate 	 * members.
4640Sstevel@tonic-gate 	 */
4650Sstevel@tonic-gate 	pthread_mutex_t		ri_queue_lock;
4660Sstevel@tonic-gate 	pthread_cond_t		ri_queue_cv;
4670Sstevel@tonic-gate 	uu_list_t		*ri_queue;
4680Sstevel@tonic-gate 	int			ri_queue_thread;
4690Sstevel@tonic-gate 
4700Sstevel@tonic-gate } restarter_inst_t;
4710Sstevel@tonic-gate 
4720Sstevel@tonic-gate typedef struct restarter_instance_list {
4730Sstevel@tonic-gate 	uu_list_t		*ril_instance_list;
4740Sstevel@tonic-gate 	pthread_mutex_t		ril_lock;
4750Sstevel@tonic-gate } restarter_instance_list_t;
4760Sstevel@tonic-gate 
4770Sstevel@tonic-gate typedef struct restarter_instance_qentry {
4780Sstevel@tonic-gate 	restarter_event_type_t	riq_type;
479*12967Sgavin.maltby@oracle.com 	int32_t			riq_reason;
4800Sstevel@tonic-gate 	uu_list_node_t		riq_link;
4810Sstevel@tonic-gate } restarter_instance_qentry_t;
4820Sstevel@tonic-gate 
4830Sstevel@tonic-gate typedef struct fork_info {
4840Sstevel@tonic-gate 	int			sf_id;
4850Sstevel@tonic-gate 	int			sf_method_type;
4860Sstevel@tonic-gate 	restarter_error_t	sf_event_type;
487*12967Sgavin.maltby@oracle.com 	restarter_str_t		sf_reason;
4880Sstevel@tonic-gate } fork_info_t;
4890Sstevel@tonic-gate 
4900Sstevel@tonic-gate typedef struct wait_info {
4910Sstevel@tonic-gate 	uu_list_node_t		wi_link;
4920Sstevel@tonic-gate 
4930Sstevel@tonic-gate 	int			wi_fd;		/* psinfo file descriptor */
4940Sstevel@tonic-gate 	id_t			wi_pid;		/* process ID */
4950Sstevel@tonic-gate 	const char		*wi_fmri;	/* instance FMRI */
4960Sstevel@tonic-gate 	int			wi_parent;	/* startd is parent */
4977219Srm88369 	int			wi_ignore;	/* ignore events */
4980Sstevel@tonic-gate } wait_info_t;
4990Sstevel@tonic-gate 
5000Sstevel@tonic-gate #define	STARTD_LOG_FILE		0x1
5010Sstevel@tonic-gate #define	STARTD_LOG_TERMINAL	0x2
5020Sstevel@tonic-gate #define	STARTD_LOG_SYSLOG	0x4
5030Sstevel@tonic-gate 
5040Sstevel@tonic-gate #define	STARTD_BOOT_QUIET	0x1
5050Sstevel@tonic-gate #define	STARTD_BOOT_VERBOSE	0x2
5060Sstevel@tonic-gate 
5075680Srm88369 /*
5085680Srm88369  * Internal debug flags used to reduce the amount of data sent to the
5095680Srm88369  * internal debug buffer. They can be turned on & off dynamically using
5105680Srm88369  * internal_debug_flags variable in mdb. By default, they're off.
5115680Srm88369  */
5125680Srm88369 #define	DEBUG_DEPENDENCIES	0x1
5135680Srm88369 
5140Sstevel@tonic-gate typedef struct startd_state {
5150Sstevel@tonic-gate 	/* Logging configuration */
5160Sstevel@tonic-gate 	char		*st_log_prefix;	/* directory prefix */
5170Sstevel@tonic-gate 	char		*st_log_file;	/* startd file in above dir */
5180Sstevel@tonic-gate 	uint_t		st_log_flags;	/* message destination */
5190Sstevel@tonic-gate 	int		st_log_level_min; /* minimum required to log */
5200Sstevel@tonic-gate 	int		st_log_timezone_known; /* timezone is available */
5210Sstevel@tonic-gate 	int		st_log_locale_known; /* locale is available */
5220Sstevel@tonic-gate 	int		st_log_login_reached; /* login service reached */
5230Sstevel@tonic-gate 
5240Sstevel@tonic-gate 	/* Boot configuration */
5250Sstevel@tonic-gate 	uint_t		st_boot_flags;	/* serial boot, etc. */
5260Sstevel@tonic-gate 	uint_t		st_initial;	/* first startd on system */
5270Sstevel@tonic-gate 
5280Sstevel@tonic-gate 	/* System configuration */
5290Sstevel@tonic-gate 	char		*st_subgraph;	/* milestone subgraph request */
5300Sstevel@tonic-gate 
5310Sstevel@tonic-gate 	uint_t		st_load_complete;  /* graph load completed */
5320Sstevel@tonic-gate 	uint_t		st_load_instances; /* restarter instances to load */
5330Sstevel@tonic-gate 	pthread_mutex_t	st_load_lock;
5340Sstevel@tonic-gate 	pthread_cond_t	st_load_cv;
5350Sstevel@tonic-gate 
5360Sstevel@tonic-gate 	/* Repository configuration */
5370Sstevel@tonic-gate 	pid_t		st_configd_pid;	/* PID of our svc.configd */
5380Sstevel@tonic-gate 					/* instance */
5390Sstevel@tonic-gate 	int		st_configd_lives; /* configd started */
5400Sstevel@tonic-gate 	pthread_mutex_t	st_configd_live_lock;
5410Sstevel@tonic-gate 	pthread_cond_t	st_configd_live_cv;
5420Sstevel@tonic-gate 
5430Sstevel@tonic-gate 	char		*st_door_path;
5440Sstevel@tonic-gate 
5450Sstevel@tonic-gate 	/* General information */
5460Sstevel@tonic-gate 	uint_t		st_flags;
5470Sstevel@tonic-gate 	struct timeval	st_start_time;	/* effective system start time */
5480Sstevel@tonic-gate 	char		*st_locale;
5490Sstevel@tonic-gate } startd_state_t;
5500Sstevel@tonic-gate 
5510Sstevel@tonic-gate extern startd_state_t *st;
5520Sstevel@tonic-gate 
5530Sstevel@tonic-gate extern boolean_t booting_to_single_user;
5540Sstevel@tonic-gate 
5550Sstevel@tonic-gate extern const char *event_names[];
5560Sstevel@tonic-gate 
5570Sstevel@tonic-gate /*
5580Sstevel@tonic-gate  * Structures for contract to instance hash table, implemented in
5590Sstevel@tonic-gate  * contract.c and used by restarter.c and method.c
5600Sstevel@tonic-gate  */
5610Sstevel@tonic-gate typedef struct contract_entry {
5620Sstevel@tonic-gate 	ctid_t		ce_ctid;
5630Sstevel@tonic-gate 	int		ce_instid;
5640Sstevel@tonic-gate 
5650Sstevel@tonic-gate 	uu_list_node_t	ce_link;
5660Sstevel@tonic-gate } contract_entry_t;
5670Sstevel@tonic-gate 
5684244Sjeanm extern volatile uint16_t	storing_contract;
5694244Sjeanm 
5700Sstevel@tonic-gate uu_list_pool_t *contract_list_pool;
5710Sstevel@tonic-gate 
5720Sstevel@tonic-gate /* contract.c */
5730Sstevel@tonic-gate ctid_t contract_init(void);
5740Sstevel@tonic-gate void contract_abandon(ctid_t);
5750Sstevel@tonic-gate int contract_kill(ctid_t, int, const char *);
5760Sstevel@tonic-gate int contract_is_empty(ctid_t);
5770Sstevel@tonic-gate void contract_hash_init();
5780Sstevel@tonic-gate void contract_hash_store(ctid_t, int);
5790Sstevel@tonic-gate void contract_hash_remove(ctid_t);
5800Sstevel@tonic-gate int lookup_inst_by_contract(ctid_t);
5810Sstevel@tonic-gate 
5820Sstevel@tonic-gate /* dict.c */
5830Sstevel@tonic-gate void dict_init(void);
5840Sstevel@tonic-gate int dict_lookup_byname(const char *);
5850Sstevel@tonic-gate int dict_insert(const char *);
5860Sstevel@tonic-gate 
5870Sstevel@tonic-gate /* expand.c */
5880Sstevel@tonic-gate int expand_method_tokens(const char *, scf_instance_t *,
5890Sstevel@tonic-gate     scf_snapshot_t *, int, char **);
5900Sstevel@tonic-gate 
5910Sstevel@tonic-gate /* env.c */
5920Sstevel@tonic-gate void init_env(void);
5930Sstevel@tonic-gate char **set_smf_env(char **, size_t, const char *,
5940Sstevel@tonic-gate     const restarter_inst_t *, const char *);
5950Sstevel@tonic-gate 
5960Sstevel@tonic-gate /* file.c */
5970Sstevel@tonic-gate int file_ready(graph_vertex_t *);
5980Sstevel@tonic-gate 
5990Sstevel@tonic-gate /* fork.c */
6000Sstevel@tonic-gate int fork_mount(char *, char *);
6010Sstevel@tonic-gate void fork_sulogin(boolean_t, const char *, ...);
6020Sstevel@tonic-gate void fork_rc_script(char, const char *, boolean_t);
6030Sstevel@tonic-gate 
6040Sstevel@tonic-gate void *fork_configd_thread(void *);
6050Sstevel@tonic-gate 
6060Sstevel@tonic-gate pid_t startd_fork1(int *);
6078944Sdp@eng.sun.com void fork_with_timeout(const char *, uint_t, uint_t);
60811996SThomas.Whitten@Sun.COM void fork_emi();
6090Sstevel@tonic-gate 
6100Sstevel@tonic-gate /* graph.c */
6110Sstevel@tonic-gate void graph_init(void);
6120Sstevel@tonic-gate void *single_user_thread(void *);
6130Sstevel@tonic-gate void *graph_thread(void *);
6140Sstevel@tonic-gate void *graph_event_thread(void *);
6150Sstevel@tonic-gate void *repository_event_thread(void *);
6160Sstevel@tonic-gate int dgraph_add_instance(const char *, scf_instance_t *, boolean_t);
6170Sstevel@tonic-gate void graph_engine_start(void);
6181958Slianep void graph_enable_by_vertex(graph_vertex_t *, int, int);
6191958Slianep int refresh_vertex(graph_vertex_t *, scf_instance_t *);
6201958Slianep void vertex_send_event(graph_vertex_t *, restarter_event_type_t);
6211958Slianep void graph_start_if_satisfied(graph_vertex_t *);
6222747Sbustos int vertex_subgraph_dependencies_shutdown(scf_handle_t *, graph_vertex_t *,
6232747Sbustos     restarter_instance_state_t);
6241958Slianep void graph_transition_sulogin(restarter_instance_state_t,
6251958Slianep     restarter_instance_state_t);
6262339Slianep void graph_transition_propagate(graph_vertex_t *, propagate_event_t,
6271958Slianep     restarter_error_t);
6287630SRenaud.Manus@Sun.COM void graph_offline_subtree_leaves(graph_vertex_t *, void *);
6299333SRenaud.Manus@Sun.COM void offline_vertex(graph_vertex_t *);
6300Sstevel@tonic-gate 
6310Sstevel@tonic-gate /* libscf.c - common */
6320Sstevel@tonic-gate char *inst_fmri_to_svc_fmri(const char *);
6330Sstevel@tonic-gate void *libscf_object_create(void *(*)(scf_handle_t *), scf_handle_t *);
6340Sstevel@tonic-gate int libscf_instance_get_fmri(scf_instance_t *, char **);
6350Sstevel@tonic-gate int libscf_fmri_get_instance(scf_handle_t *, const char *, scf_instance_t **);
6360Sstevel@tonic-gate int libscf_lookup_instance(const char *, scf_instance_t *);
6370Sstevel@tonic-gate int libscf_set_reconfig(int);
6380Sstevel@tonic-gate scf_snapshot_t *libscf_get_or_make_running_snapshot(scf_instance_t *,
6390Sstevel@tonic-gate     const char *, boolean_t);
6400Sstevel@tonic-gate int libscf_inst_set_count_prop(scf_instance_t *, const char *,
6410Sstevel@tonic-gate     const char *pgtype, uint32_t, const char *, uint64_t);
6420Sstevel@tonic-gate 
6430Sstevel@tonic-gate /* libscf.c - used by graph.c */
6447475SPhilippe.Jung@Sun.COM int libscf_get_deathrow(scf_handle_t *, scf_instance_t *, int *);
6450Sstevel@tonic-gate int libscf_get_basic_instance_data(scf_handle_t *, scf_instance_t *,
6460Sstevel@tonic-gate     const char *, int *, int *, char **);
6470Sstevel@tonic-gate int libscf_inst_get_or_add_pg(scf_instance_t *, const char *, const char *,
6480Sstevel@tonic-gate     uint32_t, scf_propertygroup_t *);
6490Sstevel@tonic-gate int libscf_read_states(const scf_propertygroup_t *,
6500Sstevel@tonic-gate     restarter_instance_state_t *, restarter_instance_state_t *);
6510Sstevel@tonic-gate int depgroup_empty(scf_handle_t *, scf_propertygroup_t *);
6520Sstevel@tonic-gate gv_type_t depgroup_read_scheme(scf_handle_t *, scf_propertygroup_t *);
6530Sstevel@tonic-gate depgroup_type_t depgroup_read_grouping(scf_handle_t *, scf_propertygroup_t *);
6540Sstevel@tonic-gate restarter_error_t depgroup_read_restart(scf_handle_t *, scf_propertygroup_t *);
6550Sstevel@tonic-gate int libscf_set_enable_ovr(scf_instance_t *, int);
6567475SPhilippe.Jung@Sun.COM int libscf_set_deathrow(scf_instance_t *, int);
6570Sstevel@tonic-gate int libscf_delete_enable_ovr(scf_instance_t *);
6580Sstevel@tonic-gate int libscf_get_milestone(scf_instance_t *, scf_property_t *, scf_value_t *,
6590Sstevel@tonic-gate     char *, size_t);
6600Sstevel@tonic-gate int libscf_extract_runlevel(scf_property_t *, char *);
6610Sstevel@tonic-gate int libscf_clear_runlevel(scf_propertygroup_t *, const char *milestone);
6620Sstevel@tonic-gate 
6630Sstevel@tonic-gate typedef int (*callback_t)(void *, void *);
6640Sstevel@tonic-gate 
6650Sstevel@tonic-gate int walk_dependency_pgs(scf_instance_t *, callback_t, void *);
6660Sstevel@tonic-gate int walk_property_astrings(scf_property_t *, callback_t, void *);
66711482SSean.Wilcox@Sun.COM void libscf_reset_start_times(restarter_inst_t *, int);
6680Sstevel@tonic-gate 
6690Sstevel@tonic-gate /* libscf.c - used by restarter.c/method.c/expand.c */
6700Sstevel@tonic-gate char *libscf_get_method(scf_handle_t *, int, restarter_inst_t *,
6710Sstevel@tonic-gate     scf_snapshot_t *, method_restart_t *, uint_t *, uint8_t *, uint64_t *,
6720Sstevel@tonic-gate     uint8_t *);
6730Sstevel@tonic-gate void libscf_populate_graph(scf_handle_t *h);
6740Sstevel@tonic-gate int update_fault_count(restarter_inst_t *, int);
6750Sstevel@tonic-gate int libscf_unset_action(scf_handle_t *, scf_propertygroup_t *, admin_action_t,
6760Sstevel@tonic-gate     int64_t);
6770Sstevel@tonic-gate int libscf_get_startd_properties(scf_instance_t *, scf_snapshot_t *, uint_t *,
6780Sstevel@tonic-gate     char **);
6790Sstevel@tonic-gate int libscf_get_template_values(scf_instance_t *, scf_snapshot_t *, char **,
6800Sstevel@tonic-gate     char **);
6810Sstevel@tonic-gate 
6820Sstevel@tonic-gate int libscf_read_method_ids(scf_handle_t *, scf_instance_t *, const char *,
6830Sstevel@tonic-gate     ctid_t *, ctid_t *, pid_t *);
6840Sstevel@tonic-gate int libscf_write_start_pid(scf_instance_t *, pid_t);
6850Sstevel@tonic-gate int libscf_write_method_status(scf_instance_t *, const char *, int);
6860Sstevel@tonic-gate int libscf_note_method_log(scf_instance_t *, const char *, const char *);
6870Sstevel@tonic-gate 
6880Sstevel@tonic-gate scf_handle_t *libscf_handle_create_bound(scf_version_t);
6890Sstevel@tonic-gate void libscf_handle_rebind(scf_handle_t *);
6900Sstevel@tonic-gate scf_handle_t *libscf_handle_create_bound_loop(void);
6910Sstevel@tonic-gate 
6920Sstevel@tonic-gate scf_snapshot_t *libscf_get_running_snapshot(scf_instance_t *);
6930Sstevel@tonic-gate int libscf_snapshots_poststart(scf_handle_t *, const char *, boolean_t);
6940Sstevel@tonic-gate int libscf_snapshots_refresh(scf_instance_t *, const char *);
6950Sstevel@tonic-gate 
6960Sstevel@tonic-gate int instance_is_transient_style(restarter_inst_t *);
6970Sstevel@tonic-gate int instance_is_wait_style(restarter_inst_t *);
6980Sstevel@tonic-gate 
6990Sstevel@tonic-gate int libscf_create_self(scf_handle_t *);
7000Sstevel@tonic-gate 
7010Sstevel@tonic-gate void libscf_reget_instance(restarter_inst_t *);
7020Sstevel@tonic-gate 
7030Sstevel@tonic-gate /* log.c */
7040Sstevel@tonic-gate void log_init();
7050Sstevel@tonic-gate void log_error(int, const char *, ...);
7060Sstevel@tonic-gate void log_framework(int, const char *, ...);
7075680Srm88369 void log_framework2(int, int, const char *, ...);
7080Sstevel@tonic-gate void log_console(int, const char *, ...);
7090Sstevel@tonic-gate void log_preexec(void);
7100Sstevel@tonic-gate void setlog(const char *);
7110Sstevel@tonic-gate void log_transition(const restarter_inst_t *, start_outcome_t);
7120Sstevel@tonic-gate void log_instance(const restarter_inst_t *, boolean_t, const char *, ...);
7130Sstevel@tonic-gate void log_instance_fmri(const char *, const char *, boolean_t,
7140Sstevel@tonic-gate     const char *, ...);
7150Sstevel@tonic-gate 
7160Sstevel@tonic-gate /* method.c */
7170Sstevel@tonic-gate void *method_thread(void *);
7180Sstevel@tonic-gate void method_remove_contract(restarter_inst_t *, boolean_t, boolean_t);
7190Sstevel@tonic-gate 
7200Sstevel@tonic-gate /* misc.c */
7210Sstevel@tonic-gate void startd_close(int);
7220Sstevel@tonic-gate void startd_fclose(FILE *);
7230Sstevel@tonic-gate int fmri_canonify(const char *, char **, boolean_t);
7240Sstevel@tonic-gate int fs_is_read_only(char *, ulong_t *);
7250Sstevel@tonic-gate int fs_remount(char *);
7260Sstevel@tonic-gate void xstr_sanitize(char *);
7270Sstevel@tonic-gate 
7280Sstevel@tonic-gate /* restarter.c */
7290Sstevel@tonic-gate void restarter_init(void);
7300Sstevel@tonic-gate void restarter_start(void);
7310Sstevel@tonic-gate int instance_in_transition(restarter_inst_t *);
7320Sstevel@tonic-gate int restarter_instance_update_states(scf_handle_t *, restarter_inst_t *,
7330Sstevel@tonic-gate     restarter_instance_state_t, restarter_instance_state_t, restarter_error_t,
734*12967Sgavin.maltby@oracle.com     restarter_str_t);
7350Sstevel@tonic-gate int stop_instance_fmri(scf_handle_t *, const char *, uint_t);
7360Sstevel@tonic-gate restarter_inst_t *inst_lookup_by_id(int);
7370Sstevel@tonic-gate void restarter_mark_pending_snapshot(const char *, uint_t);
7380Sstevel@tonic-gate void *restarter_post_fsminimal_thread(void *);
7390Sstevel@tonic-gate void timeout_insert(restarter_inst_t *, ctid_t, uint64_t);
7400Sstevel@tonic-gate void timeout_remove(restarter_inst_t *, ctid_t);
7410Sstevel@tonic-gate void timeout_init(void);
7420Sstevel@tonic-gate int is_timeout_ovr(restarter_inst_t *);
7430Sstevel@tonic-gate 
7440Sstevel@tonic-gate /* startd.c */
7450Sstevel@tonic-gate void *safe_realloc(void *, size_t);
7460Sstevel@tonic-gate char *safe_strdup(const char *s);
7470Sstevel@tonic-gate void *startd_alloc_retry(void *(*)(size_t, int), size_t);
7480Sstevel@tonic-gate void startd_free(void *, size_t);
7490Sstevel@tonic-gate uu_list_pool_t *startd_list_pool_create(const char *, size_t, size_t,
7500Sstevel@tonic-gate     uu_compare_fn_t *, uint32_t);
7510Sstevel@tonic-gate uu_list_t *startd_list_create(uu_list_pool_t *, void *, uint32_t);
7520Sstevel@tonic-gate pthread_t startd_thread_create(void *(*)(void *), void *);
7530Sstevel@tonic-gate 
7540Sstevel@tonic-gate /* special.c */
7550Sstevel@tonic-gate void special_null_transition(void);
7560Sstevel@tonic-gate void special_online_hooks_get(const char *, instance_hook_t *,
7570Sstevel@tonic-gate     instance_hook_t *, instance_hook_t *);
7580Sstevel@tonic-gate 
7591958Slianep /* transition.c */
7601958Slianep int gt_transition(scf_handle_t *, graph_vertex_t *, restarter_error_t,
7612339Slianep     restarter_instance_state_t);
7621958Slianep 
7630Sstevel@tonic-gate /* utmpx.c */
7640Sstevel@tonic-gate void utmpx_init(void);
7650Sstevel@tonic-gate void utmpx_clear_old(void);
7660Sstevel@tonic-gate int utmpx_mark_init(pid_t, char *);
7670Sstevel@tonic-gate void utmpx_mark_dead(pid_t, int, boolean_t);
7680Sstevel@tonic-gate char utmpx_get_runlevel(void);
7690Sstevel@tonic-gate void utmpx_set_runlevel(char, char, boolean_t);
7700Sstevel@tonic-gate void utmpx_write_boottime(void);
7710Sstevel@tonic-gate 
7720Sstevel@tonic-gate /* wait.c */
7730Sstevel@tonic-gate void wait_init(void);
7740Sstevel@tonic-gate void wait_prefork(void);
7750Sstevel@tonic-gate void wait_postfork(pid_t);
7760Sstevel@tonic-gate int wait_register(pid_t, const char *, int, int);
7770Sstevel@tonic-gate void *wait_thread(void *);
7787219Srm88369 void wait_ignore_by_fmri(const char *);
7790Sstevel@tonic-gate 
7800Sstevel@tonic-gate /* proc.c */
7810Sstevel@tonic-gate ctid_t proc_get_ctid();
7820Sstevel@tonic-gate 
7837475SPhilippe.Jung@Sun.COM /* deathrow.c */
7847475SPhilippe.Jung@Sun.COM extern void deathrow_init();
7857475SPhilippe.Jung@Sun.COM extern void deathrow_fini();
7867475SPhilippe.Jung@Sun.COM extern boolean_t is_fmri_in_deathrow(const char *);
7877475SPhilippe.Jung@Sun.COM 
7880Sstevel@tonic-gate #ifdef	__cplusplus
7890Sstevel@tonic-gate }
7900Sstevel@tonic-gate #endif
7910Sstevel@tonic-gate 
7920Sstevel@tonic-gate #endif	/* _STARTD_H */
793