CR 7121230 Rad unix transport paths should be created under /system/volatile/rad/
/*
* 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
* or http://www.opensolaris.org/os/licensing.
* 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 (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
*/
#ifndef _RAD_MODAPI_H
#define _RAD_MODAPI_H
#include <pthread.h>
#include <paths.h>
#include <rad/adr.h>
#include <rad/adr_name.h>
#include <rad/adr_object.h>
#ifdef __cplusplus
extern "C" {
#endif
#define RAD_COUNT(x) (sizeof (x) / sizeof (x[0]))
/*
* Container errors
*/
typedef enum conerr {
ce_ok = 0, /* success */
ce_object = 1, /* object-specific error (w/ payload) */
ce_nomem = 2, /* out of memory */
ce_notfound = 3, /* object not found */
ce_priv = 4, /* insufficient privileges */
ce_system = 5, /* system error */
ce_exists = 6, /* object already exists */
ce_mismatch = 7, /* invoke/setattr datatype mismatch */
ce_illegal = 8, /* illegal access (e.g. write to read-only) */
} conerr_t;
#define CE_LAST ce_illegal
/*
* Module errors
*/
typedef enum rad_moderr {
rm_ok,
rm_system,
rm_config
} rad_moderr_t;
/*
* Module registration
*/
#define RAD_MODVERSION_P1 -1
#define RAD_MODVERSION RAD_MODVERSION_P1
typedef struct rad_modinfo {
const char *mi_name; /* Name of module */
const char *mi_desc; /* Description of module */
} rad_modinfo_t;
extern int _rad_init(void *);
extern int rad_module_register(void *, int, rad_modinfo_t *);
/*
* Object implementation definitions
*/
typedef struct rad_container rad_container_t; /* An object namespace */
typedef struct rad_object rad_object_t; /* An implementation of an API */
typedef struct rad_instance rad_instance_t; /* An instance of an API impl. */
typedef conerr_t (attr_write_f)(rad_instance_t *, adr_attribute_t *,
data_t *, data_t **);
typedef conerr_t (attr_read_f)(rad_instance_t *, adr_attribute_t *,
data_t **, data_t **);
typedef conerr_t (meth_invoke_f)(rad_instance_t *, adr_method_t *, data_t **,
data_t **, int, data_t **);
typedef conerr_t (*attr_write_t)(rad_instance_t *, adr_attribute_t *,
data_t *, data_t **);
typedef conerr_t (*attr_read_t)(rad_instance_t *, adr_attribute_t *,
data_t **, data_t **);
typedef conerr_t (*meth_invoke_t)(rad_instance_t *, adr_method_t *, data_t **,
data_t **, int, data_t **);
struct rad_object {
adr_object_t *so_object;
meth_invoke_t *so_invoke;
attr_write_t *so_write;
attr_read_t *so_read;
};
/*
* Dynamic namespace management
*/
typedef conerr_t (*rad_dyn_list_t)(adr_name_t *, data_t **, void *arg);
typedef conerr_t (*rad_dyn_lookup_t)(adr_name_t **, rad_instance_t **,
void *arg);
/*
* Container routines
*/
#define INST_ID_PICK (-1)
rad_instance_t *instance_create(adr_name_t *, rad_object_t *, void *,
void (*)(void *));
rad_instance_t *instance_hold(rad_instance_t *);
void instance_rele(rad_instance_t *);
data_t *instance_getname(rad_instance_t *);
void *instance_getdata(rad_instance_t *);
void instance_notify(rad_instance_t *, const char *, long, data_t *);
conerr_t cont_insert(rad_container_t *, rad_instance_t *, long long);
conerr_t cont_insert_singleton(rad_container_t *, adr_name_t *, rad_object_t *);
conerr_t cont_insert_singleton_id(rad_container_t *, adr_name_t *,
rad_object_t *, long long);
void cont_remove(rad_container_t *, rad_instance_t *);
conerr_t cont_register_dynamic(rad_container_t *, adr_name_t *, rad_dyn_list_t,
rad_dyn_lookup_t, void *);
/*
* Logging routines
*/
typedef enum {
RL_ALL,
RL_DEBUG, /* Debugging messages */
RL_NOTE, /* Important notes */
RL_WARN, /* Things that are amiss */
RL_ERROR, /* Things that are wrong */
RL_CONFIG, /* Fatal configuration errors (exits) */
RL_FATAL, /* Fatal system errors (exits) */
RL_PANIC /* Internal inconsistency (aborts) */
} rad_logtype_t;
void rad_log(rad_logtype_t, const char *, ...);
void rad_log_alloc(void);
rad_logtype_t rad_get_loglevel(void);
/*
* Threading routines
*/
typedef struct rad_thread rad_thread_t;
typedef rad_moderr_t (*rad_threadfp_t)(rad_thread_t *);
typedef void (*rad_thread_asyncfp_t)(void *);
void *rad_thread_arg(rad_thread_t *);
void rad_thread_ack(rad_thread_t *, rad_moderr_t);
rad_moderr_t rad_thread_create(rad_threadfp_t, void *);
rad_moderr_t rad_thread_create_async(rad_thread_asyncfp_t, void *);
void rad_mutex_init(pthread_mutex_t *);
void rad_mutex_enter(pthread_mutex_t *);
void rad_mutex_exit(pthread_mutex_t *);
void rad_cond_init(pthread_cond_t *);
/*
* Exec routines
*/
/* Leave in/out/err unperturbed */
#define FD_LOG -1
/* Create a pipe to the child process */
#define FD_PIPE -2
/* Redirect from/to /dev/null */
#define FD_DEVNULL -3
typedef struct exec_params exec_params_t;
typedef struct exec_result {
pid_t pid; /* PID of child */
int fd_stdin; /* fd to child's side of pipe if FD_PIPE, or -1 */
int fd_stdout; /* fd to child's side of pipe if FD_PIPE, or -1 */
int fd_stderr; /* fd to child's side of pipe if FD_PIPE, or -1 */
} exec_result_t;
exec_params_t *rad_exec_params_alloc(void);
void rad_exec_params_free(exec_params_t *params);
void rad_exec_params_set_cwd(exec_params_t *params, const char *cwd);
void rad_exec_params_set_env(exec_params_t *params, const char **envp);
void rad_exec_params_set_loglevel(exec_params_t *params,
rad_logtype_t loglevel);
int rad_exec_params_set_stdin(exec_params_t *params, int fd);
int rad_exec_params_set_stdout(exec_params_t *params, int fd);
int rad_exec_params_set_stderr(exec_params_t *params, int fd);
int rad_forkexec(exec_params_t *params, const char **argv,
exec_result_t *result);
int rad_forkexec_wait(exec_params_t *params, const char **argv, int *status);
int rad_wait(exec_params_t *params, exec_result_t *result, int *status);
/*
* Locale routines
*/
typedef struct rad_locale {
char *locale;
char *language;
char *territory;
char *codeset;
char *modifier;
} rad_locale_t;
void rad_locale_free(rad_locale_t *locale);
char *rad_locale_get(void);
int rad_locale_parse(const char *locale, rad_locale_t **p);
/*
* Utility routines
*/
void *rad_zalloc(size_t);
char *rad_strndup(char *, size_t);
int rad_strccmp(const char *, const char *, size_t);
int rad_openf(const char *, int, mode_t, ...);
FILE *rad_fopenf(const char *, const char *, ...);
/*
* /usr/lib/rad/rad-specific data
*/
#define INST_ID_PROXY (1LL<<62)
#define TYPE_ID_PROXY INST_ID_PROXY
extern boolean_t rad_isproxy;
extern rad_container_t *rad_container;
/*
* Directory for temporary rad files
*/
#define RAD_TMPDIR _PATH_SYSVOL "/rad"
/*
* Default path for AF_UNIX sockets
*/
#define RAD_PATH_AFUNIX_AUTH RAD_TMPDIR "/radsocket"
#define RAD_PATH_AFUNIX_UNAUTH RAD_TMPDIR "/radsocket-unauth"
#ifdef __cplusplus
}
#endif
#endif /* _RAD_MODAPI_H */