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