inetd_impl.h revision eed64e98ce34ec2844d4c68b7e5af30cf962e9c8
/*
* 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 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _INETD_IMPL_H
#define _INETD_IMPL_H
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* function declarations.
*/
#ifdef __cplusplus
extern "C" {
#endif
#include <stdarg.h>
#include <assert.h>
#include <libscf.h>
#include <libinetutil.h>
#include <inetsvc.h>
#include <librestart.h>
#include <libuutil.h>
#include <wordexp.h>
/*
* Number of consecutive retries of a repository operation that failed due
* to a broken connection performed before giving up and failing.
*/
#define REP_OP_RETRIES 10
/* retryable SMF method error */
#define SMF_EXIT_ERR_OTHER 1
/* inetd's syslog ident string */
#define SYSLOG_IDENT "inetd"
/* Is this instance currently executing a method ? */
/* Names of properties that inetd uses to store instance state. */
#define PR_NAME_NON_START_PID "non_start_pid"
#define PR_NAME_START_PIDS "start_pids"
#define PR_NAME_CUR_INT_STATE "cur_state"
#define PR_NAME_NEXT_INT_STATE "next_state"
/* Name of the property group that holds debug flag */
#define PG_NAME_APPLICATION_CONFIG "config"
/* Name of the property which holds the debug flag value */
#define PR_NAME_DEBUG_FLAG "debug"
/*
* Instance states used internal to svc.inetd.
* ordering of this enumeration, so take care if modifying it.
*/
typedef enum {
/*
* inetd's instance methods.
* ordering of this enumeration, so take care if modifying it.
*/
typedef enum {
/* Collection of information pertaining to a method */
typedef struct {
char *exec_path; /* path passed to exec() */
/*
* Structure returned from wordexp(3c) that contains an expansion of the
* exec property into a form suitable for exec(2).
*/
/*
* Copy of the first argument of the above wordexp_t structure in the
* event that an alternate arg0 is provided, and we replace the first
* argument with the alternate arg0. This is necessary so the
* contents of the wordexp_t structure can be returned to their
* original form as returned from wordexp(3c), which is a requirement
* for calling wordfree(3c), wordexp()'s associated cleanup routine.
*/
const char *wordexp_arg0_backup;
/* time a method can run for before being considered broken */
int timeout;
typedef struct {
/*
* Structure used to construct a list of int64_t's and their associated
* scf values. Used to store lists of process ids, internal states, and to
* store the associated scf value used when writing the values back to the
* repository.
*/
typedef struct {
} rep_val_t;
/* Structure containing the state and configuration of a service instance. */
typedef struct {
char *fmri;
/* fd we're going to take a connection on */
int conn_fd;
/* number of copies of this instance active */
/* connection rate counters */
/* failure rate counters */
/* bind failure count */
/* pids of currently running methods */
/* ctids of currently running start methods */
/* remote address, used for TCP tracing */
struct sockaddr_storage remote_addr;
/* repository compatible versions of the above 2 states */
/*
* Current instance configuration resulting from its repository
* configuration.
*/
/*
* Soon to be applied instance configuration. This configuration was
* read during a refresh when this instance was online, and the
* instance needed taking offline for this configuration to be applied.
* The instance is currently on its way offline, and this configuration
* will become the current configuration when it arrives there.
*/
/* current pending conrate-offline/method timer; -1 if none pending */
/* current pending bind retry timer; -1 if none pending */
/*
* Flags that assist in the fanout of an instance arriving in the
* offline state on-route to some other state.
*/
/*
* Event waiting to be processed. RESTARTER_EVENT_TYPE_INVALID is used
* to mean no event waiting.
*/
/* link to next instance in list */
} instance_t;
/* Structure used to store information pertaining to instance method types. */
typedef struct {
const char *name;
extern uu_list_t *instance_list;
extern nfds_t num_pollfds;
extern method_type_info_t methods[];
extern iu_tq_t *timer_queue;
extern uu_list_pool_t *conn_ind_pool;
extern boolean_t debug_enabled;
/*
* util.c
*/
extern void msg_init(void);
extern void msg_fini(void);
/* PRINTFLIKE1 */
extern void debug_msg(const char *, ...);
/* PRINTFLIKE1 */
extern void error_msg(const char *, ...);
/* PRINTFLIKE1 */
extern void warn_msg(const char *, ...);
extern void poll_fini(void);
extern boolean_t isset_pollfd(int);
extern void clear_pollfd(int);
extern int set_pollfd(int, uint16_t);
extern struct pollfd *find_pollfd(int);
extern void cancel_inst_timer(instance_t *);
extern void cancel_bind_timer(instance_t *);
extern void enable_blocking(int);
extern void disable_blocking(int);
/*
* tlx.c
*/
extern rpc_info_t *create_rpc_info(const char *, const char *, const char *,
int, int);
extern void destroy_rpc_info(rpc_info_t *);
extern int register_rpc_service(const char *, const rpc_info_t *);
extern void unregister_rpc_service(const char *, const rpc_info_t *);
extern void close_net_fd(instance_t *, int);
extern void tlx_fini(void);
extern int tlx_init(void);
extern void consume_wait_data(instance_t *, int);
/*
* config.c
*/
extern int config_init(void);
extern void config_fini(void);
const method_info_t *);
extern struct method_context *read_method_context(const char *, const char *,
const char *, const char **);
extern void destroy_instance_cfg(instance_cfg_t *);
extern instance_cfg_t *read_instance_cfg(const char *);
extern int read_enable_merged(const char *, boolean_t *);
extern void refresh_debug_flag(void);
/*
* repval.c
*/
extern void repval_fini(void);
extern int repval_init(void);
extern uu_list_t *create_rep_val_list(void);
extern void destroy_rep_val_list(uu_list_t *);
extern void empty_rep_val_list(uu_list_t *);
extern int make_handle_bound(scf_handle_t *);
extern int iterate_repository_contracts(instance_t *, int);
/*
*/
extern int contract_init(void);
extern void contract_fini(void);
void contract_postfork(void);
int contract_prefork(const char *, int);
extern int adopt_contract(ctid_t, const char *);
extern int abandon_contract(ctid_t);
/*
* inetd.c
*/
extern void process_offline_inst(instance_t *);
extern void process_non_start_term(instance_t *, int);
extern void process_start_term(instance_t *);
/*
* env.c
*/
/*
* wait.c
*/
extern int method_init(void);
extern void method_fini(void);
extern void process_terminated_methods(void);
extern void unregister_instance_methods(const instance_t *);
extern void method_preexec(void);
#ifdef __cplusplus
}
#endif
#endif /* _INETD_IMPL_H */