startd.h revision dfe5735016dd804901e28c9585549f5aa15bb63b
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _STARTD_H
#define _STARTD_H
#pragma ident "%Z%%M% %I% %E% SMI"
#include <librestart.h>
#include <librestart_priv.h>
#include <libscf.h>
#include <libsysevent.h>
#include <libuutil.h>
#include <pthread.h>
#include <stdio.h>
#include <syslog.h>
#include <umem.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* We want MUTEX_HELD, but we also want pthreads. So we're stuck with this.
*/
#ifndef NDEBUG
#define MUTEX_LOCK(mp) { \
int err; \
"pthread_mutex_lock() failed on %s:%d: %s\n", \
abort(); \
} \
}
#define MUTEX_UNLOCK(mp) { \
int err; \
"pthread_mutex_unlock() failed on %s:%d: %s\n", \
abort(); \
} \
}
#else
#endif
#ifndef NDEBUG
abort(); \
}
#else
#endif
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define FAULT_COUNT_INCR 0
#define FAULT_COUNT_RESET 1
#define FAULT_THRESHOLD 3
#define MAX_CONFIGD_RETRIES 5
#define MAX_MOUNT_RETRIES 5
#define MAX_SULOGIN_RETRIES 5
#define RETURN_SUCCESS 0
#define RETURN_RETRY -1
#define RETURN_FATAL -2
#define LIBSCF_SUCCESS 0
#define LIBSCF_PROPERTY_ABSENT -1
#define LIBSCF_PGROUP_ABSENT -2
#define LIBSCF_PROPERTY_ERROR -3
#define METHOD_START 0
#define METHOD_STOP 1
#define METHOD_REFRESH 2
#define METHOD_TIMEOUT_INFINITE 0
/*
* Contract cookies used by startd.
*/
#define CONFIGD_COOKIE 0x10
#define SULOGIN_COOKIE 0x11
#define METHOD_START_COOKIE 0x20
#define METHOD_OTHER_COOKIE 0x21
#define MONITOR_COOKIE 0x30
#define ALLOC_RETRY 3
#define ALLOC_DELAY 10
#define ALLOC_DELAY_MULT 10
#define safe_scf_scope_create(h) \
#define safe_scf_service_create(h) \
#define safe_scf_instance_create(h) libscf_object_create( \
(void *(*)(scf_handle_t *))scf_instance_create, (h))
#define safe_scf_snapshot_create(h) libscf_object_create( \
(void *(*)(scf_handle_t *))scf_snapshot_create, (h))
#define safe_scf_snaplevel_create(h) libscf_object_create( \
(void *(*)(scf_handle_t *))scf_snaplevel_create, (h))
#define safe_scf_pg_create(h) \
#define safe_scf_property_create(h) libscf_object_create( \
(void *(*)(scf_handle_t *))scf_property_create, (h))
#define safe_scf_value_create(h) \
#define safe_scf_iter_create(h) \
#define safe_scf_transaction_create(h) libscf_object_create( \
(void *(*)(scf_handle_t *)) scf_transaction_create, (h))
#define safe_scf_entry_create(h) \
#define startd_alloc(sz) \
#define startd_zalloc(sz) \
extern pthread_mutexattr_t mutex_attrs;
/*
* Definitions for administrative actions.
* Note that the ordering in admin_action_t, admin_actions, and admin_events
* must match. admin_actions and admin_events are defined in startd.c.
*/
#define NACTIONS 6
typedef enum {
ADMIN_EVENT_DEGRADED = 0x0,
extern const char * const admin_actions[NACTIONS];
extern const int admin_events[NACTIONS];
extern ssize_t max_scf_name_size;
extern ssize_t max_scf_value_size;
extern ssize_t max_scf_fmri_size;
#define LOG_PREFIX_EARLY "/etc/svc/volatile/"
#define LOG_PREFIX_NORMAL "/var/svc/log/"
#define LOG_SUFFIX ".log"
#define STARTD_DEFAULT_LOG "svc.startd.log"
extern const char *log_directory; /* Current log directory path */
#define FS_TIMEZONE_DIR "/usr/share/lib/zoneinfo"
#define FS_LOCALE_DIR "/usr/lib/locale"
/*
* Simple dictionary representation.
*/
typedef struct dictionary {
int dict_new_id;
} dictionary_t;
typedef struct dict_entry {
int de_id;
const char *de_name;
} dict_entry_t;
extern dictionary_t *dictionary;
typedef struct timeout_queue {
typedef struct timeout_entry {
char *te_fmri;
char *te_logstem;
volatile int te_fired;
extern timeout_queue_t *timeouts;
/*
* State definitions.
*/
typedef enum {
STATE_NONE = 0x0,
extern const char * const instance_state_str[STATE_MAX];
typedef enum {
GVT_UNSUPPORTED = -1,
GVT_UNKNOWN = 0,
GVT_SVC, /* service */
GVT_INST, /* instance */
GVT_FILE, /* file: */
GVT_GROUP /* dependency group */
} gv_type_t;
typedef enum {
DEPGRP_UNSUPPORTED = -1,
DEPGRP_REQUIRE_ANY = 1,
typedef enum {
METHOD_RESTART_UNKNOWN = -1,
METHOD_RESTART_ALL = 0,
typedef enum {
/*
* Graph representation.
*/
/* ID must come first to support search */
typedef struct graph_vertex {
int gv_id;
char *gv_name;
void (*gv_start_f)(struct graph_vertex *);
void (*gv_post_online_f)(void);
void (*gv_post_disable_f)(void);
int gv_restarter_id;
/*
* gv_refs represents the number of references besides dependencies.
* The vertex cannot be removed when gv_refs > 0.
*
* Currently, only relevant for GVT_SVC and GVT_INST type vertices.
*/
int gv_refs;
typedef struct graph_edge {
} graph_edge_t;
/*
* Restarter transition outcomes
*/
typedef enum {
typedef void (*instance_hook_t)(void);
typedef struct service_hook_assn {
char *sh_fmri;
/*
* Restarter instance stop reasons.
*/
typedef enum {
RSTOP_CORE, /* core dumped */
RSTOP_SIGNAL, /* external fatal signal received */
RSTOP_HWERR, /* uncorrectable hardware error */
RSTOP_DEPENDENCY, /* dependency activity caused stop */
RSTOP_DISABLE, /* disabled */
RSTOP_RESTART /* restart requested */
} stop_cause_t;
/*
* Restarter instance maintenance clear reasons.
*/
typedef enum {
RUNMAINT_CLEAR = 0x0,
/*
* Restarter instance flags
*/
#define RINST_STYLE_MASK 0xf0000000
#define RINST_RETAKE_MASK 0x0f000000
/* Number of events in the queue when we start dropping ADMIN events. */
#define RINST_QUEUE_THRESHOLD 100
typedef struct restarter_inst {
int ri_id;
char *ri_common_name; /* template localized name */
char *ri_C_common_name; /* C locale name */
char *ri_logstem; /* logfile name */
char *ri_utmpx_prefix;
/*
* When we start a thread to we execute a method for this instance, we
* put the thread id in ri_method_thread. Threads with ids other than
* this which acquire ri_lock while ri_method_thread is nonzero should
* wait on ri_method_cv. ri_method_waiters should be incremented while
* waiting so the instance won't be deleted.
*/
/*
* These fields are provided so functions can operate on this structure
* and the repository without worrying about whether the instance has
* been deleted from the repository (this is possible because
* ri_i.i_fmri names the instance this structure represents -- see
* libscf_reget_inst()). ri_m_inst is the scf_instance_t for the
* instance, and ri_mi_deleted is true if the instance has been deleted.
*/
/*
* We maintain a pointer to any pending timeout for this instance
*/
/*
* Instance event queue. Graph events are queued here as a list
* of restarter_instance_qentry_t's, and the lock is held separately.
* If both ri_lock and ri_queue_lock are grabbed, ri_lock must be
* grabbed first. ri_queue_lock protects all ri_queue_* structure
* members.
*/
int ri_queue_thread;
typedef struct restarter_instance_list {
typedef struct restarter_instance_qentry {
typedef struct fork_info {
int sf_id;
int sf_method_type;
} fork_info_t;
typedef struct wait_info {
int wi_fd; /* psinfo file descriptor */
const char *wi_fmri; /* instance FMRI */
int wi_parent; /* startd is parent */
} wait_info_t;
#define STARTD_LOG_FILE 0x1
#define STARTD_LOG_TERMINAL 0x2
#define STARTD_LOG_SYSLOG 0x4
#define STARTD_BOOT_QUIET 0x1
#define STARTD_BOOT_VERBOSE 0x2
typedef struct startd_state {
/* Logging configuration */
char *st_log_prefix; /* directory prefix */
char *st_log_file; /* startd file in above dir */
int st_log_level_min; /* minimum required to log */
int st_log_timezone_known; /* timezone is available */
int st_log_locale_known; /* locale is available */
int st_log_login_reached; /* login service reached */
/* Boot configuration */
/* System configuration */
char *st_subgraph; /* milestone subgraph request */
/* Repository configuration */
/* instance */
int st_configd_lives; /* configd started */
char *st_door_path;
/* General information */
char *st_locale;
extern startd_state_t *st;
extern boolean_t booting_to_single_user;
extern const char *event_names[];
/*
* Structures for contract to instance hash table, implemented in
* contract.c and used by restarter.c and method.c
*/
typedef struct contract_entry {
int ce_instid;
extern volatile uint16_t storing_contract;
/* contract.c */
ctid_t contract_init(void);
void contract_abandon(ctid_t);
int contract_kill(ctid_t, int, const char *);
int contract_is_empty(ctid_t);
void contract_hash_init();
void contract_hash_store(ctid_t, int);
void contract_hash_remove(ctid_t);
/* dict.c */
void dict_init(void);
int dict_lookup_byname(const char *);
int dict_insert(const char *);
/* expand.c */
int expand_method_tokens(const char *, scf_instance_t *,
scf_snapshot_t *, int, char **);
/* env.c */
void init_env(void);
char **set_smf_env(char **, size_t, const char *,
const restarter_inst_t *, const char *);
/* file.c */
int file_ready(graph_vertex_t *);
/* fork.c */
int fork_mount(char *, char *);
void fork_sulogin(boolean_t, const char *, ...);
void fork_rc_script(char, const char *, boolean_t);
void *fork_configd_thread(void *);
pid_t startd_fork1(int *);
/* graph.c */
void graph_init(void);
void *single_user_thread(void *);
void *graph_thread(void *);
void *graph_event_thread(void *);
void *repository_event_thread(void *);
void graph_engine_start(void);
void graph_enable_by_vertex(graph_vertex_t *, int, int);
void graph_start_if_satisfied(graph_vertex_t *);
/* libscf.c - common */
char *inst_fmri_to_svc_fmri(const char *);
int libscf_instance_get_fmri(scf_instance_t *, char **);
int libscf_lookup_instance(const char *, scf_instance_t *);
int libscf_set_reconfig(int);
const char *, boolean_t);
int libscf_inst_set_count_prop(scf_instance_t *, const char *,
const char *, int *, int *, char **);
int libscf_inst_get_or_add_pg(scf_instance_t *, const char *, const char *,
int libscf_read_states(const scf_propertygroup_t *,
int libscf_set_enable_ovr(scf_instance_t *, int);
int libscf_inst_delete_prop(scf_instance_t *, const char *, const char *);
char *, size_t);
int libscf_extract_runlevel(scf_property_t *, char *);
typedef int (*callback_t)(void *, void *);
/* libscf.c - used by restarter.c/method.c/expand.c */
uint8_t *);
void libscf_populate_graph(scf_handle_t *h);
int update_fault_count(restarter_inst_t *, int);
int64_t);
char **);
char **);
int libscf_write_method_status(scf_instance_t *, const char *, int);
int libscf_note_method_log(scf_instance_t *, const char *, const char *);
void libscf_handle_rebind(scf_handle_t *);
int libscf_snapshots_refresh(scf_instance_t *, const char *);
int libscf_create_self(scf_handle_t *);
void libscf_reget_instance(restarter_inst_t *);
/* log.c */
void log_init();
void log_error(int, const char *, ...);
void log_framework(int, const char *, ...);
void log_console(int, const char *, ...);
void log_preexec(void);
void setlog(const char *);
void log_instance_fmri(const char *, const char *, boolean_t,
const char *, ...);
/* method.c */
void *method_thread(void *);
/* misc.c */
void startd_close(int);
void startd_fclose(FILE *);
int fmri_canonify(const char *, char **, boolean_t);
int fs_is_read_only(char *, ulong_t *);
int fs_remount(char *);
void xstr_sanitize(char *);
/* restarter.c */
void restarter_init(void);
void restarter_start(void);
char *);
void restarter_mark_pending_snapshot(const char *, uint_t);
void *restarter_post_fsminimal_thread(void *);
void timeout_init(void);
int is_timeout_ovr(restarter_inst_t *);
/* startd.c */
void *safe_realloc(void *, size_t);
char *safe_strdup(const char *s);
void startd_free(void *, size_t);
uu_compare_fn_t *, uint32_t);
pthread_t startd_thread_create(void *(*)(void *), void *);
/* special.c */
void special_null_transition(void);
void special_online_hooks_get(const char *, instance_hook_t *,
instance_hook_t *, instance_hook_t *);
/* transition.c */
/* utmpx.c */
void utmpx_init(void);
void utmpx_clear_old(void);
int utmpx_mark_init(pid_t, char *);
char utmpx_get_runlevel(void);
void utmpx_set_runlevel(char, char, boolean_t);
void utmpx_write_boottime(void);
/* wait.c */
void wait_init(void);
void wait_prefork(void);
void wait_postfork(pid_t);
int wait_register(pid_t, const char *, int, int);
void *wait_thread(void *);
/* proc.c */
#ifdef __cplusplus
}
#endif
#endif /* _STARTD_H */