xref: /titanic_44/usr/src/cmd/svc/startd/startd.h (revision f6e214c7418f43af38bd8c3a557e3d0a1d311cfa)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
53ad28c1eSrm88369  * Common Development and Distribution License (the "License").
63ad28c1eSrm88369  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
2153f3aea0SRoger A. Faulkner 
227c478bd9Sstevel@tonic-gate /*
23*f6e214c7SGavin Maltby  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_STARTD_H
277c478bd9Sstevel@tonic-gate #define	_STARTD_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/time.h>
307c478bd9Sstevel@tonic-gate #include <librestart.h>
317c478bd9Sstevel@tonic-gate #include <librestart_priv.h>
327c478bd9Sstevel@tonic-gate #include <libscf.h>
337c478bd9Sstevel@tonic-gate #include <libsysevent.h>
347c478bd9Sstevel@tonic-gate #include <libuutil.h>
357c478bd9Sstevel@tonic-gate #include <pthread.h>
3653f3aea0SRoger A. Faulkner #include <synch.h>
377c478bd9Sstevel@tonic-gate #include <stdio.h>
387c478bd9Sstevel@tonic-gate #include <syslog.h>
397c478bd9Sstevel@tonic-gate #include <umem.h>
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
427c478bd9Sstevel@tonic-gate extern "C" {
437c478bd9Sstevel@tonic-gate #endif
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate /*
4653f3aea0SRoger A. Faulkner  * We want MUTEX_HELD, but we also want pthreads.  So we're stuck with this
4753f3aea0SRoger A. Faulkner  * for the native build, at least until the build machines can catch up
4853f3aea0SRoger A. Faulkner  * with the latest version of MUTEX_HELD() in <synch.h>.
497c478bd9Sstevel@tonic-gate  */
5053f3aea0SRoger A. Faulkner #if defined(NATIVE_BUILD)
5153f3aea0SRoger A. Faulkner #undef	MUTEX_HELD
5253f3aea0SRoger A. Faulkner #define	MUTEX_HELD(m)		_mutex_held((mutex_t *)(m))
5353f3aea0SRoger A. Faulkner #endif
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate #ifndef NDEBUG
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate #define	MUTEX_LOCK(mp)	{						\
587c478bd9Sstevel@tonic-gate 	int err;							\
597c478bd9Sstevel@tonic-gate 	if ((err = pthread_mutex_lock((mp))) != 0) {			\
607c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,					\
617c478bd9Sstevel@tonic-gate 		    "pthread_mutex_lock() failed on %s:%d: %s\n",	\
627c478bd9Sstevel@tonic-gate 		    __FILE__, __LINE__, strerror(err));			\
637c478bd9Sstevel@tonic-gate 		abort();						\
647c478bd9Sstevel@tonic-gate 	}								\
657c478bd9Sstevel@tonic-gate }
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate #define	MUTEX_UNLOCK(mp)	{					\
687c478bd9Sstevel@tonic-gate 	int err;							\
697c478bd9Sstevel@tonic-gate 	if ((err = pthread_mutex_unlock((mp))) != 0) {			\
707c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,					\
717c478bd9Sstevel@tonic-gate 		    "pthread_mutex_unlock() failed on %s:%d: %s\n",	\
727c478bd9Sstevel@tonic-gate 		    __FILE__, __LINE__, strerror(err));			\
737c478bd9Sstevel@tonic-gate 		abort();						\
747c478bd9Sstevel@tonic-gate 	}								\
757c478bd9Sstevel@tonic-gate }
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate #else
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate #define	MUTEX_LOCK(mp)		(void) pthread_mutex_lock((mp))
807c478bd9Sstevel@tonic-gate #define	MUTEX_UNLOCK(mp)	(void) pthread_mutex_unlock((mp))
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate #endif
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate #ifndef NDEBUG
857c478bd9Sstevel@tonic-gate #define	bad_error(func, err)	{					\
867c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, "%s:%d: %s() failed with unexpected "	\
877c478bd9Sstevel@tonic-gate 	    "error %d.  Aborting.\n", __FILE__, __LINE__, (func), (err)); \
887c478bd9Sstevel@tonic-gate 	abort();							\
897c478bd9Sstevel@tonic-gate }
907c478bd9Sstevel@tonic-gate #else
917c478bd9Sstevel@tonic-gate #define	bad_error(func, err)	abort()
927c478bd9Sstevel@tonic-gate #endif
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate #define	min(a, b)	(((a) < (b)) ? (a) : (b))
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate #define	FAULT_COUNT_INCR	0
987c478bd9Sstevel@tonic-gate #define	FAULT_COUNT_RESET	1
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate #define	FAULT_THRESHOLD		3
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate #define	MAX_CONFIGD_RETRIES	5
1039444c26fSTom Whitten #define	MAX_EMI_RETRIES		5
1047c478bd9Sstevel@tonic-gate #define	MAX_MOUNT_RETRIES	5
1057c478bd9Sstevel@tonic-gate #define	MAX_SULOGIN_RETRIES	5
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate #define	RETURN_SUCCESS		0
1087c478bd9Sstevel@tonic-gate #define	RETURN_RETRY		-1
1097c478bd9Sstevel@tonic-gate #define	RETURN_FATAL		-2
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate #define	LIBSCF_SUCCESS		0
1127c478bd9Sstevel@tonic-gate #define	LIBSCF_PROPERTY_ABSENT	-1
1137c478bd9Sstevel@tonic-gate #define	LIBSCF_PGROUP_ABSENT	-2
1147c478bd9Sstevel@tonic-gate #define	LIBSCF_PROPERTY_ERROR	-3
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate #define	METHOD_START		0
1177c478bd9Sstevel@tonic-gate #define	METHOD_STOP		1
1187c478bd9Sstevel@tonic-gate #define	METHOD_REFRESH		2
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate #define	METHOD_TIMEOUT_INFINITE	0
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate /*
1237c478bd9Sstevel@tonic-gate  * Contract cookies used by startd.
1247c478bd9Sstevel@tonic-gate  */
1257c478bd9Sstevel@tonic-gate #define	CONFIGD_COOKIE		0x10
1267c478bd9Sstevel@tonic-gate #define	SULOGIN_COOKIE		0x11
1277c478bd9Sstevel@tonic-gate #define	METHOD_START_COOKIE	0x20
1287c478bd9Sstevel@tonic-gate #define	METHOD_OTHER_COOKIE	0x21
1297c478bd9Sstevel@tonic-gate #define	MONITOR_COOKIE		0x30
1309444c26fSTom Whitten #define	EMI_COOKIE		0x31
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate #define	ALLOC_RETRY		3
1347c478bd9Sstevel@tonic-gate #define	ALLOC_DELAY		10
1357c478bd9Sstevel@tonic-gate #define	ALLOC_DELAY_MULT	10
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate #define	safe_scf_scope_create(h)	\
1387c478bd9Sstevel@tonic-gate 	libscf_object_create((void *(*)(scf_handle_t *))scf_scope_create, (h))
1397c478bd9Sstevel@tonic-gate #define	safe_scf_service_create(h)	\
1407c478bd9Sstevel@tonic-gate 	libscf_object_create((void *(*)(scf_handle_t *))scf_service_create, (h))
1417c478bd9Sstevel@tonic-gate #define	safe_scf_instance_create(h)	libscf_object_create(	\
1427c478bd9Sstevel@tonic-gate 	(void *(*)(scf_handle_t *))scf_instance_create, (h))
1437c478bd9Sstevel@tonic-gate #define	safe_scf_snapshot_create(h)	libscf_object_create(	\
1447c478bd9Sstevel@tonic-gate 	(void *(*)(scf_handle_t *))scf_snapshot_create, (h))
1457c478bd9Sstevel@tonic-gate #define	safe_scf_snaplevel_create(h)	libscf_object_create(	\
1467c478bd9Sstevel@tonic-gate 	(void *(*)(scf_handle_t *))scf_snaplevel_create, (h))
1477c478bd9Sstevel@tonic-gate #define	safe_scf_pg_create(h)		\
1487c478bd9Sstevel@tonic-gate 	libscf_object_create((void *(*)(scf_handle_t *))scf_pg_create, (h))
1497c478bd9Sstevel@tonic-gate #define	safe_scf_property_create(h)	libscf_object_create(	\
1507c478bd9Sstevel@tonic-gate 	(void *(*)(scf_handle_t *))scf_property_create, (h))
1517c478bd9Sstevel@tonic-gate #define	safe_scf_value_create(h)	\
1527c478bd9Sstevel@tonic-gate 	libscf_object_create((void *(*)(scf_handle_t *))scf_value_create, (h))
1537c478bd9Sstevel@tonic-gate #define	safe_scf_iter_create(h)		\
1547c478bd9Sstevel@tonic-gate 	libscf_object_create((void *(*)(scf_handle_t *))scf_iter_create, (h))
1557c478bd9Sstevel@tonic-gate #define	safe_scf_transaction_create(h)	libscf_object_create(	\
1567c478bd9Sstevel@tonic-gate 	(void *(*)(scf_handle_t *))	scf_transaction_create, (h))
1577c478bd9Sstevel@tonic-gate #define	safe_scf_entry_create(h)	\
1587c478bd9Sstevel@tonic-gate 	libscf_object_create((void *(*)(scf_handle_t *))scf_entry_create, (h))
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate #define	startd_alloc(sz)	\
1617c478bd9Sstevel@tonic-gate 	startd_alloc_retry((void *(*)(size_t, int))umem_alloc, (sz))
1627c478bd9Sstevel@tonic-gate #define	startd_zalloc(sz)	\
1637c478bd9Sstevel@tonic-gate 	startd_alloc_retry((void *(*)(size_t, int))umem_zalloc, (sz))
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate extern pthread_mutexattr_t mutex_attrs;
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate /*
1697c478bd9Sstevel@tonic-gate  * Definitions for administrative actions.
1707c478bd9Sstevel@tonic-gate  *   Note that the ordering in admin_action_t, admin_actions, and admin_events
1717c478bd9Sstevel@tonic-gate  *   must match.  admin_actions and admin_events are defined in startd.c.
1727c478bd9Sstevel@tonic-gate  */
1737c478bd9Sstevel@tonic-gate #define	NACTIONS			6
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate typedef enum {
1767c478bd9Sstevel@tonic-gate 	ADMIN_EVENT_DEGRADED = 0x0,
1777c478bd9Sstevel@tonic-gate 	ADMIN_EVENT_MAINT_OFF,
1787c478bd9Sstevel@tonic-gate 	ADMIN_EVENT_MAINT_ON,
1797c478bd9Sstevel@tonic-gate 	ADMIN_EVENT_MAINT_ON_IMMEDIATE,
1807c478bd9Sstevel@tonic-gate 	ADMIN_EVENT_REFRESH,
1817c478bd9Sstevel@tonic-gate 	ADMIN_EVENT_RESTART
1827c478bd9Sstevel@tonic-gate } admin_action_t;
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate extern const char * const admin_actions[NACTIONS];
1857c478bd9Sstevel@tonic-gate extern const int admin_events[NACTIONS];
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate #define	LOG_DATE_SIZE	32	/* Max size of timestamp in log output */
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate extern ssize_t max_scf_name_size;
1907c478bd9Sstevel@tonic-gate extern ssize_t max_scf_value_size;
1917c478bd9Sstevel@tonic-gate extern ssize_t max_scf_fmri_size;
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate extern mode_t fmask;
1947c478bd9Sstevel@tonic-gate extern mode_t dmask;
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate #define	LOG_PREFIX_EARLY	"/etc/svc/volatile/"
1977c478bd9Sstevel@tonic-gate #define	LOG_PREFIX_NORMAL	"/var/svc/log/"
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate #define	LOG_SUFFIX		".log"
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate #define	STARTD_DEFAULT_LOG	"svc.startd.log"
2029444c26fSTom Whitten #define	EMI_LOG ((const char *) "system-early-manifest-import:default.log")
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate extern const char *log_directory;	/* Current log directory path */
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate #define	FS_TIMEZONE_DIR		"/usr/share/lib/zoneinfo"
2077c478bd9Sstevel@tonic-gate #define	FS_LOCALE_DIR		"/usr/lib/locale"
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate /*
2107c478bd9Sstevel@tonic-gate  * Simple dictionary representation.
2117c478bd9Sstevel@tonic-gate  */
2127c478bd9Sstevel@tonic-gate typedef struct dictionary {
2137c478bd9Sstevel@tonic-gate 	uu_list_t		*dict_list;
2147c478bd9Sstevel@tonic-gate 	int			dict_new_id;
2157c478bd9Sstevel@tonic-gate 	pthread_mutex_t		dict_lock;
2167c478bd9Sstevel@tonic-gate } dictionary_t;
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate typedef struct dict_entry {
2197c478bd9Sstevel@tonic-gate 	int			de_id;
2207c478bd9Sstevel@tonic-gate 	const char		*de_name;
2217c478bd9Sstevel@tonic-gate 	uu_list_node_t		de_link;
2227c478bd9Sstevel@tonic-gate } dict_entry_t;
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate extern dictionary_t *dictionary;
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate typedef struct timeout_queue {
2277c478bd9Sstevel@tonic-gate 	uu_list_t		*tq_list;
2287c478bd9Sstevel@tonic-gate 	pthread_mutex_t		tq_lock;
2297c478bd9Sstevel@tonic-gate } timeout_queue_t;
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate typedef struct timeout_entry {
2327c478bd9Sstevel@tonic-gate 	hrtime_t		te_timeout;	/* timeout expiration time */
2337c478bd9Sstevel@tonic-gate 	ctid_t			te_ctid;
2347c478bd9Sstevel@tonic-gate 	char			*te_fmri;
2357c478bd9Sstevel@tonic-gate 	char			*te_logstem;
2367c478bd9Sstevel@tonic-gate 	volatile int		te_fired;
2377c478bd9Sstevel@tonic-gate 	uu_list_node_t		te_link;
2387c478bd9Sstevel@tonic-gate } timeout_entry_t;
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate extern timeout_queue_t *timeouts;
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate /*
2437c478bd9Sstevel@tonic-gate  * State definitions.
2447c478bd9Sstevel@tonic-gate  */
2457c478bd9Sstevel@tonic-gate typedef enum {
2467c478bd9Sstevel@tonic-gate 	STATE_NONE = 0x0,
2477c478bd9Sstevel@tonic-gate 	STATE_UNINIT,
2487c478bd9Sstevel@tonic-gate 	STATE_MAINT,
2497c478bd9Sstevel@tonic-gate 	STATE_OFFLINE,
2507c478bd9Sstevel@tonic-gate 	STATE_DISABLED,
2517c478bd9Sstevel@tonic-gate 	STATE_ONLINE,
2527c478bd9Sstevel@tonic-gate 	STATE_DEGRADED
2537c478bd9Sstevel@tonic-gate } instance_state_t;
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate #define	STATE_MAX	(STATE_DEGRADED + 1)
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate extern const char * const instance_state_str[STATE_MAX];
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate typedef enum {
2607c478bd9Sstevel@tonic-gate 	GVT_UNSUPPORTED = -1,
2617c478bd9Sstevel@tonic-gate 	GVT_UNKNOWN = 0,
2627c478bd9Sstevel@tonic-gate 	GVT_SVC,		/* service */
2637c478bd9Sstevel@tonic-gate 	GVT_INST,		/* instance */
2647c478bd9Sstevel@tonic-gate 	GVT_FILE,		/* file: */
2657c478bd9Sstevel@tonic-gate 	GVT_GROUP		/* dependency group */
2667c478bd9Sstevel@tonic-gate } gv_type_t;
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate typedef enum {
2697c478bd9Sstevel@tonic-gate 	DEPGRP_UNSUPPORTED = -1,
2707c478bd9Sstevel@tonic-gate 	DEPGRP_REQUIRE_ANY = 1,
2717c478bd9Sstevel@tonic-gate 	DEPGRP_REQUIRE_ALL,
2727c478bd9Sstevel@tonic-gate 	DEPGRP_EXCLUDE_ALL,
2737c478bd9Sstevel@tonic-gate 	DEPGRP_OPTIONAL_ALL
2747c478bd9Sstevel@tonic-gate } depgroup_type_t;
2757c478bd9Sstevel@tonic-gate 
2767c478bd9Sstevel@tonic-gate typedef enum {
2777c478bd9Sstevel@tonic-gate 	METHOD_RESTART_UNKNOWN = -1,
2787c478bd9Sstevel@tonic-gate 	METHOD_RESTART_ALL = 0,
2797c478bd9Sstevel@tonic-gate 	METHOD_RESTART_EXTERNAL_FAULT,
2807c478bd9Sstevel@tonic-gate 	METHOD_RESTART_ANY_FAULT,
2817c478bd9Sstevel@tonic-gate 	METHOD_RESTART_OTHER
2827c478bd9Sstevel@tonic-gate } method_restart_t;
2837c478bd9Sstevel@tonic-gate 
284cd3bce3eSlianep typedef enum {
285cd3bce3eSlianep 	PROPAGATE_START,
286cd3bce3eSlianep 	PROPAGATE_STOP,
287cd3bce3eSlianep 	PROPAGATE_SAT
288cd3bce3eSlianep } propagate_event_t;
289cd3bce3eSlianep 
2907c478bd9Sstevel@tonic-gate /*
2917c478bd9Sstevel@tonic-gate  * Graph representation.
2927c478bd9Sstevel@tonic-gate  */
2937c478bd9Sstevel@tonic-gate #define	GV_CONFIGURED	0x01	/* Service exists in repository, ready */
2947c478bd9Sstevel@tonic-gate #define	GV_ENABLED	0x02	/* Service should be online */
2957c478bd9Sstevel@tonic-gate #define	GV_ENBLD_NOOVR	0x04	/* GV_ENABLED, ignoring override */
2967c478bd9Sstevel@tonic-gate #define	GV_INSUBGRAPH	0x08	/* Current milestone depends on service */
29770cbfe41SPhilippe Jung #define	GV_DEATHROW	0x10	/* Service is on deathrow */
298aca380d7SRenaud Manus #define	GV_TOOFFLINE	0x20	/* Services in subtree to offline */
299aca380d7SRenaud Manus #define	GV_TODISABLE	0x40	/* Services in subtree to disable */
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate /* ID must come first to support search */
3027c478bd9Sstevel@tonic-gate typedef struct graph_vertex {
3037c478bd9Sstevel@tonic-gate 	int				gv_id;
3047c478bd9Sstevel@tonic-gate 	char				*gv_name;
3057c478bd9Sstevel@tonic-gate 	uu_list_node_t			gv_link;
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 	uint_t				gv_flags;
3087c478bd9Sstevel@tonic-gate 	restarter_instance_state_t	gv_state;
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate 	gv_type_t			gv_type;
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 	depgroup_type_t			gv_depgroup;
3137c478bd9Sstevel@tonic-gate 	restarter_error_t		gv_restart;
3147c478bd9Sstevel@tonic-gate 
3157c478bd9Sstevel@tonic-gate 	void				(*gv_start_f)(struct graph_vertex *);
3167c478bd9Sstevel@tonic-gate 	void				(*gv_post_online_f)(void);
3177c478bd9Sstevel@tonic-gate 	void				(*gv_post_disable_f)(void);
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate 	int				gv_restarter_id;
3207c478bd9Sstevel@tonic-gate 	evchan_t			*gv_restarter_channel;
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate 	int				gv_delegate_initialized;
3237c478bd9Sstevel@tonic-gate 	evchan_t			*gv_delegate_channel;
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate 	uu_list_t			*gv_dependencies;
3267c478bd9Sstevel@tonic-gate 	uu_list_t			*gv_dependents;
3273ad28c1eSrm88369 
3283ad28c1eSrm88369 	/*
3293ad28c1eSrm88369 	 * gv_refs represents the number of references besides dependencies.
3303ad28c1eSrm88369 	 * The vertex cannot be removed when gv_refs > 0.
3313ad28c1eSrm88369 	 *
3323ad28c1eSrm88369 	 * Currently, only relevant for GVT_SVC and GVT_INST type vertices.
3333ad28c1eSrm88369 	 */
3343ad28c1eSrm88369 	int 				gv_refs;
335*f6e214c7SGavin Maltby 
336*f6e214c7SGavin Maltby 	int32_t				gv_stn_tset;
337*f6e214c7SGavin Maltby 	int32_t				gv_reason;
3387c478bd9Sstevel@tonic-gate } graph_vertex_t;
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate typedef struct graph_edge {
3417c478bd9Sstevel@tonic-gate 	graph_vertex_t	*ge_vertex;
3427c478bd9Sstevel@tonic-gate 	uu_list_node_t	ge_link;
3437c478bd9Sstevel@tonic-gate 	graph_vertex_t	*ge_parent;
3447c478bd9Sstevel@tonic-gate } graph_edge_t;
3457c478bd9Sstevel@tonic-gate 
346*f6e214c7SGavin Maltby int libscf_get_info_events_all(scf_propertygroup_t *);
347*f6e214c7SGavin Maltby int32_t libscf_get_stn_tset(scf_instance_t *);
348*f6e214c7SGavin Maltby 
3497c478bd9Sstevel@tonic-gate /*
35099b44c3bSlianep  * Restarter transition outcomes
3517c478bd9Sstevel@tonic-gate  */
3527c478bd9Sstevel@tonic-gate typedef enum {
35399b44c3bSlianep 	MAINT_REQUESTED,
3547c478bd9Sstevel@tonic-gate 	START_REQUESTED,
3557c478bd9Sstevel@tonic-gate 	START_FAILED_REPEATEDLY,
3567c478bd9Sstevel@tonic-gate 	START_FAILED_CONFIGURATION,
3577c478bd9Sstevel@tonic-gate 	START_FAILED_FATAL,
3587c478bd9Sstevel@tonic-gate 	START_FAILED_TIMEOUT_FATAL,
3597c478bd9Sstevel@tonic-gate 	START_FAILED_OTHER
3607c478bd9Sstevel@tonic-gate } start_outcome_t;
3617c478bd9Sstevel@tonic-gate 
3627c478bd9Sstevel@tonic-gate typedef void (*instance_hook_t)(void);
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate typedef struct service_hook_assn {
3657c478bd9Sstevel@tonic-gate 	char	*sh_fmri;
3667c478bd9Sstevel@tonic-gate 	instance_hook_t	sh_pre_online_hook;
3677c478bd9Sstevel@tonic-gate 	instance_hook_t	sh_post_online_hook;
3687c478bd9Sstevel@tonic-gate 	instance_hook_t	sh_post_offline_hook;
3697c478bd9Sstevel@tonic-gate } service_hook_assn_t;
3707c478bd9Sstevel@tonic-gate 
3717c478bd9Sstevel@tonic-gate /*
3727c478bd9Sstevel@tonic-gate  * Restarter instance stop reasons.
3737c478bd9Sstevel@tonic-gate  */
3747c478bd9Sstevel@tonic-gate typedef enum {
3757c478bd9Sstevel@tonic-gate 	RSTOP_EXIT = 0x0,	/* exited or empty */
3767c478bd9Sstevel@tonic-gate 	RSTOP_CORE,		/* core dumped */
3777c478bd9Sstevel@tonic-gate 	RSTOP_SIGNAL,		/* external fatal signal received */
3787c478bd9Sstevel@tonic-gate 	RSTOP_HWERR,		/* uncorrectable hardware error */
3797c478bd9Sstevel@tonic-gate 	RSTOP_DEPENDENCY,	/* dependency activity caused stop */
3807c478bd9Sstevel@tonic-gate 	RSTOP_DISABLE,		/* disabled */
3817c478bd9Sstevel@tonic-gate 	RSTOP_RESTART		/* restart requested */
3827c478bd9Sstevel@tonic-gate } stop_cause_t;
3837c478bd9Sstevel@tonic-gate 
3847c478bd9Sstevel@tonic-gate /*
3857c478bd9Sstevel@tonic-gate  * Restarter instance maintenance clear reasons.
3867c478bd9Sstevel@tonic-gate  */
3877c478bd9Sstevel@tonic-gate typedef enum {
3887c478bd9Sstevel@tonic-gate 	RUNMAINT_CLEAR = 0x0,
3897c478bd9Sstevel@tonic-gate 	RUNMAINT_DISABLE
3907c478bd9Sstevel@tonic-gate } unmaint_cause_t;
3917c478bd9Sstevel@tonic-gate 
3927c478bd9Sstevel@tonic-gate /*
3937c478bd9Sstevel@tonic-gate  * Restarter instance flags
3947c478bd9Sstevel@tonic-gate  */
3957c478bd9Sstevel@tonic-gate #define	RINST_CONTRACT		0x00000000	/* progeny constitute inst */
3967c478bd9Sstevel@tonic-gate #define	RINST_TRANSIENT		0x10000000	/* inst operates momentarily */
3977c478bd9Sstevel@tonic-gate #define	RINST_WAIT		0x20000000	/* child constitutes inst */
3987c478bd9Sstevel@tonic-gate #define	RINST_STYLE_MASK	0xf0000000
3997c478bd9Sstevel@tonic-gate 
4007c478bd9Sstevel@tonic-gate #define	RINST_RETAKE_RUNNING	0x01000000	/* pending running snapshot */
4017c478bd9Sstevel@tonic-gate #define	RINST_RETAKE_START	0x02000000	/* pending start snapshot */
4027c478bd9Sstevel@tonic-gate 
4037c478bd9Sstevel@tonic-gate #define	RINST_RETAKE_MASK	0x0f000000
4047c478bd9Sstevel@tonic-gate 
40516ba0facSSean Wilcox #define	RINST_START_TIMES	5		/* failures to consider */
40616ba0facSSean Wilcox #define	RINST_FAILURE_RATE_NS	600000000000LL	/* 1 failure/10 minutes */
4077c478bd9Sstevel@tonic-gate 
4087c478bd9Sstevel@tonic-gate /* Number of events in the queue when we start dropping ADMIN events. */
4097c478bd9Sstevel@tonic-gate #define	RINST_QUEUE_THRESHOLD	100
4107c478bd9Sstevel@tonic-gate 
4117c478bd9Sstevel@tonic-gate typedef struct restarter_inst {
4127c478bd9Sstevel@tonic-gate 	int			ri_id;
4137c478bd9Sstevel@tonic-gate 	instance_data_t		ri_i;
4147c478bd9Sstevel@tonic-gate 	char			*ri_common_name; /* template localized name */
4157c478bd9Sstevel@tonic-gate 	char			*ri_C_common_name; /* C locale name */
4167c478bd9Sstevel@tonic-gate 
4177c478bd9Sstevel@tonic-gate 	char			*ri_logstem;	/* logfile name */
4187c478bd9Sstevel@tonic-gate 	char			*ri_utmpx_prefix;
4197c478bd9Sstevel@tonic-gate 	uint_t			ri_flags;
4207c478bd9Sstevel@tonic-gate 	instance_hook_t		ri_pre_online_hook;
4217c478bd9Sstevel@tonic-gate 	instance_hook_t		ri_post_online_hook;
4227c478bd9Sstevel@tonic-gate 	instance_hook_t		ri_post_offline_hook;
4237c478bd9Sstevel@tonic-gate 
4247c478bd9Sstevel@tonic-gate 	hrtime_t		ri_start_time[RINST_START_TIMES];
4257c478bd9Sstevel@tonic-gate 	uint_t			ri_start_index;	/* times started */
4267c478bd9Sstevel@tonic-gate 
4277c478bd9Sstevel@tonic-gate 	uu_list_node_t		ri_link;
4287c478bd9Sstevel@tonic-gate 	pthread_mutex_t		ri_lock;
4297c478bd9Sstevel@tonic-gate 
4307c478bd9Sstevel@tonic-gate 	/*
4317c478bd9Sstevel@tonic-gate 	 * When we start a thread to we execute a method for this instance, we
4327c478bd9Sstevel@tonic-gate 	 * put the thread id in ri_method_thread.  Threads with ids other than
4337c478bd9Sstevel@tonic-gate 	 * this which acquire ri_lock while ri_method_thread is nonzero should
4347c478bd9Sstevel@tonic-gate 	 * wait on ri_method_cv.  ri_method_waiters should be incremented while
4357c478bd9Sstevel@tonic-gate 	 * waiting so the instance won't be deleted.
4367c478bd9Sstevel@tonic-gate 	 */
4377c478bd9Sstevel@tonic-gate 	pthread_t		ri_method_thread;
4387c478bd9Sstevel@tonic-gate 	pthread_cond_t		ri_method_cv;
4397c478bd9Sstevel@tonic-gate 	uint_t			ri_method_waiters;
4407c478bd9Sstevel@tonic-gate 
4417c478bd9Sstevel@tonic-gate 	/*
4427c478bd9Sstevel@tonic-gate 	 * These fields are provided so functions can operate on this structure
4437c478bd9Sstevel@tonic-gate 	 * and the repository without worrying about whether the instance has
4447c478bd9Sstevel@tonic-gate 	 * been deleted from the repository (this is possible because
4457c478bd9Sstevel@tonic-gate 	 * ri_i.i_fmri names the instance this structure represents -- see
4467c478bd9Sstevel@tonic-gate 	 * libscf_reget_inst()).  ri_m_inst is the scf_instance_t for the
4477c478bd9Sstevel@tonic-gate 	 * instance, and ri_mi_deleted is true if the instance has been deleted.
4487c478bd9Sstevel@tonic-gate 	 */
4497c478bd9Sstevel@tonic-gate 	scf_instance_t		*ri_m_inst;
4507c478bd9Sstevel@tonic-gate 	boolean_t		ri_mi_deleted;
4517c478bd9Sstevel@tonic-gate 
4527c478bd9Sstevel@tonic-gate 	/*
4537c478bd9Sstevel@tonic-gate 	 * We maintain a pointer to any pending timeout for this instance
4547c478bd9Sstevel@tonic-gate 	 * for quick reference/deletion.
4557c478bd9Sstevel@tonic-gate 	 */
4567c478bd9Sstevel@tonic-gate 	timeout_entry_t		*ri_timeout;
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate 	/*
4597c478bd9Sstevel@tonic-gate 	 * Instance event queue.  Graph events are queued here as a list
4607c478bd9Sstevel@tonic-gate 	 * of restarter_instance_qentry_t's, and the lock is held separately.
4617c478bd9Sstevel@tonic-gate 	 * If both ri_lock and ri_queue_lock are grabbed, ri_lock must be
4627c478bd9Sstevel@tonic-gate 	 * grabbed first.  ri_queue_lock protects all ri_queue_* structure
4637c478bd9Sstevel@tonic-gate 	 * members.
4647c478bd9Sstevel@tonic-gate 	 */
4657c478bd9Sstevel@tonic-gate 	pthread_mutex_t		ri_queue_lock;
4667c478bd9Sstevel@tonic-gate 	pthread_cond_t		ri_queue_cv;
4677c478bd9Sstevel@tonic-gate 	uu_list_t		*ri_queue;
4687c478bd9Sstevel@tonic-gate 	int			ri_queue_thread;
4697c478bd9Sstevel@tonic-gate 
4707c478bd9Sstevel@tonic-gate } restarter_inst_t;
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate typedef struct restarter_instance_list {
4737c478bd9Sstevel@tonic-gate 	uu_list_t		*ril_instance_list;
4747c478bd9Sstevel@tonic-gate 	pthread_mutex_t		ril_lock;
4757c478bd9Sstevel@tonic-gate } restarter_instance_list_t;
4767c478bd9Sstevel@tonic-gate 
4777c478bd9Sstevel@tonic-gate typedef struct restarter_instance_qentry {
4787c478bd9Sstevel@tonic-gate 	restarter_event_type_t	riq_type;
479*f6e214c7SGavin Maltby 	int32_t			riq_reason;
4807c478bd9Sstevel@tonic-gate 	uu_list_node_t		riq_link;
4817c478bd9Sstevel@tonic-gate } restarter_instance_qentry_t;
4827c478bd9Sstevel@tonic-gate 
4837c478bd9Sstevel@tonic-gate typedef struct fork_info {
4847c478bd9Sstevel@tonic-gate 	int			sf_id;
4857c478bd9Sstevel@tonic-gate 	int			sf_method_type;
4867c478bd9Sstevel@tonic-gate 	restarter_error_t	sf_event_type;
487*f6e214c7SGavin Maltby 	restarter_str_t		sf_reason;
4887c478bd9Sstevel@tonic-gate } fork_info_t;
4897c478bd9Sstevel@tonic-gate 
4907c478bd9Sstevel@tonic-gate typedef struct wait_info {
4917c478bd9Sstevel@tonic-gate 	uu_list_node_t		wi_link;
4927c478bd9Sstevel@tonic-gate 
4937c478bd9Sstevel@tonic-gate 	int			wi_fd;		/* psinfo file descriptor */
4947c478bd9Sstevel@tonic-gate 	id_t			wi_pid;		/* process ID */
4957c478bd9Sstevel@tonic-gate 	const char		*wi_fmri;	/* instance FMRI */
4967c478bd9Sstevel@tonic-gate 	int			wi_parent;	/* startd is parent */
49763c7f71bSrm88369 	int			wi_ignore;	/* ignore events */
4987c478bd9Sstevel@tonic-gate } wait_info_t;
4997c478bd9Sstevel@tonic-gate 
5007c478bd9Sstevel@tonic-gate #define	STARTD_LOG_FILE		0x1
5017c478bd9Sstevel@tonic-gate #define	STARTD_LOG_TERMINAL	0x2
5027c478bd9Sstevel@tonic-gate #define	STARTD_LOG_SYSLOG	0x4
5037c478bd9Sstevel@tonic-gate 
5047c478bd9Sstevel@tonic-gate #define	STARTD_BOOT_QUIET	0x1
5057c478bd9Sstevel@tonic-gate #define	STARTD_BOOT_VERBOSE	0x2
5067c478bd9Sstevel@tonic-gate 
5073efb42ecSrm88369 /*
5083efb42ecSrm88369  * Internal debug flags used to reduce the amount of data sent to the
5093efb42ecSrm88369  * internal debug buffer. They can be turned on & off dynamically using
5103efb42ecSrm88369  * internal_debug_flags variable in mdb. By default, they're off.
5113efb42ecSrm88369  */
5123efb42ecSrm88369 #define	DEBUG_DEPENDENCIES	0x1
5133efb42ecSrm88369 
5147c478bd9Sstevel@tonic-gate typedef struct startd_state {
5157c478bd9Sstevel@tonic-gate 	/* Logging configuration */
5167c478bd9Sstevel@tonic-gate 	char		*st_log_prefix;	/* directory prefix */
5177c478bd9Sstevel@tonic-gate 	char		*st_log_file;	/* startd file in above dir */
5187c478bd9Sstevel@tonic-gate 	uint_t		st_log_flags;	/* message destination */
5197c478bd9Sstevel@tonic-gate 	int		st_log_level_min; /* minimum required to log */
5207c478bd9Sstevel@tonic-gate 	int		st_log_timezone_known; /* timezone is available */
5217c478bd9Sstevel@tonic-gate 	int		st_log_locale_known; /* locale is available */
5227c478bd9Sstevel@tonic-gate 	int		st_log_login_reached; /* login service reached */
5237c478bd9Sstevel@tonic-gate 
5247c478bd9Sstevel@tonic-gate 	/* Boot configuration */
5257c478bd9Sstevel@tonic-gate 	uint_t		st_boot_flags;	/* serial boot, etc. */
5267c478bd9Sstevel@tonic-gate 	uint_t		st_initial;	/* first startd on system */
5277c478bd9Sstevel@tonic-gate 
5287c478bd9Sstevel@tonic-gate 	/* System configuration */
5297c478bd9Sstevel@tonic-gate 	char		*st_subgraph;	/* milestone subgraph request */
5307c478bd9Sstevel@tonic-gate 
5317c478bd9Sstevel@tonic-gate 	uint_t		st_load_complete;  /* graph load completed */
5327c478bd9Sstevel@tonic-gate 	uint_t		st_load_instances; /* restarter instances to load */
5337c478bd9Sstevel@tonic-gate 	pthread_mutex_t	st_load_lock;
5347c478bd9Sstevel@tonic-gate 	pthread_cond_t	st_load_cv;
5357c478bd9Sstevel@tonic-gate 
5367c478bd9Sstevel@tonic-gate 	/* Repository configuration */
5377c478bd9Sstevel@tonic-gate 	pid_t		st_configd_pid;	/* PID of our svc.configd */
5387c478bd9Sstevel@tonic-gate 					/* instance */
5397c478bd9Sstevel@tonic-gate 	int		st_configd_lives; /* configd started */
5407c478bd9Sstevel@tonic-gate 	pthread_mutex_t	st_configd_live_lock;
5417c478bd9Sstevel@tonic-gate 	pthread_cond_t	st_configd_live_cv;
5427c478bd9Sstevel@tonic-gate 
5437c478bd9Sstevel@tonic-gate 	char		*st_door_path;
5447c478bd9Sstevel@tonic-gate 
5457c478bd9Sstevel@tonic-gate 	/* General information */
5467c478bd9Sstevel@tonic-gate 	uint_t		st_flags;
5477c478bd9Sstevel@tonic-gate 	struct timeval	st_start_time;	/* effective system start time */
5487c478bd9Sstevel@tonic-gate 	char		*st_locale;
5497c478bd9Sstevel@tonic-gate } startd_state_t;
5507c478bd9Sstevel@tonic-gate 
5517c478bd9Sstevel@tonic-gate extern startd_state_t *st;
5527c478bd9Sstevel@tonic-gate 
5537c478bd9Sstevel@tonic-gate extern boolean_t booting_to_single_user;
5547c478bd9Sstevel@tonic-gate 
5557c478bd9Sstevel@tonic-gate extern const char *event_names[];
5567c478bd9Sstevel@tonic-gate 
5577c478bd9Sstevel@tonic-gate /*
5587c478bd9Sstevel@tonic-gate  * Structures for contract to instance hash table, implemented in
5597c478bd9Sstevel@tonic-gate  * contract.c and used by restarter.c and method.c
5607c478bd9Sstevel@tonic-gate  */
5617c478bd9Sstevel@tonic-gate typedef struct contract_entry {
5627c478bd9Sstevel@tonic-gate 	ctid_t		ce_ctid;
5637c478bd9Sstevel@tonic-gate 	int		ce_instid;
5647c478bd9Sstevel@tonic-gate 
5657c478bd9Sstevel@tonic-gate 	uu_list_node_t	ce_link;
5667c478bd9Sstevel@tonic-gate } contract_entry_t;
5677c478bd9Sstevel@tonic-gate 
568dfe57350Sjeanm extern volatile uint16_t	storing_contract;
569dfe57350Sjeanm 
5707c478bd9Sstevel@tonic-gate uu_list_pool_t *contract_list_pool;
5717c478bd9Sstevel@tonic-gate 
5727c478bd9Sstevel@tonic-gate /* contract.c */
5737c478bd9Sstevel@tonic-gate ctid_t contract_init(void);
5747c478bd9Sstevel@tonic-gate void contract_abandon(ctid_t);
5757c478bd9Sstevel@tonic-gate int contract_kill(ctid_t, int, const char *);
5767c478bd9Sstevel@tonic-gate int contract_is_empty(ctid_t);
5777c478bd9Sstevel@tonic-gate void contract_hash_init();
5787c478bd9Sstevel@tonic-gate void contract_hash_store(ctid_t, int);
5797c478bd9Sstevel@tonic-gate void contract_hash_remove(ctid_t);
5807c478bd9Sstevel@tonic-gate int lookup_inst_by_contract(ctid_t);
5817c478bd9Sstevel@tonic-gate 
5827c478bd9Sstevel@tonic-gate /* dict.c */
5837c478bd9Sstevel@tonic-gate void dict_init(void);
5847c478bd9Sstevel@tonic-gate int dict_lookup_byname(const char *);
5857c478bd9Sstevel@tonic-gate int dict_insert(const char *);
5867c478bd9Sstevel@tonic-gate 
5877c478bd9Sstevel@tonic-gate /* expand.c */
5887c478bd9Sstevel@tonic-gate int expand_method_tokens(const char *, scf_instance_t *,
5897c478bd9Sstevel@tonic-gate     scf_snapshot_t *, int, char **);
5907c478bd9Sstevel@tonic-gate 
5917c478bd9Sstevel@tonic-gate /* env.c */
5927c478bd9Sstevel@tonic-gate void init_env(void);
5937c478bd9Sstevel@tonic-gate char **set_smf_env(char **, size_t, const char *,
5947c478bd9Sstevel@tonic-gate     const restarter_inst_t *, const char *);
5957c478bd9Sstevel@tonic-gate 
5967c478bd9Sstevel@tonic-gate /* file.c */
5977c478bd9Sstevel@tonic-gate int file_ready(graph_vertex_t *);
5987c478bd9Sstevel@tonic-gate 
5997c478bd9Sstevel@tonic-gate /* fork.c */
6007c478bd9Sstevel@tonic-gate int fork_mount(char *, char *);
6017c478bd9Sstevel@tonic-gate void fork_sulogin(boolean_t, const char *, ...);
6027c478bd9Sstevel@tonic-gate void fork_rc_script(char, const char *, boolean_t);
6037c478bd9Sstevel@tonic-gate 
6047c478bd9Sstevel@tonic-gate void *fork_configd_thread(void *);
6057c478bd9Sstevel@tonic-gate 
6067c478bd9Sstevel@tonic-gate pid_t startd_fork1(int *);
6074d53c7adSDan Price void fork_with_timeout(const char *, uint_t, uint_t);
6089444c26fSTom Whitten void fork_emi();
6097c478bd9Sstevel@tonic-gate 
6107c478bd9Sstevel@tonic-gate /* graph.c */
6117c478bd9Sstevel@tonic-gate void graph_init(void);
6127c478bd9Sstevel@tonic-gate void *single_user_thread(void *);
6137c478bd9Sstevel@tonic-gate void *graph_thread(void *);
6147c478bd9Sstevel@tonic-gate void *graph_event_thread(void *);
6157c478bd9Sstevel@tonic-gate void *repository_event_thread(void *);
6167c478bd9Sstevel@tonic-gate int dgraph_add_instance(const char *, scf_instance_t *, boolean_t);
6177c478bd9Sstevel@tonic-gate void graph_engine_start(void);
61899b44c3bSlianep void graph_enable_by_vertex(graph_vertex_t *, int, int);
61999b44c3bSlianep int refresh_vertex(graph_vertex_t *, scf_instance_t *);
62099b44c3bSlianep void vertex_send_event(graph_vertex_t *, restarter_event_type_t);
62199b44c3bSlianep void graph_start_if_satisfied(graph_vertex_t *);
62256e23938Sbustos int vertex_subgraph_dependencies_shutdown(scf_handle_t *, graph_vertex_t *,
62356e23938Sbustos     restarter_instance_state_t);
62499b44c3bSlianep void graph_transition_sulogin(restarter_instance_state_t,
62599b44c3bSlianep     restarter_instance_state_t);
626cd3bce3eSlianep void graph_transition_propagate(graph_vertex_t *, propagate_event_t,
62799b44c3bSlianep     restarter_error_t);
628aca380d7SRenaud Manus void graph_offline_subtree_leaves(graph_vertex_t *, void *);
629845e9415SRenaud Manus void offline_vertex(graph_vertex_t *);
6307c478bd9Sstevel@tonic-gate 
6317c478bd9Sstevel@tonic-gate /* libscf.c - common */
6327c478bd9Sstevel@tonic-gate char *inst_fmri_to_svc_fmri(const char *);
6337c478bd9Sstevel@tonic-gate void *libscf_object_create(void *(*)(scf_handle_t *), scf_handle_t *);
6347c478bd9Sstevel@tonic-gate int libscf_instance_get_fmri(scf_instance_t *, char **);
6357c478bd9Sstevel@tonic-gate int libscf_fmri_get_instance(scf_handle_t *, const char *, scf_instance_t **);
6367c478bd9Sstevel@tonic-gate int libscf_lookup_instance(const char *, scf_instance_t *);
6377c478bd9Sstevel@tonic-gate int libscf_set_reconfig(int);
6387c478bd9Sstevel@tonic-gate scf_snapshot_t *libscf_get_or_make_running_snapshot(scf_instance_t *,
6397c478bd9Sstevel@tonic-gate     const char *, boolean_t);
6407c478bd9Sstevel@tonic-gate int libscf_inst_set_count_prop(scf_instance_t *, const char *,
6417c478bd9Sstevel@tonic-gate     const char *pgtype, uint32_t, const char *, uint64_t);
6427c478bd9Sstevel@tonic-gate 
6437c478bd9Sstevel@tonic-gate /* libscf.c - used by graph.c */
64470cbfe41SPhilippe Jung int libscf_get_deathrow(scf_handle_t *, scf_instance_t *, int *);
6457c478bd9Sstevel@tonic-gate int libscf_get_basic_instance_data(scf_handle_t *, scf_instance_t *,
6467c478bd9Sstevel@tonic-gate     const char *, int *, int *, char **);
6477c478bd9Sstevel@tonic-gate int libscf_inst_get_or_add_pg(scf_instance_t *, const char *, const char *,
6487c478bd9Sstevel@tonic-gate     uint32_t, scf_propertygroup_t *);
6497c478bd9Sstevel@tonic-gate int libscf_read_states(const scf_propertygroup_t *,
6507c478bd9Sstevel@tonic-gate     restarter_instance_state_t *, restarter_instance_state_t *);
6517c478bd9Sstevel@tonic-gate int depgroup_empty(scf_handle_t *, scf_propertygroup_t *);
6527c478bd9Sstevel@tonic-gate gv_type_t depgroup_read_scheme(scf_handle_t *, scf_propertygroup_t *);
6537c478bd9Sstevel@tonic-gate depgroup_type_t depgroup_read_grouping(scf_handle_t *, scf_propertygroup_t *);
6547c478bd9Sstevel@tonic-gate restarter_error_t depgroup_read_restart(scf_handle_t *, scf_propertygroup_t *);
6557c478bd9Sstevel@tonic-gate int libscf_set_enable_ovr(scf_instance_t *, int);
65670cbfe41SPhilippe Jung int libscf_set_deathrow(scf_instance_t *, int);
6577c478bd9Sstevel@tonic-gate int libscf_delete_enable_ovr(scf_instance_t *);
6587c478bd9Sstevel@tonic-gate int libscf_get_milestone(scf_instance_t *, scf_property_t *, scf_value_t *,
6597c478bd9Sstevel@tonic-gate     char *, size_t);
6607c478bd9Sstevel@tonic-gate int libscf_extract_runlevel(scf_property_t *, char *);
6617c478bd9Sstevel@tonic-gate int libscf_clear_runlevel(scf_propertygroup_t *, const char *milestone);
6627c478bd9Sstevel@tonic-gate 
6637c478bd9Sstevel@tonic-gate typedef int (*callback_t)(void *, void *);
6647c478bd9Sstevel@tonic-gate 
6657c478bd9Sstevel@tonic-gate int walk_dependency_pgs(scf_instance_t *, callback_t, void *);
6667c478bd9Sstevel@tonic-gate int walk_property_astrings(scf_property_t *, callback_t, void *);
66716ba0facSSean Wilcox void libscf_reset_start_times(restarter_inst_t *, int);
6687c478bd9Sstevel@tonic-gate 
6697c478bd9Sstevel@tonic-gate /* libscf.c - used by restarter.c/method.c/expand.c */
6707c478bd9Sstevel@tonic-gate char *libscf_get_method(scf_handle_t *, int, restarter_inst_t *,
6717c478bd9Sstevel@tonic-gate     scf_snapshot_t *, method_restart_t *, uint_t *, uint8_t *, uint64_t *,
6727c478bd9Sstevel@tonic-gate     uint8_t *);
6737c478bd9Sstevel@tonic-gate void libscf_populate_graph(scf_handle_t *h);
6747c478bd9Sstevel@tonic-gate int update_fault_count(restarter_inst_t *, int);
6757c478bd9Sstevel@tonic-gate int libscf_unset_action(scf_handle_t *, scf_propertygroup_t *, admin_action_t,
6767c478bd9Sstevel@tonic-gate     int64_t);
6777c478bd9Sstevel@tonic-gate int libscf_get_startd_properties(scf_instance_t *, scf_snapshot_t *, uint_t *,
6787c478bd9Sstevel@tonic-gate     char **);
6797c478bd9Sstevel@tonic-gate int libscf_get_template_values(scf_instance_t *, scf_snapshot_t *, char **,
6807c478bd9Sstevel@tonic-gate     char **);
6817c478bd9Sstevel@tonic-gate 
6827c478bd9Sstevel@tonic-gate int libscf_read_method_ids(scf_handle_t *, scf_instance_t *, const char *,
6837c478bd9Sstevel@tonic-gate     ctid_t *, ctid_t *, pid_t *);
6847c478bd9Sstevel@tonic-gate int libscf_write_start_pid(scf_instance_t *, pid_t);
6857c478bd9Sstevel@tonic-gate int libscf_write_method_status(scf_instance_t *, const char *, int);
6867c478bd9Sstevel@tonic-gate int libscf_note_method_log(scf_instance_t *, const char *, const char *);
6877c478bd9Sstevel@tonic-gate 
6887c478bd9Sstevel@tonic-gate scf_handle_t *libscf_handle_create_bound(scf_version_t);
6897c478bd9Sstevel@tonic-gate void libscf_handle_rebind(scf_handle_t *);
6907c478bd9Sstevel@tonic-gate scf_handle_t *libscf_handle_create_bound_loop(void);
6917c478bd9Sstevel@tonic-gate 
6927c478bd9Sstevel@tonic-gate scf_snapshot_t *libscf_get_running_snapshot(scf_instance_t *);
6937c478bd9Sstevel@tonic-gate int libscf_snapshots_poststart(scf_handle_t *, const char *, boolean_t);
6947c478bd9Sstevel@tonic-gate int libscf_snapshots_refresh(scf_instance_t *, const char *);
6957c478bd9Sstevel@tonic-gate 
6967c478bd9Sstevel@tonic-gate int instance_is_transient_style(restarter_inst_t *);
6977c478bd9Sstevel@tonic-gate int instance_is_wait_style(restarter_inst_t *);
6987c478bd9Sstevel@tonic-gate 
6997c478bd9Sstevel@tonic-gate int libscf_create_self(scf_handle_t *);
7007c478bd9Sstevel@tonic-gate 
7017c478bd9Sstevel@tonic-gate void libscf_reget_instance(restarter_inst_t *);
7027c478bd9Sstevel@tonic-gate 
7037c478bd9Sstevel@tonic-gate /* log.c */
7047c478bd9Sstevel@tonic-gate void log_init();
7057c478bd9Sstevel@tonic-gate void log_error(int, const char *, ...);
7067c478bd9Sstevel@tonic-gate void log_framework(int, const char *, ...);
7073efb42ecSrm88369 void log_framework2(int, int, const char *, ...);
7087c478bd9Sstevel@tonic-gate void log_console(int, const char *, ...);
7097c478bd9Sstevel@tonic-gate void log_preexec(void);
7107c478bd9Sstevel@tonic-gate void setlog(const char *);
7117c478bd9Sstevel@tonic-gate void log_transition(const restarter_inst_t *, start_outcome_t);
7127c478bd9Sstevel@tonic-gate void log_instance(const restarter_inst_t *, boolean_t, const char *, ...);
7137c478bd9Sstevel@tonic-gate void log_instance_fmri(const char *, const char *, boolean_t,
7147c478bd9Sstevel@tonic-gate     const char *, ...);
7157c478bd9Sstevel@tonic-gate 
7167c478bd9Sstevel@tonic-gate /* method.c */
7177c478bd9Sstevel@tonic-gate void *method_thread(void *);
7187c478bd9Sstevel@tonic-gate void method_remove_contract(restarter_inst_t *, boolean_t, boolean_t);
7197c478bd9Sstevel@tonic-gate 
7207c478bd9Sstevel@tonic-gate /* misc.c */
7217c478bd9Sstevel@tonic-gate void startd_close(int);
7227c478bd9Sstevel@tonic-gate void startd_fclose(FILE *);
7237c478bd9Sstevel@tonic-gate int fmri_canonify(const char *, char **, boolean_t);
7247c478bd9Sstevel@tonic-gate int fs_is_read_only(char *, ulong_t *);
7257c478bd9Sstevel@tonic-gate int fs_remount(char *);
7267c478bd9Sstevel@tonic-gate void xstr_sanitize(char *);
7277c478bd9Sstevel@tonic-gate 
7287c478bd9Sstevel@tonic-gate /* restarter.c */
7297c478bd9Sstevel@tonic-gate void restarter_init(void);
7307c478bd9Sstevel@tonic-gate void restarter_start(void);
7317c478bd9Sstevel@tonic-gate int instance_in_transition(restarter_inst_t *);
7327c478bd9Sstevel@tonic-gate int restarter_instance_update_states(scf_handle_t *, restarter_inst_t *,
7337c478bd9Sstevel@tonic-gate     restarter_instance_state_t, restarter_instance_state_t, restarter_error_t,
734*f6e214c7SGavin Maltby     restarter_str_t);
7357c478bd9Sstevel@tonic-gate int stop_instance_fmri(scf_handle_t *, const char *, uint_t);
7367c478bd9Sstevel@tonic-gate restarter_inst_t *inst_lookup_by_id(int);
7377c478bd9Sstevel@tonic-gate void restarter_mark_pending_snapshot(const char *, uint_t);
7387c478bd9Sstevel@tonic-gate void *restarter_post_fsminimal_thread(void *);
7397c478bd9Sstevel@tonic-gate void timeout_insert(restarter_inst_t *, ctid_t, uint64_t);
7407c478bd9Sstevel@tonic-gate void timeout_remove(restarter_inst_t *, ctid_t);
7417c478bd9Sstevel@tonic-gate void timeout_init(void);
7427c478bd9Sstevel@tonic-gate int is_timeout_ovr(restarter_inst_t *);
7437c478bd9Sstevel@tonic-gate 
7447c478bd9Sstevel@tonic-gate /* startd.c */
7457c478bd9Sstevel@tonic-gate void *safe_realloc(void *, size_t);
7467c478bd9Sstevel@tonic-gate char *safe_strdup(const char *s);
7477c478bd9Sstevel@tonic-gate void *startd_alloc_retry(void *(*)(size_t, int), size_t);
7487c478bd9Sstevel@tonic-gate void startd_free(void *, size_t);
7497c478bd9Sstevel@tonic-gate uu_list_pool_t *startd_list_pool_create(const char *, size_t, size_t,
7507c478bd9Sstevel@tonic-gate     uu_compare_fn_t *, uint32_t);
7517c478bd9Sstevel@tonic-gate uu_list_t *startd_list_create(uu_list_pool_t *, void *, uint32_t);
7527c478bd9Sstevel@tonic-gate pthread_t startd_thread_create(void *(*)(void *), void *);
7537c478bd9Sstevel@tonic-gate 
7547c478bd9Sstevel@tonic-gate /* special.c */
7557c478bd9Sstevel@tonic-gate void special_null_transition(void);
7567c478bd9Sstevel@tonic-gate void special_online_hooks_get(const char *, instance_hook_t *,
7577c478bd9Sstevel@tonic-gate     instance_hook_t *, instance_hook_t *);
7587c478bd9Sstevel@tonic-gate 
75999b44c3bSlianep /* transition.c */
76099b44c3bSlianep int gt_transition(scf_handle_t *, graph_vertex_t *, restarter_error_t,
761cd3bce3eSlianep     restarter_instance_state_t);
76299b44c3bSlianep 
7637c478bd9Sstevel@tonic-gate /* utmpx.c */
7647c478bd9Sstevel@tonic-gate void utmpx_init(void);
7657c478bd9Sstevel@tonic-gate void utmpx_clear_old(void);
7667c478bd9Sstevel@tonic-gate int utmpx_mark_init(pid_t, char *);
7677c478bd9Sstevel@tonic-gate void utmpx_mark_dead(pid_t, int, boolean_t);
7687c478bd9Sstevel@tonic-gate char utmpx_get_runlevel(void);
7697c478bd9Sstevel@tonic-gate void utmpx_set_runlevel(char, char, boolean_t);
7707c478bd9Sstevel@tonic-gate void utmpx_write_boottime(void);
7717c478bd9Sstevel@tonic-gate 
7727c478bd9Sstevel@tonic-gate /* wait.c */
7737c478bd9Sstevel@tonic-gate void wait_init(void);
7747c478bd9Sstevel@tonic-gate void wait_prefork(void);
7757c478bd9Sstevel@tonic-gate void wait_postfork(pid_t);
7767c478bd9Sstevel@tonic-gate int wait_register(pid_t, const char *, int, int);
7777c478bd9Sstevel@tonic-gate void *wait_thread(void *);
77863c7f71bSrm88369 void wait_ignore_by_fmri(const char *);
7797c478bd9Sstevel@tonic-gate 
7807c478bd9Sstevel@tonic-gate /* proc.c */
7817c478bd9Sstevel@tonic-gate ctid_t proc_get_ctid();
7827c478bd9Sstevel@tonic-gate 
78370cbfe41SPhilippe Jung /* deathrow.c */
78470cbfe41SPhilippe Jung extern void deathrow_init();
78570cbfe41SPhilippe Jung extern void deathrow_fini();
78670cbfe41SPhilippe Jung extern boolean_t is_fmri_in_deathrow(const char *);
78770cbfe41SPhilippe Jung 
7887c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
7897c478bd9Sstevel@tonic-gate }
7907c478bd9Sstevel@tonic-gate #endif
7917c478bd9Sstevel@tonic-gate 
7927c478bd9Sstevel@tonic-gate #endif	/* _STARTD_H */
793