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