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 */ 217c478bd9Sstevel@tonic-gate /* 22*63c7f71bSrm88369 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _STARTD_H 277c478bd9Sstevel@tonic-gate #define _STARTD_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #include <sys/time.h> 327c478bd9Sstevel@tonic-gate #include <librestart.h> 337c478bd9Sstevel@tonic-gate #include <librestart_priv.h> 347c478bd9Sstevel@tonic-gate #include <libscf.h> 357c478bd9Sstevel@tonic-gate #include <libsysevent.h> 367c478bd9Sstevel@tonic-gate #include <libuutil.h> 377c478bd9Sstevel@tonic-gate #include <pthread.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 /* 477c478bd9Sstevel@tonic-gate * We want MUTEX_HELD, but we also want pthreads. So we're stuck with this. 487c478bd9Sstevel@tonic-gate */ 497c478bd9Sstevel@tonic-gate #define PTHREAD_MUTEX_HELD(m) _mutex_held((struct _lwp_mutex *)(m)) 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate #ifndef NDEBUG 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate #define MUTEX_LOCK(mp) { \ 547c478bd9Sstevel@tonic-gate int err; \ 557c478bd9Sstevel@tonic-gate if ((err = pthread_mutex_lock((mp))) != 0) { \ 567c478bd9Sstevel@tonic-gate (void) fprintf(stderr, \ 577c478bd9Sstevel@tonic-gate "pthread_mutex_lock() failed on %s:%d: %s\n", \ 587c478bd9Sstevel@tonic-gate __FILE__, __LINE__, strerror(err)); \ 597c478bd9Sstevel@tonic-gate abort(); \ 607c478bd9Sstevel@tonic-gate } \ 617c478bd9Sstevel@tonic-gate } 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate #define MUTEX_UNLOCK(mp) { \ 647c478bd9Sstevel@tonic-gate int err; \ 657c478bd9Sstevel@tonic-gate if ((err = pthread_mutex_unlock((mp))) != 0) { \ 667c478bd9Sstevel@tonic-gate (void) fprintf(stderr, \ 677c478bd9Sstevel@tonic-gate "pthread_mutex_unlock() failed on %s:%d: %s\n", \ 687c478bd9Sstevel@tonic-gate __FILE__, __LINE__, strerror(err)); \ 697c478bd9Sstevel@tonic-gate abort(); \ 707c478bd9Sstevel@tonic-gate } \ 717c478bd9Sstevel@tonic-gate } 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate #else 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate #define MUTEX_LOCK(mp) (void) pthread_mutex_lock((mp)) 767c478bd9Sstevel@tonic-gate #define MUTEX_UNLOCK(mp) (void) pthread_mutex_unlock((mp)) 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate #endif 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate #ifndef NDEBUG 817c478bd9Sstevel@tonic-gate #define bad_error(func, err) { \ 827c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s:%d: %s() failed with unexpected " \ 837c478bd9Sstevel@tonic-gate "error %d. Aborting.\n", __FILE__, __LINE__, (func), (err)); \ 847c478bd9Sstevel@tonic-gate abort(); \ 857c478bd9Sstevel@tonic-gate } 867c478bd9Sstevel@tonic-gate #else 877c478bd9Sstevel@tonic-gate #define bad_error(func, err) abort() 887c478bd9Sstevel@tonic-gate #endif 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate #define min(a, b) (((a) < (b)) ? (a) : (b)) 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate #define FAULT_COUNT_INCR 0 947c478bd9Sstevel@tonic-gate #define FAULT_COUNT_RESET 1 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate #define FAULT_THRESHOLD 3 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate #define MAX_CONFIGD_RETRIES 5 997c478bd9Sstevel@tonic-gate #define MAX_MOUNT_RETRIES 5 1007c478bd9Sstevel@tonic-gate #define MAX_SULOGIN_RETRIES 5 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate #define RETURN_SUCCESS 0 1037c478bd9Sstevel@tonic-gate #define RETURN_RETRY -1 1047c478bd9Sstevel@tonic-gate #define RETURN_FATAL -2 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate #define LIBSCF_SUCCESS 0 1077c478bd9Sstevel@tonic-gate #define LIBSCF_PROPERTY_ABSENT -1 1087c478bd9Sstevel@tonic-gate #define LIBSCF_PGROUP_ABSENT -2 1097c478bd9Sstevel@tonic-gate #define LIBSCF_PROPERTY_ERROR -3 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate #define METHOD_START 0 1127c478bd9Sstevel@tonic-gate #define METHOD_STOP 1 1137c478bd9Sstevel@tonic-gate #define METHOD_REFRESH 2 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate #define METHOD_TIMEOUT_INFINITE 0 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate /* 1187c478bd9Sstevel@tonic-gate * Contract cookies used by startd. 1197c478bd9Sstevel@tonic-gate */ 1207c478bd9Sstevel@tonic-gate #define CONFIGD_COOKIE 0x10 1217c478bd9Sstevel@tonic-gate #define SULOGIN_COOKIE 0x11 1227c478bd9Sstevel@tonic-gate #define METHOD_START_COOKIE 0x20 1237c478bd9Sstevel@tonic-gate #define METHOD_OTHER_COOKIE 0x21 1247c478bd9Sstevel@tonic-gate #define MONITOR_COOKIE 0x30 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate #define ALLOC_RETRY 3 1287c478bd9Sstevel@tonic-gate #define ALLOC_DELAY 10 1297c478bd9Sstevel@tonic-gate #define ALLOC_DELAY_MULT 10 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate #define safe_scf_scope_create(h) \ 1327c478bd9Sstevel@tonic-gate libscf_object_create((void *(*)(scf_handle_t *))scf_scope_create, (h)) 1337c478bd9Sstevel@tonic-gate #define safe_scf_service_create(h) \ 1347c478bd9Sstevel@tonic-gate libscf_object_create((void *(*)(scf_handle_t *))scf_service_create, (h)) 1357c478bd9Sstevel@tonic-gate #define safe_scf_instance_create(h) libscf_object_create( \ 1367c478bd9Sstevel@tonic-gate (void *(*)(scf_handle_t *))scf_instance_create, (h)) 1377c478bd9Sstevel@tonic-gate #define safe_scf_snapshot_create(h) libscf_object_create( \ 1387c478bd9Sstevel@tonic-gate (void *(*)(scf_handle_t *))scf_snapshot_create, (h)) 1397c478bd9Sstevel@tonic-gate #define safe_scf_snaplevel_create(h) libscf_object_create( \ 1407c478bd9Sstevel@tonic-gate (void *(*)(scf_handle_t *))scf_snaplevel_create, (h)) 1417c478bd9Sstevel@tonic-gate #define safe_scf_pg_create(h) \ 1427c478bd9Sstevel@tonic-gate libscf_object_create((void *(*)(scf_handle_t *))scf_pg_create, (h)) 1437c478bd9Sstevel@tonic-gate #define safe_scf_property_create(h) libscf_object_create( \ 1447c478bd9Sstevel@tonic-gate (void *(*)(scf_handle_t *))scf_property_create, (h)) 1457c478bd9Sstevel@tonic-gate #define safe_scf_value_create(h) \ 1467c478bd9Sstevel@tonic-gate libscf_object_create((void *(*)(scf_handle_t *))scf_value_create, (h)) 1477c478bd9Sstevel@tonic-gate #define safe_scf_iter_create(h) \ 1487c478bd9Sstevel@tonic-gate libscf_object_create((void *(*)(scf_handle_t *))scf_iter_create, (h)) 1497c478bd9Sstevel@tonic-gate #define safe_scf_transaction_create(h) libscf_object_create( \ 1507c478bd9Sstevel@tonic-gate (void *(*)(scf_handle_t *)) scf_transaction_create, (h)) 1517c478bd9Sstevel@tonic-gate #define safe_scf_entry_create(h) \ 1527c478bd9Sstevel@tonic-gate libscf_object_create((void *(*)(scf_handle_t *))scf_entry_create, (h)) 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate #define startd_alloc(sz) \ 1557c478bd9Sstevel@tonic-gate startd_alloc_retry((void *(*)(size_t, int))umem_alloc, (sz)) 1567c478bd9Sstevel@tonic-gate #define startd_zalloc(sz) \ 1577c478bd9Sstevel@tonic-gate startd_alloc_retry((void *(*)(size_t, int))umem_zalloc, (sz)) 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate extern pthread_mutexattr_t mutex_attrs; 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate /* 1637c478bd9Sstevel@tonic-gate * Definitions for administrative actions. 1647c478bd9Sstevel@tonic-gate * Note that the ordering in admin_action_t, admin_actions, and admin_events 1657c478bd9Sstevel@tonic-gate * must match. admin_actions and admin_events are defined in startd.c. 1667c478bd9Sstevel@tonic-gate */ 1677c478bd9Sstevel@tonic-gate #define NACTIONS 6 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate typedef enum { 1707c478bd9Sstevel@tonic-gate ADMIN_EVENT_DEGRADED = 0x0, 1717c478bd9Sstevel@tonic-gate ADMIN_EVENT_MAINT_OFF, 1727c478bd9Sstevel@tonic-gate ADMIN_EVENT_MAINT_ON, 1737c478bd9Sstevel@tonic-gate ADMIN_EVENT_MAINT_ON_IMMEDIATE, 1747c478bd9Sstevel@tonic-gate ADMIN_EVENT_REFRESH, 1757c478bd9Sstevel@tonic-gate ADMIN_EVENT_RESTART 1767c478bd9Sstevel@tonic-gate } admin_action_t; 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate extern const char * const admin_actions[NACTIONS]; 1797c478bd9Sstevel@tonic-gate extern const int admin_events[NACTIONS]; 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate #define LOG_DATE_SIZE 32 /* Max size of timestamp in log output */ 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate extern ssize_t max_scf_name_size; 1847c478bd9Sstevel@tonic-gate extern ssize_t max_scf_value_size; 1857c478bd9Sstevel@tonic-gate extern ssize_t max_scf_fmri_size; 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate extern mode_t fmask; 1887c478bd9Sstevel@tonic-gate extern mode_t dmask; 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate #define LOG_PREFIX_EARLY "/etc/svc/volatile/" 1917c478bd9Sstevel@tonic-gate #define LOG_PREFIX_NORMAL "/var/svc/log/" 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate #define LOG_SUFFIX ".log" 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate #define STARTD_DEFAULT_LOG "svc.startd.log" 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate extern const char *log_directory; /* Current log directory path */ 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate #define FS_TIMEZONE_DIR "/usr/share/lib/zoneinfo" 2007c478bd9Sstevel@tonic-gate #define FS_LOCALE_DIR "/usr/lib/locale" 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate /* 2037c478bd9Sstevel@tonic-gate * Simple dictionary representation. 2047c478bd9Sstevel@tonic-gate */ 2057c478bd9Sstevel@tonic-gate typedef struct dictionary { 2067c478bd9Sstevel@tonic-gate uu_list_t *dict_list; 2077c478bd9Sstevel@tonic-gate int dict_new_id; 2087c478bd9Sstevel@tonic-gate pthread_mutex_t dict_lock; 2097c478bd9Sstevel@tonic-gate } dictionary_t; 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate typedef struct dict_entry { 2127c478bd9Sstevel@tonic-gate int de_id; 2137c478bd9Sstevel@tonic-gate const char *de_name; 2147c478bd9Sstevel@tonic-gate uu_list_node_t de_link; 2157c478bd9Sstevel@tonic-gate } dict_entry_t; 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate extern dictionary_t *dictionary; 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate typedef struct timeout_queue { 2207c478bd9Sstevel@tonic-gate uu_list_t *tq_list; 2217c478bd9Sstevel@tonic-gate pthread_mutex_t tq_lock; 2227c478bd9Sstevel@tonic-gate } timeout_queue_t; 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate typedef struct timeout_entry { 2257c478bd9Sstevel@tonic-gate hrtime_t te_timeout; /* timeout expiration time */ 2267c478bd9Sstevel@tonic-gate ctid_t te_ctid; 2277c478bd9Sstevel@tonic-gate char *te_fmri; 2287c478bd9Sstevel@tonic-gate char *te_logstem; 2297c478bd9Sstevel@tonic-gate volatile int te_fired; 2307c478bd9Sstevel@tonic-gate uu_list_node_t te_link; 2317c478bd9Sstevel@tonic-gate } timeout_entry_t; 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate extern timeout_queue_t *timeouts; 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate /* 2367c478bd9Sstevel@tonic-gate * State definitions. 2377c478bd9Sstevel@tonic-gate */ 2387c478bd9Sstevel@tonic-gate typedef enum { 2397c478bd9Sstevel@tonic-gate STATE_NONE = 0x0, 2407c478bd9Sstevel@tonic-gate STATE_UNINIT, 2417c478bd9Sstevel@tonic-gate STATE_MAINT, 2427c478bd9Sstevel@tonic-gate STATE_OFFLINE, 2437c478bd9Sstevel@tonic-gate STATE_DISABLED, 2447c478bd9Sstevel@tonic-gate STATE_ONLINE, 2457c478bd9Sstevel@tonic-gate STATE_DEGRADED 2467c478bd9Sstevel@tonic-gate } instance_state_t; 2477c478bd9Sstevel@tonic-gate 2487c478bd9Sstevel@tonic-gate #define STATE_MAX (STATE_DEGRADED + 1) 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate extern const char * const instance_state_str[STATE_MAX]; 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate typedef enum { 2537c478bd9Sstevel@tonic-gate GVT_UNSUPPORTED = -1, 2547c478bd9Sstevel@tonic-gate GVT_UNKNOWN = 0, 2557c478bd9Sstevel@tonic-gate GVT_SVC, /* service */ 2567c478bd9Sstevel@tonic-gate GVT_INST, /* instance */ 2577c478bd9Sstevel@tonic-gate GVT_FILE, /* file: */ 2587c478bd9Sstevel@tonic-gate GVT_GROUP /* dependency group */ 2597c478bd9Sstevel@tonic-gate } gv_type_t; 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate typedef enum { 2627c478bd9Sstevel@tonic-gate DEPGRP_UNSUPPORTED = -1, 2637c478bd9Sstevel@tonic-gate DEPGRP_REQUIRE_ANY = 1, 2647c478bd9Sstevel@tonic-gate DEPGRP_REQUIRE_ALL, 2657c478bd9Sstevel@tonic-gate DEPGRP_EXCLUDE_ALL, 2667c478bd9Sstevel@tonic-gate DEPGRP_OPTIONAL_ALL 2677c478bd9Sstevel@tonic-gate } depgroup_type_t; 2687c478bd9Sstevel@tonic-gate 2697c478bd9Sstevel@tonic-gate typedef enum { 2707c478bd9Sstevel@tonic-gate METHOD_RESTART_UNKNOWN = -1, 2717c478bd9Sstevel@tonic-gate METHOD_RESTART_ALL = 0, 2727c478bd9Sstevel@tonic-gate METHOD_RESTART_EXTERNAL_FAULT, 2737c478bd9Sstevel@tonic-gate METHOD_RESTART_ANY_FAULT, 2747c478bd9Sstevel@tonic-gate METHOD_RESTART_OTHER 2757c478bd9Sstevel@tonic-gate } method_restart_t; 2767c478bd9Sstevel@tonic-gate 277cd3bce3eSlianep typedef enum { 278cd3bce3eSlianep PROPAGATE_START, 279cd3bce3eSlianep PROPAGATE_STOP, 280cd3bce3eSlianep PROPAGATE_SAT 281cd3bce3eSlianep } propagate_event_t; 282cd3bce3eSlianep 2837c478bd9Sstevel@tonic-gate /* 2847c478bd9Sstevel@tonic-gate * Graph representation. 2857c478bd9Sstevel@tonic-gate */ 2867c478bd9Sstevel@tonic-gate #define GV_CONFIGURED 0x01 /* Service exists in repository, ready */ 2877c478bd9Sstevel@tonic-gate #define GV_ENABLED 0x02 /* Service should be online */ 2887c478bd9Sstevel@tonic-gate #define GV_ENBLD_NOOVR 0x04 /* GV_ENABLED, ignoring override */ 2897c478bd9Sstevel@tonic-gate #define GV_INSUBGRAPH 0x08 /* Current milestone depends on service */ 2907c478bd9Sstevel@tonic-gate 2917c478bd9Sstevel@tonic-gate /* ID must come first to support search */ 2927c478bd9Sstevel@tonic-gate typedef struct graph_vertex { 2937c478bd9Sstevel@tonic-gate int gv_id; 2947c478bd9Sstevel@tonic-gate char *gv_name; 2957c478bd9Sstevel@tonic-gate uu_list_node_t gv_link; 2967c478bd9Sstevel@tonic-gate 2977c478bd9Sstevel@tonic-gate uint_t gv_flags; 2987c478bd9Sstevel@tonic-gate restarter_instance_state_t gv_state; 2997c478bd9Sstevel@tonic-gate 3007c478bd9Sstevel@tonic-gate gv_type_t gv_type; 3017c478bd9Sstevel@tonic-gate 3027c478bd9Sstevel@tonic-gate depgroup_type_t gv_depgroup; 3037c478bd9Sstevel@tonic-gate restarter_error_t gv_restart; 3047c478bd9Sstevel@tonic-gate 3057c478bd9Sstevel@tonic-gate void (*gv_start_f)(struct graph_vertex *); 3067c478bd9Sstevel@tonic-gate void (*gv_post_online_f)(void); 3077c478bd9Sstevel@tonic-gate void (*gv_post_disable_f)(void); 3087c478bd9Sstevel@tonic-gate 3097c478bd9Sstevel@tonic-gate int gv_restarter_id; 3107c478bd9Sstevel@tonic-gate evchan_t *gv_restarter_channel; 3117c478bd9Sstevel@tonic-gate 3127c478bd9Sstevel@tonic-gate int gv_delegate_initialized; 3137c478bd9Sstevel@tonic-gate evchan_t *gv_delegate_channel; 3147c478bd9Sstevel@tonic-gate 3157c478bd9Sstevel@tonic-gate uu_list_t *gv_dependencies; 3167c478bd9Sstevel@tonic-gate uu_list_t *gv_dependents; 3173ad28c1eSrm88369 3183ad28c1eSrm88369 /* 3193ad28c1eSrm88369 * gv_refs represents the number of references besides dependencies. 3203ad28c1eSrm88369 * The vertex cannot be removed when gv_refs > 0. 3213ad28c1eSrm88369 * 3223ad28c1eSrm88369 * Currently, only relevant for GVT_SVC and GVT_INST type vertices. 3233ad28c1eSrm88369 */ 3243ad28c1eSrm88369 int gv_refs; 3257c478bd9Sstevel@tonic-gate } graph_vertex_t; 3267c478bd9Sstevel@tonic-gate 3277c478bd9Sstevel@tonic-gate typedef struct graph_edge { 3287c478bd9Sstevel@tonic-gate graph_vertex_t *ge_vertex; 3297c478bd9Sstevel@tonic-gate uu_list_node_t ge_link; 3307c478bd9Sstevel@tonic-gate graph_vertex_t *ge_parent; 3317c478bd9Sstevel@tonic-gate } graph_edge_t; 3327c478bd9Sstevel@tonic-gate 3337c478bd9Sstevel@tonic-gate /* 33499b44c3bSlianep * Restarter transition outcomes 3357c478bd9Sstevel@tonic-gate */ 3367c478bd9Sstevel@tonic-gate typedef enum { 33799b44c3bSlianep MAINT_REQUESTED, 3387c478bd9Sstevel@tonic-gate START_REQUESTED, 3397c478bd9Sstevel@tonic-gate START_FAILED_REPEATEDLY, 3407c478bd9Sstevel@tonic-gate START_FAILED_CONFIGURATION, 3417c478bd9Sstevel@tonic-gate START_FAILED_FATAL, 3427c478bd9Sstevel@tonic-gate START_FAILED_TIMEOUT_FATAL, 3437c478bd9Sstevel@tonic-gate START_FAILED_OTHER 3447c478bd9Sstevel@tonic-gate } start_outcome_t; 3457c478bd9Sstevel@tonic-gate 3467c478bd9Sstevel@tonic-gate typedef void (*instance_hook_t)(void); 3477c478bd9Sstevel@tonic-gate 3487c478bd9Sstevel@tonic-gate typedef struct service_hook_assn { 3497c478bd9Sstevel@tonic-gate char *sh_fmri; 3507c478bd9Sstevel@tonic-gate instance_hook_t sh_pre_online_hook; 3517c478bd9Sstevel@tonic-gate instance_hook_t sh_post_online_hook; 3527c478bd9Sstevel@tonic-gate instance_hook_t sh_post_offline_hook; 3537c478bd9Sstevel@tonic-gate } service_hook_assn_t; 3547c478bd9Sstevel@tonic-gate 3557c478bd9Sstevel@tonic-gate /* 3567c478bd9Sstevel@tonic-gate * Restarter instance stop reasons. 3577c478bd9Sstevel@tonic-gate */ 3587c478bd9Sstevel@tonic-gate typedef enum { 3597c478bd9Sstevel@tonic-gate RSTOP_EXIT = 0x0, /* exited or empty */ 3607c478bd9Sstevel@tonic-gate RSTOP_CORE, /* core dumped */ 3617c478bd9Sstevel@tonic-gate RSTOP_SIGNAL, /* external fatal signal received */ 3627c478bd9Sstevel@tonic-gate RSTOP_HWERR, /* uncorrectable hardware error */ 3637c478bd9Sstevel@tonic-gate RSTOP_DEPENDENCY, /* dependency activity caused stop */ 3647c478bd9Sstevel@tonic-gate RSTOP_DISABLE, /* disabled */ 3657c478bd9Sstevel@tonic-gate RSTOP_RESTART /* restart requested */ 3667c478bd9Sstevel@tonic-gate } stop_cause_t; 3677c478bd9Sstevel@tonic-gate 3687c478bd9Sstevel@tonic-gate /* 3697c478bd9Sstevel@tonic-gate * Restarter instance maintenance clear reasons. 3707c478bd9Sstevel@tonic-gate */ 3717c478bd9Sstevel@tonic-gate typedef enum { 3727c478bd9Sstevel@tonic-gate RUNMAINT_CLEAR = 0x0, 3737c478bd9Sstevel@tonic-gate RUNMAINT_DISABLE 3747c478bd9Sstevel@tonic-gate } unmaint_cause_t; 3757c478bd9Sstevel@tonic-gate 3767c478bd9Sstevel@tonic-gate /* 3777c478bd9Sstevel@tonic-gate * Restarter instance flags 3787c478bd9Sstevel@tonic-gate */ 3797c478bd9Sstevel@tonic-gate #define RINST_CONTRACT 0x00000000 /* progeny constitute inst */ 3807c478bd9Sstevel@tonic-gate #define RINST_TRANSIENT 0x10000000 /* inst operates momentarily */ 3817c478bd9Sstevel@tonic-gate #define RINST_WAIT 0x20000000 /* child constitutes inst */ 3827c478bd9Sstevel@tonic-gate #define RINST_STYLE_MASK 0xf0000000 3837c478bd9Sstevel@tonic-gate 3847c478bd9Sstevel@tonic-gate #define RINST_RETAKE_RUNNING 0x01000000 /* pending running snapshot */ 3857c478bd9Sstevel@tonic-gate #define RINST_RETAKE_START 0x02000000 /* pending start snapshot */ 3867c478bd9Sstevel@tonic-gate 3877c478bd9Sstevel@tonic-gate #define RINST_RETAKE_MASK 0x0f000000 3887c478bd9Sstevel@tonic-gate 3897c478bd9Sstevel@tonic-gate #define RINST_START_TIMES 10 /* failures to consider */ 3907c478bd9Sstevel@tonic-gate #define RINST_FAILURE_RATE_NS 1000000000LL /* 1 failure/second */ 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate /* Number of events in the queue when we start dropping ADMIN events. */ 3937c478bd9Sstevel@tonic-gate #define RINST_QUEUE_THRESHOLD 100 3947c478bd9Sstevel@tonic-gate 3957c478bd9Sstevel@tonic-gate typedef struct restarter_inst { 3967c478bd9Sstevel@tonic-gate int ri_id; 3977c478bd9Sstevel@tonic-gate instance_data_t ri_i; 3987c478bd9Sstevel@tonic-gate char *ri_common_name; /* template localized name */ 3997c478bd9Sstevel@tonic-gate char *ri_C_common_name; /* C locale name */ 4007c478bd9Sstevel@tonic-gate 4017c478bd9Sstevel@tonic-gate char *ri_logstem; /* logfile name */ 4027c478bd9Sstevel@tonic-gate char *ri_utmpx_prefix; 4037c478bd9Sstevel@tonic-gate uint_t ri_flags; 4047c478bd9Sstevel@tonic-gate instance_hook_t ri_pre_online_hook; 4057c478bd9Sstevel@tonic-gate instance_hook_t ri_post_online_hook; 4067c478bd9Sstevel@tonic-gate instance_hook_t ri_post_offline_hook; 4077c478bd9Sstevel@tonic-gate 4087c478bd9Sstevel@tonic-gate hrtime_t ri_start_time[RINST_START_TIMES]; 4097c478bd9Sstevel@tonic-gate uint_t ri_start_index; /* times started */ 4107c478bd9Sstevel@tonic-gate 4117c478bd9Sstevel@tonic-gate uu_list_node_t ri_link; 4127c478bd9Sstevel@tonic-gate pthread_mutex_t ri_lock; 4137c478bd9Sstevel@tonic-gate 4147c478bd9Sstevel@tonic-gate /* 4157c478bd9Sstevel@tonic-gate * When we start a thread to we execute a method for this instance, we 4167c478bd9Sstevel@tonic-gate * put the thread id in ri_method_thread. Threads with ids other than 4177c478bd9Sstevel@tonic-gate * this which acquire ri_lock while ri_method_thread is nonzero should 4187c478bd9Sstevel@tonic-gate * wait on ri_method_cv. ri_method_waiters should be incremented while 4197c478bd9Sstevel@tonic-gate * waiting so the instance won't be deleted. 4207c478bd9Sstevel@tonic-gate */ 4217c478bd9Sstevel@tonic-gate pthread_t ri_method_thread; 4227c478bd9Sstevel@tonic-gate pthread_cond_t ri_method_cv; 4237c478bd9Sstevel@tonic-gate uint_t ri_method_waiters; 4247c478bd9Sstevel@tonic-gate 4257c478bd9Sstevel@tonic-gate /* 4267c478bd9Sstevel@tonic-gate * These fields are provided so functions can operate on this structure 4277c478bd9Sstevel@tonic-gate * and the repository without worrying about whether the instance has 4287c478bd9Sstevel@tonic-gate * been deleted from the repository (this is possible because 4297c478bd9Sstevel@tonic-gate * ri_i.i_fmri names the instance this structure represents -- see 4307c478bd9Sstevel@tonic-gate * libscf_reget_inst()). ri_m_inst is the scf_instance_t for the 4317c478bd9Sstevel@tonic-gate * instance, and ri_mi_deleted is true if the instance has been deleted. 4327c478bd9Sstevel@tonic-gate */ 4337c478bd9Sstevel@tonic-gate scf_instance_t *ri_m_inst; 4347c478bd9Sstevel@tonic-gate boolean_t ri_mi_deleted; 4357c478bd9Sstevel@tonic-gate 4367c478bd9Sstevel@tonic-gate /* 4377c478bd9Sstevel@tonic-gate * We maintain a pointer to any pending timeout for this instance 4387c478bd9Sstevel@tonic-gate * for quick reference/deletion. 4397c478bd9Sstevel@tonic-gate */ 4407c478bd9Sstevel@tonic-gate timeout_entry_t *ri_timeout; 4417c478bd9Sstevel@tonic-gate 4427c478bd9Sstevel@tonic-gate /* 4437c478bd9Sstevel@tonic-gate * Instance event queue. Graph events are queued here as a list 4447c478bd9Sstevel@tonic-gate * of restarter_instance_qentry_t's, and the lock is held separately. 4457c478bd9Sstevel@tonic-gate * If both ri_lock and ri_queue_lock are grabbed, ri_lock must be 4467c478bd9Sstevel@tonic-gate * grabbed first. ri_queue_lock protects all ri_queue_* structure 4477c478bd9Sstevel@tonic-gate * members. 4487c478bd9Sstevel@tonic-gate */ 4497c478bd9Sstevel@tonic-gate pthread_mutex_t ri_queue_lock; 4507c478bd9Sstevel@tonic-gate pthread_cond_t ri_queue_cv; 4517c478bd9Sstevel@tonic-gate uu_list_t *ri_queue; 4527c478bd9Sstevel@tonic-gate int ri_queue_thread; 4537c478bd9Sstevel@tonic-gate 4547c478bd9Sstevel@tonic-gate } restarter_inst_t; 4557c478bd9Sstevel@tonic-gate 4567c478bd9Sstevel@tonic-gate typedef struct restarter_instance_list { 4577c478bd9Sstevel@tonic-gate uu_list_t *ril_instance_list; 4587c478bd9Sstevel@tonic-gate pthread_mutex_t ril_lock; 4597c478bd9Sstevel@tonic-gate } restarter_instance_list_t; 4607c478bd9Sstevel@tonic-gate 4617c478bd9Sstevel@tonic-gate typedef struct restarter_instance_qentry { 4627c478bd9Sstevel@tonic-gate restarter_event_type_t riq_type; 4637c478bd9Sstevel@tonic-gate uu_list_node_t riq_link; 4647c478bd9Sstevel@tonic-gate } restarter_instance_qentry_t; 4657c478bd9Sstevel@tonic-gate 4667c478bd9Sstevel@tonic-gate typedef struct fork_info { 4677c478bd9Sstevel@tonic-gate int sf_id; 4687c478bd9Sstevel@tonic-gate int sf_method_type; 4697c478bd9Sstevel@tonic-gate restarter_error_t sf_event_type; 4707c478bd9Sstevel@tonic-gate } fork_info_t; 4717c478bd9Sstevel@tonic-gate 4727c478bd9Sstevel@tonic-gate typedef struct wait_info { 4737c478bd9Sstevel@tonic-gate uu_list_node_t wi_link; 4747c478bd9Sstevel@tonic-gate 4757c478bd9Sstevel@tonic-gate int wi_fd; /* psinfo file descriptor */ 4767c478bd9Sstevel@tonic-gate id_t wi_pid; /* process ID */ 4777c478bd9Sstevel@tonic-gate const char *wi_fmri; /* instance FMRI */ 4787c478bd9Sstevel@tonic-gate int wi_parent; /* startd is parent */ 479*63c7f71bSrm88369 int wi_ignore; /* ignore events */ 4807c478bd9Sstevel@tonic-gate } wait_info_t; 4817c478bd9Sstevel@tonic-gate 4827c478bd9Sstevel@tonic-gate #define STARTD_LOG_FILE 0x1 4837c478bd9Sstevel@tonic-gate #define STARTD_LOG_TERMINAL 0x2 4847c478bd9Sstevel@tonic-gate #define STARTD_LOG_SYSLOG 0x4 4857c478bd9Sstevel@tonic-gate 4867c478bd9Sstevel@tonic-gate #define STARTD_BOOT_QUIET 0x1 4877c478bd9Sstevel@tonic-gate #define STARTD_BOOT_VERBOSE 0x2 4887c478bd9Sstevel@tonic-gate 4893efb42ecSrm88369 /* 4903efb42ecSrm88369 * Internal debug flags used to reduce the amount of data sent to the 4913efb42ecSrm88369 * internal debug buffer. They can be turned on & off dynamically using 4923efb42ecSrm88369 * internal_debug_flags variable in mdb. By default, they're off. 4933efb42ecSrm88369 */ 4943efb42ecSrm88369 #define DEBUG_DEPENDENCIES 0x1 4953efb42ecSrm88369 4967c478bd9Sstevel@tonic-gate typedef struct startd_state { 4977c478bd9Sstevel@tonic-gate /* Logging configuration */ 4987c478bd9Sstevel@tonic-gate char *st_log_prefix; /* directory prefix */ 4997c478bd9Sstevel@tonic-gate char *st_log_file; /* startd file in above dir */ 5007c478bd9Sstevel@tonic-gate uint_t st_log_flags; /* message destination */ 5017c478bd9Sstevel@tonic-gate int st_log_level_min; /* minimum required to log */ 5027c478bd9Sstevel@tonic-gate int st_log_timezone_known; /* timezone is available */ 5037c478bd9Sstevel@tonic-gate int st_log_locale_known; /* locale is available */ 5047c478bd9Sstevel@tonic-gate int st_log_login_reached; /* login service reached */ 5057c478bd9Sstevel@tonic-gate 5067c478bd9Sstevel@tonic-gate /* Boot configuration */ 5077c478bd9Sstevel@tonic-gate uint_t st_boot_flags; /* serial boot, etc. */ 5087c478bd9Sstevel@tonic-gate uint_t st_initial; /* first startd on system */ 5097c478bd9Sstevel@tonic-gate 5107c478bd9Sstevel@tonic-gate /* System configuration */ 5117c478bd9Sstevel@tonic-gate char *st_subgraph; /* milestone subgraph request */ 5127c478bd9Sstevel@tonic-gate 5137c478bd9Sstevel@tonic-gate uint_t st_load_complete; /* graph load completed */ 5147c478bd9Sstevel@tonic-gate uint_t st_load_instances; /* restarter instances to load */ 5157c478bd9Sstevel@tonic-gate pthread_mutex_t st_load_lock; 5167c478bd9Sstevel@tonic-gate pthread_cond_t st_load_cv; 5177c478bd9Sstevel@tonic-gate 5187c478bd9Sstevel@tonic-gate /* Repository configuration */ 5197c478bd9Sstevel@tonic-gate pid_t st_configd_pid; /* PID of our svc.configd */ 5207c478bd9Sstevel@tonic-gate /* instance */ 5217c478bd9Sstevel@tonic-gate int st_configd_lives; /* configd started */ 5227c478bd9Sstevel@tonic-gate pthread_mutex_t st_configd_live_lock; 5237c478bd9Sstevel@tonic-gate pthread_cond_t st_configd_live_cv; 5247c478bd9Sstevel@tonic-gate 5257c478bd9Sstevel@tonic-gate char *st_door_path; 5267c478bd9Sstevel@tonic-gate 5277c478bd9Sstevel@tonic-gate /* General information */ 5287c478bd9Sstevel@tonic-gate uint_t st_flags; 5297c478bd9Sstevel@tonic-gate struct timeval st_start_time; /* effective system start time */ 5307c478bd9Sstevel@tonic-gate char *st_locale; 5317c478bd9Sstevel@tonic-gate } startd_state_t; 5327c478bd9Sstevel@tonic-gate 5337c478bd9Sstevel@tonic-gate extern startd_state_t *st; 5347c478bd9Sstevel@tonic-gate 5357c478bd9Sstevel@tonic-gate extern boolean_t booting_to_single_user; 5367c478bd9Sstevel@tonic-gate 5377c478bd9Sstevel@tonic-gate extern const char *event_names[]; 5387c478bd9Sstevel@tonic-gate 5397c478bd9Sstevel@tonic-gate /* 5407c478bd9Sstevel@tonic-gate * Structures for contract to instance hash table, implemented in 5417c478bd9Sstevel@tonic-gate * contract.c and used by restarter.c and method.c 5427c478bd9Sstevel@tonic-gate */ 5437c478bd9Sstevel@tonic-gate typedef struct contract_entry { 5447c478bd9Sstevel@tonic-gate ctid_t ce_ctid; 5457c478bd9Sstevel@tonic-gate int ce_instid; 5467c478bd9Sstevel@tonic-gate 5477c478bd9Sstevel@tonic-gate uu_list_node_t ce_link; 5487c478bd9Sstevel@tonic-gate } contract_entry_t; 5497c478bd9Sstevel@tonic-gate 550dfe57350Sjeanm extern volatile uint16_t storing_contract; 551dfe57350Sjeanm 5527c478bd9Sstevel@tonic-gate uu_list_pool_t *contract_list_pool; 5537c478bd9Sstevel@tonic-gate 5547c478bd9Sstevel@tonic-gate /* contract.c */ 5557c478bd9Sstevel@tonic-gate ctid_t contract_init(void); 5567c478bd9Sstevel@tonic-gate void contract_abandon(ctid_t); 5577c478bd9Sstevel@tonic-gate int contract_kill(ctid_t, int, const char *); 5587c478bd9Sstevel@tonic-gate int contract_is_empty(ctid_t); 5597c478bd9Sstevel@tonic-gate void contract_hash_init(); 5607c478bd9Sstevel@tonic-gate void contract_hash_store(ctid_t, int); 5617c478bd9Sstevel@tonic-gate void contract_hash_remove(ctid_t); 5627c478bd9Sstevel@tonic-gate int lookup_inst_by_contract(ctid_t); 5637c478bd9Sstevel@tonic-gate 5647c478bd9Sstevel@tonic-gate /* dict.c */ 5657c478bd9Sstevel@tonic-gate void dict_init(void); 5667c478bd9Sstevel@tonic-gate int dict_lookup_byname(const char *); 5677c478bd9Sstevel@tonic-gate int dict_insert(const char *); 5687c478bd9Sstevel@tonic-gate 5697c478bd9Sstevel@tonic-gate /* expand.c */ 5707c478bd9Sstevel@tonic-gate int expand_method_tokens(const char *, scf_instance_t *, 5717c478bd9Sstevel@tonic-gate scf_snapshot_t *, int, char **); 5727c478bd9Sstevel@tonic-gate 5737c478bd9Sstevel@tonic-gate /* env.c */ 5747c478bd9Sstevel@tonic-gate void init_env(void); 5757c478bd9Sstevel@tonic-gate char **set_smf_env(char **, size_t, const char *, 5767c478bd9Sstevel@tonic-gate const restarter_inst_t *, const char *); 5777c478bd9Sstevel@tonic-gate 5787c478bd9Sstevel@tonic-gate /* file.c */ 5797c478bd9Sstevel@tonic-gate int file_ready(graph_vertex_t *); 5807c478bd9Sstevel@tonic-gate 5817c478bd9Sstevel@tonic-gate /* fork.c */ 5827c478bd9Sstevel@tonic-gate int fork_mount(char *, char *); 5837c478bd9Sstevel@tonic-gate void fork_sulogin(boolean_t, const char *, ...); 5847c478bd9Sstevel@tonic-gate void fork_rc_script(char, const char *, boolean_t); 5857c478bd9Sstevel@tonic-gate 5867c478bd9Sstevel@tonic-gate void *fork_configd_thread(void *); 5877c478bd9Sstevel@tonic-gate 5887c478bd9Sstevel@tonic-gate pid_t startd_fork1(int *); 5897c478bd9Sstevel@tonic-gate 5907c478bd9Sstevel@tonic-gate /* graph.c */ 5917c478bd9Sstevel@tonic-gate void graph_init(void); 5927c478bd9Sstevel@tonic-gate void *single_user_thread(void *); 5937c478bd9Sstevel@tonic-gate void *graph_thread(void *); 5947c478bd9Sstevel@tonic-gate void *graph_event_thread(void *); 5957c478bd9Sstevel@tonic-gate void *repository_event_thread(void *); 5967c478bd9Sstevel@tonic-gate int dgraph_add_instance(const char *, scf_instance_t *, boolean_t); 5977c478bd9Sstevel@tonic-gate void graph_engine_start(void); 59899b44c3bSlianep void graph_enable_by_vertex(graph_vertex_t *, int, int); 59999b44c3bSlianep int refresh_vertex(graph_vertex_t *, scf_instance_t *); 60099b44c3bSlianep void vertex_send_event(graph_vertex_t *, restarter_event_type_t); 60199b44c3bSlianep void graph_start_if_satisfied(graph_vertex_t *); 60256e23938Sbustos int vertex_subgraph_dependencies_shutdown(scf_handle_t *, graph_vertex_t *, 60356e23938Sbustos restarter_instance_state_t); 60499b44c3bSlianep void graph_transition_sulogin(restarter_instance_state_t, 60599b44c3bSlianep restarter_instance_state_t); 606cd3bce3eSlianep void graph_transition_propagate(graph_vertex_t *, propagate_event_t, 60799b44c3bSlianep restarter_error_t); 6087c478bd9Sstevel@tonic-gate 6097c478bd9Sstevel@tonic-gate /* libscf.c - common */ 6107c478bd9Sstevel@tonic-gate char *inst_fmri_to_svc_fmri(const char *); 6117c478bd9Sstevel@tonic-gate void *libscf_object_create(void *(*)(scf_handle_t *), scf_handle_t *); 6127c478bd9Sstevel@tonic-gate int libscf_instance_get_fmri(scf_instance_t *, char **); 6137c478bd9Sstevel@tonic-gate int libscf_fmri_get_instance(scf_handle_t *, const char *, scf_instance_t **); 6147c478bd9Sstevel@tonic-gate int libscf_lookup_instance(const char *, scf_instance_t *); 6157c478bd9Sstevel@tonic-gate int libscf_set_reconfig(int); 6167c478bd9Sstevel@tonic-gate scf_snapshot_t *libscf_get_or_make_running_snapshot(scf_instance_t *, 6177c478bd9Sstevel@tonic-gate const char *, boolean_t); 6187c478bd9Sstevel@tonic-gate int libscf_inst_set_count_prop(scf_instance_t *, const char *, 6197c478bd9Sstevel@tonic-gate const char *pgtype, uint32_t, const char *, uint64_t); 6207c478bd9Sstevel@tonic-gate 6217c478bd9Sstevel@tonic-gate /* libscf.c - used by graph.c */ 6227c478bd9Sstevel@tonic-gate int libscf_get_basic_instance_data(scf_handle_t *, scf_instance_t *, 6237c478bd9Sstevel@tonic-gate const char *, int *, int *, char **); 6247c478bd9Sstevel@tonic-gate int libscf_inst_get_or_add_pg(scf_instance_t *, const char *, const char *, 6257c478bd9Sstevel@tonic-gate uint32_t, scf_propertygroup_t *); 6267c478bd9Sstevel@tonic-gate int libscf_read_states(const scf_propertygroup_t *, 6277c478bd9Sstevel@tonic-gate restarter_instance_state_t *, restarter_instance_state_t *); 6287c478bd9Sstevel@tonic-gate int depgroup_empty(scf_handle_t *, scf_propertygroup_t *); 6297c478bd9Sstevel@tonic-gate gv_type_t depgroup_read_scheme(scf_handle_t *, scf_propertygroup_t *); 6307c478bd9Sstevel@tonic-gate depgroup_type_t depgroup_read_grouping(scf_handle_t *, scf_propertygroup_t *); 6317c478bd9Sstevel@tonic-gate restarter_error_t depgroup_read_restart(scf_handle_t *, scf_propertygroup_t *); 6327c478bd9Sstevel@tonic-gate int libscf_set_enable_ovr(scf_instance_t *, int); 6337c478bd9Sstevel@tonic-gate int libscf_inst_delete_prop(scf_instance_t *, const char *, const char *); 6347c478bd9Sstevel@tonic-gate int libscf_delete_enable_ovr(scf_instance_t *); 6357c478bd9Sstevel@tonic-gate int libscf_get_milestone(scf_instance_t *, scf_property_t *, scf_value_t *, 6367c478bd9Sstevel@tonic-gate char *, size_t); 6377c478bd9Sstevel@tonic-gate int libscf_extract_runlevel(scf_property_t *, char *); 6387c478bd9Sstevel@tonic-gate int libscf_clear_runlevel(scf_propertygroup_t *, const char *milestone); 6397c478bd9Sstevel@tonic-gate 6407c478bd9Sstevel@tonic-gate typedef int (*callback_t)(void *, void *); 6417c478bd9Sstevel@tonic-gate 6427c478bd9Sstevel@tonic-gate int walk_dependency_pgs(scf_instance_t *, callback_t, void *); 6437c478bd9Sstevel@tonic-gate int walk_property_astrings(scf_property_t *, callback_t, void *); 6447c478bd9Sstevel@tonic-gate 6457c478bd9Sstevel@tonic-gate /* libscf.c - used by restarter.c/method.c/expand.c */ 6467c478bd9Sstevel@tonic-gate char *libscf_get_method(scf_handle_t *, int, restarter_inst_t *, 6477c478bd9Sstevel@tonic-gate scf_snapshot_t *, method_restart_t *, uint_t *, uint8_t *, uint64_t *, 6487c478bd9Sstevel@tonic-gate uint8_t *); 6497c478bd9Sstevel@tonic-gate void libscf_populate_graph(scf_handle_t *h); 6507c478bd9Sstevel@tonic-gate int update_fault_count(restarter_inst_t *, int); 6517c478bd9Sstevel@tonic-gate int libscf_unset_action(scf_handle_t *, scf_propertygroup_t *, admin_action_t, 6527c478bd9Sstevel@tonic-gate int64_t); 6537c478bd9Sstevel@tonic-gate int libscf_get_startd_properties(scf_instance_t *, scf_snapshot_t *, uint_t *, 6547c478bd9Sstevel@tonic-gate char **); 6557c478bd9Sstevel@tonic-gate int libscf_get_template_values(scf_instance_t *, scf_snapshot_t *, char **, 6567c478bd9Sstevel@tonic-gate char **); 6577c478bd9Sstevel@tonic-gate 6587c478bd9Sstevel@tonic-gate int libscf_read_method_ids(scf_handle_t *, scf_instance_t *, const char *, 6597c478bd9Sstevel@tonic-gate ctid_t *, ctid_t *, pid_t *); 6607c478bd9Sstevel@tonic-gate int libscf_write_start_pid(scf_instance_t *, pid_t); 6617c478bd9Sstevel@tonic-gate int libscf_write_method_status(scf_instance_t *, const char *, int); 6627c478bd9Sstevel@tonic-gate int libscf_note_method_log(scf_instance_t *, const char *, const char *); 6637c478bd9Sstevel@tonic-gate 6647c478bd9Sstevel@tonic-gate scf_handle_t *libscf_handle_create_bound(scf_version_t); 6657c478bd9Sstevel@tonic-gate void libscf_handle_rebind(scf_handle_t *); 6667c478bd9Sstevel@tonic-gate scf_handle_t *libscf_handle_create_bound_loop(void); 6677c478bd9Sstevel@tonic-gate 6687c478bd9Sstevel@tonic-gate scf_snapshot_t *libscf_get_running_snapshot(scf_instance_t *); 6697c478bd9Sstevel@tonic-gate int libscf_snapshots_poststart(scf_handle_t *, const char *, boolean_t); 6707c478bd9Sstevel@tonic-gate int libscf_snapshots_refresh(scf_instance_t *, const char *); 6717c478bd9Sstevel@tonic-gate 6727c478bd9Sstevel@tonic-gate int instance_is_transient_style(restarter_inst_t *); 6737c478bd9Sstevel@tonic-gate int instance_is_wait_style(restarter_inst_t *); 6747c478bd9Sstevel@tonic-gate 6757c478bd9Sstevel@tonic-gate int libscf_create_self(scf_handle_t *); 6767c478bd9Sstevel@tonic-gate 6777c478bd9Sstevel@tonic-gate void libscf_reget_instance(restarter_inst_t *); 6787c478bd9Sstevel@tonic-gate 6797c478bd9Sstevel@tonic-gate /* log.c */ 6807c478bd9Sstevel@tonic-gate void log_init(); 6817c478bd9Sstevel@tonic-gate void log_error(int, const char *, ...); 6827c478bd9Sstevel@tonic-gate void log_framework(int, const char *, ...); 6833efb42ecSrm88369 void log_framework2(int, int, const char *, ...); 6847c478bd9Sstevel@tonic-gate void log_console(int, const char *, ...); 6857c478bd9Sstevel@tonic-gate void log_preexec(void); 6867c478bd9Sstevel@tonic-gate void setlog(const char *); 6877c478bd9Sstevel@tonic-gate void log_transition(const restarter_inst_t *, start_outcome_t); 6887c478bd9Sstevel@tonic-gate void log_instance(const restarter_inst_t *, boolean_t, const char *, ...); 6897c478bd9Sstevel@tonic-gate void log_instance_fmri(const char *, const char *, boolean_t, 6907c478bd9Sstevel@tonic-gate const char *, ...); 6917c478bd9Sstevel@tonic-gate 6927c478bd9Sstevel@tonic-gate /* method.c */ 6937c478bd9Sstevel@tonic-gate void *method_thread(void *); 6947c478bd9Sstevel@tonic-gate void method_remove_contract(restarter_inst_t *, boolean_t, boolean_t); 6957c478bd9Sstevel@tonic-gate 6967c478bd9Sstevel@tonic-gate /* misc.c */ 6977c478bd9Sstevel@tonic-gate void startd_close(int); 6987c478bd9Sstevel@tonic-gate void startd_fclose(FILE *); 6997c478bd9Sstevel@tonic-gate int fmri_canonify(const char *, char **, boolean_t); 7007c478bd9Sstevel@tonic-gate int fs_is_read_only(char *, ulong_t *); 7017c478bd9Sstevel@tonic-gate int fs_remount(char *); 7027c478bd9Sstevel@tonic-gate void xstr_sanitize(char *); 7037c478bd9Sstevel@tonic-gate 7047c478bd9Sstevel@tonic-gate /* restarter.c */ 7057c478bd9Sstevel@tonic-gate void restarter_init(void); 7067c478bd9Sstevel@tonic-gate void restarter_start(void); 7077c478bd9Sstevel@tonic-gate int instance_in_transition(restarter_inst_t *); 7087c478bd9Sstevel@tonic-gate int restarter_instance_update_states(scf_handle_t *, restarter_inst_t *, 7097c478bd9Sstevel@tonic-gate restarter_instance_state_t, restarter_instance_state_t, restarter_error_t, 7107c478bd9Sstevel@tonic-gate char *); 7117c478bd9Sstevel@tonic-gate int stop_instance_fmri(scf_handle_t *, const char *, uint_t); 7127c478bd9Sstevel@tonic-gate restarter_inst_t *inst_lookup_by_id(int); 7137c478bd9Sstevel@tonic-gate void restarter_mark_pending_snapshot(const char *, uint_t); 7147c478bd9Sstevel@tonic-gate void *restarter_post_fsminimal_thread(void *); 7157c478bd9Sstevel@tonic-gate void timeout_insert(restarter_inst_t *, ctid_t, uint64_t); 7167c478bd9Sstevel@tonic-gate void timeout_remove(restarter_inst_t *, ctid_t); 7177c478bd9Sstevel@tonic-gate void timeout_init(void); 7187c478bd9Sstevel@tonic-gate int is_timeout_ovr(restarter_inst_t *); 7197c478bd9Sstevel@tonic-gate 7207c478bd9Sstevel@tonic-gate /* startd.c */ 7217c478bd9Sstevel@tonic-gate void *safe_realloc(void *, size_t); 7227c478bd9Sstevel@tonic-gate char *safe_strdup(const char *s); 7237c478bd9Sstevel@tonic-gate void *startd_alloc_retry(void *(*)(size_t, int), size_t); 7247c478bd9Sstevel@tonic-gate void startd_free(void *, size_t); 7257c478bd9Sstevel@tonic-gate uu_list_pool_t *startd_list_pool_create(const char *, size_t, size_t, 7267c478bd9Sstevel@tonic-gate uu_compare_fn_t *, uint32_t); 7277c478bd9Sstevel@tonic-gate uu_list_t *startd_list_create(uu_list_pool_t *, void *, uint32_t); 7287c478bd9Sstevel@tonic-gate pthread_t startd_thread_create(void *(*)(void *), void *); 7297c478bd9Sstevel@tonic-gate 7307c478bd9Sstevel@tonic-gate /* special.c */ 7317c478bd9Sstevel@tonic-gate void special_null_transition(void); 7327c478bd9Sstevel@tonic-gate void special_online_hooks_get(const char *, instance_hook_t *, 7337c478bd9Sstevel@tonic-gate instance_hook_t *, instance_hook_t *); 7347c478bd9Sstevel@tonic-gate 73599b44c3bSlianep /* transition.c */ 73699b44c3bSlianep int gt_transition(scf_handle_t *, graph_vertex_t *, restarter_error_t, 737cd3bce3eSlianep restarter_instance_state_t); 73899b44c3bSlianep 7397c478bd9Sstevel@tonic-gate /* utmpx.c */ 7407c478bd9Sstevel@tonic-gate void utmpx_init(void); 7417c478bd9Sstevel@tonic-gate void utmpx_clear_old(void); 7427c478bd9Sstevel@tonic-gate int utmpx_mark_init(pid_t, char *); 7437c478bd9Sstevel@tonic-gate void utmpx_mark_dead(pid_t, int, boolean_t); 7447c478bd9Sstevel@tonic-gate char utmpx_get_runlevel(void); 7457c478bd9Sstevel@tonic-gate void utmpx_set_runlevel(char, char, boolean_t); 7467c478bd9Sstevel@tonic-gate void utmpx_write_boottime(void); 7477c478bd9Sstevel@tonic-gate 7487c478bd9Sstevel@tonic-gate /* wait.c */ 7497c478bd9Sstevel@tonic-gate void wait_init(void); 7507c478bd9Sstevel@tonic-gate void wait_prefork(void); 7517c478bd9Sstevel@tonic-gate void wait_postfork(pid_t); 7527c478bd9Sstevel@tonic-gate int wait_register(pid_t, const char *, int, int); 7537c478bd9Sstevel@tonic-gate void *wait_thread(void *); 754*63c7f71bSrm88369 void wait_ignore_by_fmri(const char *); 7557c478bd9Sstevel@tonic-gate 7567c478bd9Sstevel@tonic-gate /* proc.c */ 7577c478bd9Sstevel@tonic-gate ctid_t proc_get_ctid(); 7587c478bd9Sstevel@tonic-gate 7597c478bd9Sstevel@tonic-gate #ifdef __cplusplus 7607c478bd9Sstevel@tonic-gate } 7617c478bd9Sstevel@tonic-gate #endif 7627c478bd9Sstevel@tonic-gate 7637c478bd9Sstevel@tonic-gate #endif /* _STARTD_H */ 764