2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A
2N/A
2N/A#ifndef _INSTZONES_LIB_H
2N/A#define _INSTZONES_LIB_H
2N/A
2N/A
2N/A/*
2N/A * Module: instzones_lib.h
2N/A * Group: libinstzones
2N/A * Description: This module contains the libinstzones internal data structures,
2N/A * constants, and function prototypes. This include should not be
2N/A * needed by any external code (consumers of this library).
2N/A */
2N/A
2N/A/*
2N/A * required includes
2N/A */
2N/A
2N/A/* System includes */
2N/A
2N/A#include <zone.h>
2N/A#include <libzonecfg.h>
2N/A#include <libcontract.h>
2N/A#include <instzones_api.h>
2N/A
2N/A
2N/A
2N/A/*
2N/A * C++ prefix
2N/A */
2N/A
2N/A#ifdef __cplusplus
2N/Aextern "C" {
2N/A#endif
2N/A
2N/A/* constants */
2N/A
2N/A
2N/A/* macros */
2N/A
2N/A/*
2N/A * argument array processing type
2N/A */
2N/A
2N/A/*
2N/A * This is the "argument array" definition that is returned by _z_new_args
2N/A * and is used by _z_add_args, _z_free_args, etc.
2N/A */
2N/A
2N/Astruct _argArray_t {
2N/A long _aaNumArgs; /* number of arguments set */
2N/A long _aaMaxArgs; /* number of arguments allocated */
2N/A char **_aaArgs; /* actual arguments */
2N/A};
2N/A
2N/Atypedef struct _argArray_t argArray_t;
2N/A
2N/A/*
2N/A * lock objects
2N/A */
2N/A
2N/A/*
2N/A * this allows a root path to be prepended to a lock object; e.g.
2N/A * rootpath.%s/zone.%s/...
2N/A */
2N/A#define LOBJ_ROOTPATH "rootpath.%s"
2N/A
2N/A/* this locks all zones */
2N/A#define LOBJ_ZONEADMIN "zone.*"
2N/A
2N/A/* this locks all packages, in all zones */
2N/A#define LOBJ_PKGADMIN "zone.*/package.*"
2N/A
2N/A/* this locks all patches, in all zones */
2N/A#define LOBJ_PATCHADMIN "zone.*/patch.*"
2N/A
2N/A#define LOCK_OBJECT_MAXLEN 512
2N/A#define LOCK_KEY_MAXLEN 37
2N/A
2N/A/* paths to commands executed by this module */
2N/A
2N/A#define PKGADM_CMD "/usr/bin/pkgadm"
2N/A
2N/A/* max message size for program output functions (echo, echo debug, progerr) */
2N/A
2N/A#define MAX_MESSAGE_SIZE 4096
2N/A
2N/A/* maximum number of retries when waiting for lock */
2N/A
2N/A#define MAX_RETRIES 300
2N/A
2N/A/* delay (in seconds) between retries when waiting for lock */
2N/A
2N/A#define RETRY_DELAY_SECS 1
2N/A
2N/A/* Size of buffer increments when reading from pipe */
2N/A
2N/A#define PIPE_BUFFER_INCREMENT 256
2N/A
2N/A/*
2N/A * These dynamic libraries are required in order to use the zones
2N/A * functionality - if these libraries are not available at runtime,
2N/A * then zones are assumed to NOT be available, and it is assumed that
2N/A * the program is running in the global zone with no non-global zones.
2N/A */
2N/A
2N/A#if defined(LIBZONECFG_PATH)
2N/A#define ZONECFG1_LIBRARY LIBZONECFG_PATH
2N/A#else /* defined(LIBZONECFG_PATH) */
2N/A#define ZONECFG1_LIBRARY "libzonecfg.so.1"
2N/A#endif /* defined(LIBZONECFG_PATH) */
2N/A
2N/A#define ZONECFG_LIBRARY "libzonecfg.so"
2N/A
2N/A#define CONTRACT1_LIBRARY "libcontract.so.1"
2N/A#define CONTRACT_LIBRARY "libcontract.so"
2N/A
2N/A/*
2N/A * Environment values used when running commands within a non-global zone
2N/A */
2N/A
2N/A/* SHELL= */
2N/A
2N/A#define ZONE_FAILSAFESHELL "/usr/sbin/sh"
2N/A
2N/A/* PATH= */
2N/A
2N/A#define ZONE_DEF_PATH "/usr/sbin:/usr/bin"
2N/A
2N/A/* error codes */
2N/A#define ERR_MALLOC_FAIL -50
2N/A
2N/A/*
2N/A * zone brand list structure
2N/A */
2N/A
2N/Astruct _zoneBrandList {
2N/A char *string_ptr;
2N/A struct _zoneBrandList *next;
2N/A};
2N/A
2N/A/*
2N/A * zone status structure - used to retrieve and hold status of zones
2N/A */
2N/A
2N/Astruct _zoneListElement_t {
2N/A char *_zlName;
2N/A char *_zlPath;
2N/A char *_zlScratchName;
2N/A zone_state_t _zlState;
2N/A};
2N/A
2N/Atypedef struct _zoneListElement_t zoneListElement_t;
2N/A
2N/A/*
2N/A * User-specified list of zones.
2N/A */
2N/A
2N/Atypedef struct zone_spec_s {
2N/A struct zone_spec_s *zl_next;
2N/A boolean_t zl_used;
2N/A char zl_name[ZONENAME_MAX];
2N/A} zone_spec_t;
2N/A
2N/A/*
2N/A * The global data structure used to hold all of the global (extern) data
2N/A * used by this library.
2N/A *
2N/A * --> THESE DEFINITIONS ARE ORDER DEPENDENT BASED <--
2N/A * --> ON THE ORDER OF THE STRUCTURE INITIALIZERS! <--
2N/A */
2N/A
2N/Astruct _z_global_data_t {
2N/A char *_z_ObjectLocks; /* object locks held */
2N/A char *_z_root_dir; /* root for zone lib fctns */
2N/A int _z_SigReceived; /* received signal count */
2N/A pid_t _z_ChildProcessId; /* child to propagate sigs to */
2N/A zone_spec_t *_zone_spec; /* zones to operate on */
2N/A _z_printf_fcn_t _z_echo; /* operational message fcn */
2N/A _z_printf_fcn_t _z_echo_debug; /* debug message fcn */
2N/A _z_printf_fcn_t _z_progerr; /* program error fcn */
2N/A};
2N/A
2N/Atypedef struct _z_global_data_t z_global_data_t;
2N/A
2N/A/*
2N/A * When _INSTZONES_LIB_Z_DEFINE_GLOBAL_DATA is defined,
2N/A * instzones_lib.h will define the z_global_data structure.
2N/A * Otherwise an extern to the structure is inserted.
2N/A *
2N/A * --> THESE DEFINITIONS ARE ORDER DEPENDENT BASED ON <--
2N/A * --> THE ORDER OF THE _z_global_data_t STRUCTURE!!! <--
2N/A */
2N/A
2N/A#if defined(_INSTZONES_LIB_Z_DEFINE_GLOBAL_DATA)
2N/A
2N/A/* define and initialize structure */
2N/A
2N/Az_global_data_t _z_global_data = {
2N/A NULL, /* *_z_ObjectLocks */
2N/A "", /* *_z_root_dir */
2N/A 0, /* _z_SigReceived */
2N/A -1, /* _z_ChildProcessId */
2N/A NULL, /* *_zone_spec */
2N/A NULL, /* _z_echo */
2N/A NULL, /* _z_echo_debug */
2N/A NULL /* _z_progerr */
2N/A};
2N/A
2N/A#else /* !defined(_INSTZONES_LIB__Z_DEFINE_GLOBAL_DATA) */
2N/A
2N/A/* define structure extern */
2N/A
2N/Aextern z_global_data_t _z_global_data;
2N/A
2N/A#endif /* defined(_INSTZONES_LIB_Z_DEFINE_GLOBAL_DATA) */
2N/A
2N/A/* function prototypes */
2N/A
2N/A/*
2N/A * The following functions can be used by other libs, but not
2N/A * by applications.
2N/A */
2N/A
2N/Avoid *_z_calloc(size_t size);
2N/Avoid *_z_malloc(size_t size);
2N/Avoid *_z_realloc(void *ptr, size_t size);
2N/Avoid *_z_strdup(char *str);
2N/A
2N/A/* ---> zones_utils.c */
2N/A
2N/A/*PRINTFLIKE1*/
2N/Avoid _z_program_error(char *fmt, ...);
2N/A/*PRINTFLIKE1*/
2N/Avoid _z_echo(char *fmt, ...);
2N/A/*PRINTFLIKE1*/
2N/Avoid _z_echoDebug(char *a_fmt, ...);
2N/Aint _z_is_directory(char *path);
2N/Aboolean_t _z_running_in_global_zone(void);
2N/Aboolean_t _z_zones_are_implemented(void);
2N/Avoid _z_sig_trap(int a_signo);
2N/Aint _z_close_file_descriptors(void *a_fds, int a_fd);
2N/Aboolean_t _z_brands_are_implemented(void);
2N/A
2N/A
2N/A/* ---> zones_locks.c */
2N/A
2N/Aboolean_t _z_adjust_lock_object_for_rootpath(char **r_result,
2N/A char *a_lockObject);
2N/Aboolean_t _z_acquire_lock(char **r_lockKey, char *a_zoneName,
2N/A char *a_lock, pid_t a_pid, boolean_t a_wait);
2N/Aboolean_t _z_lock_zone_object(char **r_objectLocks,
2N/A char *a_zoneName, char *a_lockObject,
2N/A pid_t a_pid, char *a_waitingMsg,
2N/A char *a_busyMsg);
2N/Aboolean_t _z_release_lock(char *a_zoneName, char *a_lock,
2N/A char *a_key, boolean_t a_wait);
2N/Aboolean_t _z_unlock_zone(zoneListElement_t *a_zlst,
2N/A ZLOCKS_T a_lflags);
2N/Aboolean_t _z_unlock_zone_object(char **r_objectLocks,
2N/A char *a_zoneName, char *a_lockObject,
2N/A char *a_errMsg);
2N/A
2N/A/* ---> zones_args.c */
2N/A
2N/Avoid _z_free_args(argArray_t *a_args);
2N/AargArray_t *_z_new_args(int initialCount);
2N/A/*PRINTFLIKE2*/
2N/Aboolean_t _z_add_arg(argArray_t *a_args, char *a_format, ...);
2N/Achar **_z_get_argv(argArray_t *a_args);
2N/A
2N/A/* ---> zones_str.c */
2N/A
2N/Aboolean_t _z_strContainsToken(char *a_string, char *a_token,
2N/A char *a_separators);
2N/Achar *_z_strGetToken(char *r_sep, char *a_string,
2N/A int a_index, char *a_separators);
2N/Avoid _z_strRemoveLeadingWhitespace(char **a_str);
2N/Avoid _z_strGetToken_r(char *r_sep, char *a_string,
2N/A int a_index, char *a_separators, char *a_buf,
2N/A int a_bufLen);
2N/Avoid _z_strAddToken(char **a_old, char *a_new,
2N/A char a_separator);
2N/Avoid _z_strRemoveToken(char **r_string, char *a_token,
2N/A char *a_separators, int a_index);
2N/A/*PRINTFLIKE3*/
2N/Avoid _z_strPrintf_r(char *a_buf, int a_bufLen,
2N/A char *a_format, ...);
2N/A/*PRINTFLIKE1*/
2N/Achar *_z_strPrintf(char *a_format, ...);
2N/A
2N/A/* ---> zones_exec.c */
2N/A
2N/Aint _z_zone_exec(int *r_status, char **r_results, char *a_inputFile,
2N/A char *a_path, char *a_argv[], const char *a_zoneName,
2N/A int *a_fds);
2N/Aint _zexec(const char *a_zoneName,
2N/A const char *path, char *argv[]);
2N/Achar *_zexec_add_env(char *name, char *value);
2N/Aint _zexec_init_template(void);
2N/Achar **_zexec_prep_env();
2N/A
2N/A/*
2N/A * C++ postfix
2N/A */
2N/A
2N/A#ifdef __cplusplus
2N/A}
2N/A#endif
2N/A
2N/A#endif /* _INSTZONES_LIB_H */