librestart.h revision 870ad75a2b67a92c3449d93b4fef8a0baa982b4a
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * CDDL HEADER START
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * The contents of this file are subject to the terms of the
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Common Development and Distribution License (the "License").
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * You may not use this file except in compliance with the License.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * See the License for the specific language governing permissions
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * and limitations under the License.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * When distributing Covered Code, include this CDDL HEADER in each
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * If applicable, add the following below this CDDL HEADER, with the
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * fields enclosed by brackets "[]" replaced with your own identifying
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * information: Portions Copyright [yyyy] [name of copyright owner]
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * CDDL HEADER END
07925104db56e5c3eacc4865b918bd16af5cec59gww * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Use is subject to license terms.
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern "C" {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * There are 3 parts to librestart.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * 1) The event protocol from the master restarter to its delegates.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * 2) A functional interface for updating the repository.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * 3) Convenience functions for common restarter tasks.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Event protocol
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * We need a reliable event protocol, as there's no way to define
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * restarter events as idempotent.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Currently using sysevent channels as the reliable event implementation.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * This could change if the implementation proves unsuitable, but
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * the API defined here should abstract anything but a change in
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * the fundamental event model.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * We offer functions to tease apart the event rather than generic
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * nvpair interfaces. This is because each event type has a well-
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * defined set of fields.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Some of the functions have external contracted consumers, review contracts
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * when making incompatible changes.
cb5caa98562cf06753163f558cbcfe30b8f4673adjltypedef struct restarter_event_handle restarter_event_handle_t;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Define an event protocol version. In theory, we could use this in
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * the future to support delegated restarters which use an older
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * protocol. In practice, increment RESTARTER_EVENT_VERSION whenever the
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * protocol might have changed.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Event types
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * RESTARTER_EVENT_TYPE_ADD_INSTANCE
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * responsible for a new (stopped) instance
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * RESTARTER_EVENT_TYPE_REMOVE_INSTANCE
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * no longer responsible for this instance; stop it and return
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * RESTARTER_EVENT_TYPE_ENABLE
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * no guarantee that dependencies are met; see
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * RESTARTER_EVENT_TYPE_START
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * RESTARTER_EVENT_TYPE_DISABLE
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * no guarantee that instance was running
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * RESTARTER_EVENT_TYPE_ADMIN_DEGRADED
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * RESTARTER_EVENT_TYPE_ADMIN_REFRESH
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * RESTARTER_EVENT_TYPE_ADMIN_RESTART
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * RESTARTER_EVENT_TYPE_ADMIN_MAINT_OFF
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * RESTARTER_EVENT_TYPE_ADMIN_MAINT_ON
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * RESTARTER_EVENT_TYPE_ADMIN_MAINT_ON_IMMEDIATE
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * RESTARTER_EVENT_TYPE_ADMIN_MAINT_OFF
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * RESTARTER_EVENT_TYPE_STOP
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * dependencies are, or are becoming, unsatisfied
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * RESTARTER_EVENT_TYPE_START
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * dependencies have become satisfied
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * RESTARTER_EVENT_TYPE_DEPENDENCY_CYCLE
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * instance caused a dependency cycle
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * RESTARTER_EVENT_TYPE_INVALID_DEPENDENCY
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * instance has an invalid dependency
cb5caa98562cf06753163f558cbcfe30b8f4673adjltypedef enum {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * These values are ordered by severity of required restart, as we use
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * integer comparisons to determine error flow.
cb5caa98562cf06753163f558cbcfe30b8f4673adjltypedef enum {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * restarter_store_contract() and restarter_remove_contract() types
cb5caa98562cf06753163f558cbcfe30b8f4673adjltypedef enum {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * restarter_bind_handle() registers a delegate with svc.startd to
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * begin consuming events.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * On initial bind, the delgated restarter receives an event for each
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * instance it is responsible for, as if that instance was new.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * callers must have superuser privileges
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * The event handler can return 0 for success, or EAGAIN to request
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * retry of event delivery. EAGAIN may be returned 3 times before the
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * event is discarded.
cb5caa98562cf06753163f558cbcfe30b8f4673adjlrestarter_event_type_t restarter_event_get_type(restarter_event_t *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlvoid restarter_event_get_time(restarter_event_t *, hrtime_t *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlssize_t restarter_event_get_instance(restarter_event_t *, char *, size_t);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlrestarter_event_handle_t *restarter_event_get_handle(restarter_event_t *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * The following functions work only on certain types of events.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * They fail with a return of -1 if they're called on an inappropriate event.
cb5caa98562cf06753163f558cbcfe30b8f4673adjlint restarter_event_get_current_states(restarter_event_t *,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl restarter_instance_state_t *, restarter_instance_state_t *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Functions for updating the repository.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * When setting state to "maintenance", callers of restarter_set_states() can
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * set aux_state to "service_request" to communicate that another service has
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * requested maintenance state for the target service.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Callers should use restarter_inst_validate_aux_fmri() to validate the fmri
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * of the requested service and pass "service_request" for aux_state when
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * calling restarter_set_states(). See inetd and startd for examples.
cb5caa98562cf06753163f558cbcfe30b8f4673adjlint restarter_set_states(restarter_event_handle_t *, const char *,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl restarter_instance_state_t, restarter_instance_state_t, restarter_error_t,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl const char *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlint restarter_event_publish_retry(evchan_t *, const char *, const char *,
cb5caa98562cf06753163f558cbcfe30b8f4673adjlssize_t restarter_state_to_string(restarter_instance_state_t, char *, size_t);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlrestarter_instance_state_t restarter_string_to_state(char *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl /* Stable */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl /* Private */
typedef struct mc_error {
} mc_error_t;
int restarter_rm_libs_loadable(void);
int restarter_is_null_method(const char *);
int restarter_is_kill_method(const char *);
int restarter_is_kill_proc_method(const char *);
/* Validate the inst fmri specified in restarter_actions/auxiliary_fmri */
/* Delete instance's restarter_actions/auxiliary_fmri property */
/* Get boolean value from instance's restarter_actions/auxiliary_tty */
/* Delete instance's restarter/auxiliary_fmri property */
* Set instance's restarter/auxiliary_fmri, value come from
#ifdef __cplusplus