/*
* 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
*/
/*
*/
/*
* Module: zones.c
* Group: libinstzones
* Description: Provide "zones" interface for install consolidation code
*
* Public Methods:
* z_create_zone_admin_file - Given a location to create the file, and
* optionally an existing administration file, generate an
* administration file that can be used to perform "non-interactive"
* operations in a non-global zone.
* z_free_zone_list - free contents of zoneList_t object
* z_get_nonglobal_zone_list - return zoneList_t object describing all
* non-global native zones
* z_get_nonglobal_zone_list_by_brand - return zoneList_t object describing
* all non-global zones matching the list of zone brands passed in.
* z_free_brand_list - free contents of a zoneBrandList_t object
* z_make_brand_list - return a zoneBrandList_t object describing the list
* of all zone brands passed in.
* z_get_zonename - return the name of the current zone
* z_global_only - Determine if the global zone is only zone on the spec list
* z_lock_this_zone - lock this zone
* z_lock_zones - lock specified zones
* z_mount_in_lz - Mount global zone directory in specified zone's root file
* system
* z_non_global_zones_exist - Determine if any non-global native zones exist
* z_on_zone_spec - Determine if named zone is on the zone_spec list
* z_running_in_global_zone - Determine if running in the "global" zone
* z_set_output_functions - Link program specific output functions
* z_set_zone_root - Set root for zones library operations
* z_set_zone_spec - Set list of zones on which actions will be performed
* z_umount_lz_mount - Unmount directory mounted with z_mount_in_lz
* z_unlock_this_zone - unlock this zone
* z_unlock_zones - unlock specified zones
* z_verify_zone_spec - Verify list of zones on which actions will be performed
* z_zlist_change_zone_state - Change the current state of the specified zone
* z_zlist_get_current_state - Determine the current kernel state of the
* specified zone
* z_zlist_get_original_state - Return the original kernal state of the
* specified zone
* z_zlist_get_scratch - Determine name of scratch zone
* z_zlist_get_zonename - Determine name of specified zone
* z_zlist_get_zonepath - Determine zonepath of specified zone
* z_zlist_restore_zone_state - Return the zone to the state it was originally
* in
* z_zone_exec - Execute a Unix command in a specified zone and return results
* z_zones_are_implemented - Determine if any zone operations can be performed
* z_is_zone_branded - determine if zone has a non-native brand
* z_is_zone_brand_in_list - determine if the zone's brand matches the
* brand list passed in.
* z_brands_are_implemented - determine if branded zones are implemented on
* this system
*/
/*
* System includes
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <ctype.h>
#include <sys/sysmacros.h>
#include <string.h>
#include <strings.h>
#include <stdarg.h>
#include <limits.h>
#include <errno.h>
#include <time.h>
#include <signal.h>
#include <stropts.h>
#include <wait.h>
#include <zone.h>
#include <libintl.h>
#include <locale.h>
#include <libzonecfg.h>
#include <libcontract.h>
#include <assert.h>
#include <dlfcn.h>
#include <link.h>
#include <time.h>
/*
* local includes
*/
/*
* When _INSTZONES_LIB_Z_DEFINE_GLOBAL_DATA is defined,
* instzones_lib.h will define the z_global_data structure.
* Otherwise an extern to the structure is inserted.
*/
#include "instzones_lib.h"
#include "zones_strings.h"
/*
* Private structures
*/
/* maximum number of arguments to exec() call */
/*
* Library Function Prototypes
*/
/*
* Local Function Prototypes
*/
/*
* global internal (private) declarations
*/
/*
* *****************************************************************************
* global external (public) functions
* *****************************************************************************
*/
/*
* Name: z_create_zone_admin_file
* Description: Given a location to create the file, and optionally an existing
* administration file, generate an administration file that
* can be used to perform "non-interactive" operations in a
* non-global zone.
* Arguments: a_zoneAdminFilename - pointer to string representing the
* full path of zone admin file to create
* a_userAdminFilename - pointer to string representing the path
* to an existing "user" administration file - the
* administration file created will contain the
* settings contained in this file, modified as
* appropriate to supress any interaction;
* If this is == NULL then the administration file
* created will not contain any extra settings
* Returns: boolean_t
* == B_TRUE - admin file created
* == B_FALSE - failed to create admin file
*/
{
/* entry assertions */
/* create temporary zone admin file */
return (B_FALSE);
}
/* open user admin file if specified */
if (a_userAdminFilename != (char *)NULL) {
}
/* create default admin file for zone pkg ops if no user admin file */
/* create default admin file */
"basedir=default\nconflict=nocheck\nidepend=nocheck\n"
"instance=unique\npartial=nocheck\nrdepend=nocheck\n"
"runlevel=nocheck\nsetuid=nocheck\nspace=nocheck\n"
"mail=\n");
} else for (;;) {
/* copy user admin file substitute/change appropriate entries */
char *p;
/* read next line of user admin file */
if (p == (char *)NULL) {
break;
}
/* modify / replace / accept as appropriate */
/*LINTED*/
} else {
}
}
/* close admin file and return success */
return (B_TRUE);
}
/*
* Name: z_brands_are_implemented
* Description: Determine if any branded zones may be present
* Arguments: void
* Returns: boolean_t
* == B_TRUE - branded zones are supported
* == B_FALSE - branded zones are not supported
*/
z_brands_are_implemented(void)
{
/* if availability has not been determined, cache it now */
if (!_brandsImplementedDetermined) {
if (_brandsAreImplemented) {
} else {
}
}
/* return cached answer */
return (_brandsAreImplemented);
}
/*
* Name: z_free_zone_list
* Description: free contents of zoneList_t object
* Arguments: a_zlst - handle to zoneList_t object to free
* Returns: void
*/
void
{
int numzones;
/* ignore empty list */
return;
}
/* free each entry in the zone list */
numzones++) {
/* free zone name string */
/* free zonepath string */
}
}
/* free handle to the list */
}
/*
* Name: z_get_nonglobal_zone_list
* Description: return zoneList_t object describing all non-global
* native zones - branded zones are not included in list
* Arguments: None.
* Returns: zoneList_t
* == NULL - error, list could not be generated
* != NULL - success, list returned
* NOTE: Any zoneList_t returned is placed in new storage for the
* calling function. The caller must use 'z_free_zone_list' to
* dispose of the storage once the list is no longer needed.
*/
{
return (NULL);
return (zones);
}
/*
* Name: z_free_brand_list
* Description: Free contents of zoneBrandList_t object
* Arguments: brands - pointer to zoneBrandList_t object to free
* Returns: void
*/
void
{
}
}
/*
* Name: z_make_brand_list
* Description: Given a string with a list of brand name delimited by
* the delimeter passed in, build a zoneBrandList_t structure
* with the list of brand names and return it to the caller.
* Arguments:
* brands - const char pointer to string list of brand names
* delim - const char pointer to string representing the
* delimeter for brands string.
* Returns: zoneBrandList_t *
* == NULL - error, list could not be generated
* != NULL - success, list returned
* NOTE: Any zoneBrandList_t returned is placed in new storage for the
* calling function. The caller must use 'z_free_brand_list' to
* dispose of the storage once the list is no longer needed.
*/
{
return (NULL);
if ((brand = (zoneBrandList_t *)
return (NULL);
}
return (NULL);
}
}
}
return (head);
}
/*
* Name: z_get_nonglobal_zone_list_by_brand
* Description: return zoneList_t object describing all non-global
* zones matching the list of brands passed in.
* Arguments: brands - The list of zone brands to look for.
* Returns: zoneList_t
* == NULL - error, list could not be generated
* != NULL - success, list returned
* NOTE: Any zoneList_t returned is placed in new storage for the
* calling function. The caller must use 'z_free_zone_list' to
* dispose of the storage once the list is no longer needed.
*/
{
int numzones = 0;
/* if zones are not implemented, return empty list */
if (!z_zones_are_implemented()) {
return ((zoneList_t)NULL);
}
/*
* Open the zone index file. Note that getzoneent_private() handles
* NULL.
*/
zoneIndexFP = setzoneent();
/* index file open; scan all zones; see if any are at least installed */
/* skip the global zone */
continue;
}
/*
* skip any zones with brands not on the brand list
*/
continue;
}
/*
* If the user specified an explicit zone list, then ignore any
* zones that aren't on that list.
*/
break;
}
continue;
}
}
/* non-global zone: create entry for this zone */
if (numzones == 0) {
sizeof (zoneListElement_t)*2);
} else {
sizeof (zoneListElement_t)*2);
}
/*
* remember the zone name, zonepath and the current
* zone state of the zone.
*/
/* get the zone kernel status */
}
/*
* For a scratch zone, we need to know the kernel zone name.
*/
}
/*
* remember the current kernel status of the zone.
*/
numzones++;
}
/* close the index file */
/* return generated list */
return (zlst);
}
/*
* Name: z_get_zonename
* Description: return the name of the current zone
* Arguments: void
* Returns: char *
* - pointer to string representing the name of the current
* zone
* NOTE: Any string returned is placed in new storage for the
* calling function. The caller must use 'Free' to dispose
* of the storage once the string is no longer needed.
*/
char *
z_get_zonename(void)
{
/* if zones are not implemented, return "" */
if (!z_zones_are_implemented()) {
return (_z_strdup(""));
}
/* get the zone i.d. of the current zone */
/* get the name of the current zone */
/* return "" if could not get zonename */
if (zonenameLen < 1) {
return (_z_strdup(""));
}
}
/*
* Name: z_global_only
* Description: Determine if the global zone is only zone on the spec list.
* Arguments: None
* Returns: B_TRUE if global zone is the only zone on the list,
* B_FALSE otherwise.
*/
z_global_only(void)
{
/* return true if zones are not implemented - treate as global zone */
if (!z_zones_are_implemented()) {
return (B_TRUE);
}
/* return true if this is the global zone */
return (B_TRUE);
}
/* return false - not the global zone */
return (B_FALSE);
}
/*
* Name: z_lock_this_zone
* Description: lock this zone
* Arguments: a_lflags - [RO, *RO] - (ZLOCKS_T)
* Flags indicating which locks to acquire
* Returns: boolean_t
* == B_TRUE - success specified locks acquired
* == B_FALSE - failure specified locks not acquired
* NOTE: the lock objects for "this zone" are maintained internally.
*/
{
boolean_t b;
char *zoneName;
/* entry assertions */
/* entry debugging info */
zoneName = z_get_zonename();
/* lock zone administration */
if (a_lflags & ZLOCKS_ZONE_ADMIN) {
if (!b) {
return (B_FALSE);
}
}
/* lock package administration always */
if (a_lflags & ZLOCKS_PKG_ADMIN) {
if (!b) {
(void) z_unlock_this_zone(a_lflags);
return (B_FALSE);
}
}
return (B_TRUE);
}
/*
* Name: z_lock_zones
* Description: lock specified zones
* Arguments: a_zlst - zoneList_t object describing zones to lock
* a_lflags - [RO, *RO] - (ZLOCKS_T)
* Flags indicating which locks to acquire
* Returns: boolean_t
* == B_TRUE - success, zones locked
* == B_FALSE - failure, zones not locked
*/
{
boolean_t b;
int i;
/* entry assertions */
/* entry debugging info */
/* if zones are not implemented, return TRUE */
if (z_zones_are_implemented() == B_FALSE) {
return (B_TRUE);
}
/* lock this zone first before locking other zones */
b = z_lock_this_zone(a_lflags);
if (b == B_FALSE) {
return (b);
}
/* ignore empty list */
return (B_FALSE);
}
/* zones exist */
/*
* lock each listed zone that is currently running
*/
/* ignore zone if already locked */
continue;
}
/* ignore zone if not running */
continue;
}
/*
* mark zone locked - if interrupted out during lock, an attempt
* will be made to release the lock
*/
/* lock this zone */
/* on failure unlock all zones and return error */
if (b != B_TRUE) {
return (B_FALSE);
}
}
/* success */
return (B_TRUE);
}
/*
* Name: z_mount_in_lz
* Description: Mount global zone directory in specified zone's root file system
* Arguments: r_lzMountPoint - pointer to handle to string - on success, the
* full path to the mount point relative to the global zone
* root file system is returned here - this is needed to
* unmount the directory when it is no longer needed
* r_lzRootPath - pointer to handle to string - on success, the
* full path to the mount point relative to the specified
* zone's root file system is returned here - this is
* passed to any command executing in the specified zone to
* access the directory mounted
* a_zoneName - pointer to string representing the name of the zone
* to mount the specified global zone directory in
* a_gzPath - pointer to string representing the full absolute path
* of the global zone directory to LOFS mount inside of the
* specified non-global zone
* a_mountPointPrefix - pointer to string representing the prefix
* to be used when creating the mount point name in the
* specified zone's root directory
* Returns: boolean_t
* == B_TRUE - global zone directory mounted successfully
* == B_FALSE - failed to mount directory in specified zone
* NOTE: Any strings returned is placed in new storage for the
* calling function. The caller must use 'Free' to dispose
* of the storage once the strings are no longer needed.
*/
char *a_gzPath, char *a_mountPointPrefix)
{
int err;
int slen;
/* entry assertions */
/* entry debugging info */
/* reset returned non-global zone mount point path handle */
*r_lzMountPoint = (char *)NULL;
*r_lzRootPath = (char *)NULL;
/* if zones are not implemented, return FALSE */
if (z_zones_are_implemented() == B_FALSE) {
return (B_FALSE);
}
/* error if global zone path is not absolute */
if (*a_gzPath != '/') {
return (B_FALSE);
}
/* error if global zone path does not exist */
if (_z_is_directory(a_gzPath) != 0) {
return (B_FALSE);
}
/* verify that specified non-global zone exists */
return (B_FALSE);
}
/* obtain global zone path to non-global zones root file system */
return (B_FALSE);
}
if (lzRootPath[0] == '\0') {
return (B_FALSE);
}
/*
* lofs resolve the non-global zone's root path first in case
* its in a path that's been lofs mounted read-only.
*/
/* verify that the root path exists */
if (_z_is_directory(lzRootPath) != 0) {
return (B_FALSE);
}
/*
* generate a unique key - the key is the same length as unique uid
* but contains different information that is as unique as can be made;
* include current hires time (nanosecond real timer). Such a unique
* i.d. will look like:
* 0203104092-1145345-0004e94d6af481a0
*/
UUID_FORMAT, sizeof (uuid));
return (B_FALSE);
}
/* create the global zone mount point */
if (slen > sizeof (gzMountPoint)) {
"%s/.SUNW_%s_%s", lzRootPath,
uuid, sizeof (gzMountPoint));
return (B_FALSE);
}
if (slen > sizeof (lzMountPoint)) {
sizeof (lzMountPoint));
return (B_FALSE);
}
/* error if the mount point already exists */
if (_z_is_directory(gzMountPoint) == 0) {
return (B_FALSE);
}
/* create the temporary mount point */
return (B_FALSE);
}
/* mount the global zone path on the non-global zone root file system */
if (err != 0) {
return (B_FALSE);
}
/* success - return both mountpoints to caller */
/* return success */
return (B_TRUE);
}
/*
* Name: z_non_global_zones_exist
* Description: Determine if any non-global native zones exist
* Arguments: None.
* Returns: boolean_t
* == B_TRUE - at least one non-global native zone exists
* == B_FALSE - no non-global native zone exists
*/
z_non_global_zones_exist(void)
{
/* if zones are not implemented, return FALSE */
if (z_zones_are_implemented() == B_FALSE) {
return (B_FALSE);
}
/* determine if any zones are configured */
zoneIndexFP = setzoneent();
if (zoneIndexFP == NULL) {
return (B_FALSE);
}
/* index file open; scan all zones; see if any are at least installed */
/*
* If the user specified an explicit zone list, then ignore any
* zones that aren't on that list.
*/
break;
}
continue;
}
}
/* skip the global zone */
continue;
}
/* skip any branded zones */
continue;
}
/* is this zone installed? */
break;
}
}
/* close the index file */
/* return results */
return (anyExist);
}
/*
* Name: z_on_zone_spec
* Description: Determine if named zone is on the zone_spec list.
* Arguments: Pointer to name to test.
* Returns: B_TRUE if named zone is on the list or if the user specified
* no list at all (all zones is the default), B_FALSE otherwise.
*/
{
/* entry assertions */
/* return true if zones not implemented or no zone spec list defined */
return (B_TRUE);
}
/* return true if named zone is on the zone spec list */
return (B_TRUE);
}
/* named zone is not on the zone spec list */
return (B_FALSE);
}
/*
* Name: z_running_in_global_zone
* Description: Determine if running in the "global" zone
* Arguments: void
* Returns: boolean_t
* == B_TRUE - running in global zone
* == B_FALSE - not running in global zone
*/
z_running_in_global_zone(void)
{
/* if ID has not been determined, cache it now */
if (!_zoneIdDetermined) {
}
return (_zoneIsGlobal);
}
/*
* Name: z_set_output_functions
* Description: Link program specific output functions to this library.
* Arguments: a_echo_fcn - (_z_printf_fcn_t)
* Function to call to cause "normal operation" messages
* a_echo_debug_fcn - (_z_printf_fcn_t)
* Function to call to cause "debugging" messages
* a_progerr_fcn - (_z_printf_fcn_t)
* Function to call to cause "program error" messages
* Returns: void
* NOTE: If NULL is specified for any function, then the functionality
* associated with that function is disabled.
* NOTE: The function pointers provided must call a function that
* takes two arguments:
* function(char *format, char *message)
* Any registered function will be called like:
* function("%s", "message")
*/
void
{
}
/*
* Name: z_set_zone_root
* Description: Set root for zones library operations
* Arguments: Path to root of boot environment containing zone; must be
* absolute.
* Returns: None.
* NOTE: Must be called before performing any zone-related operations.
* (Currently called directly by set_inst_root() during -R
* argument handling.)
*/
void
{
char *rootdir;
/* if zones are not implemented, just return */
if (!z_zones_are_implemented())
return;
/* entry assertions */
rootdir[0] = '\0';
}
/* free any existing cached root path */
}
/* store duplicate of new zone root path */
if (*rootdir != '\0') {
} else {
}
/* set zone root path */
}
/*
* Name: z_set_zone_spec
* Description: Set list of zones on which actions will be performed.
* Arguments: Whitespace-separated list of zone names.
* Returns: 0 on success, -1 on error.
* NOTES: Will call _z_program_error if argument can't be parsed or
* memory not available.
*/
int
{
const char *zend;
/* entry assertions */
/* parse list to zone_spec_t list, store in global data */
for (;;) {
zlist++;
}
if (*zlist == '\0') {
break;
}
break;
}
}
if (zlen >= ZONENAME_MAX) {
return (-1);
}
}
return (-1);
}
return (0);
}
/*
* Name: z_umount_lz_mount
* Description: Unmount directory mounted with z_mount_in_lz
* Arguments: a_lzMountPointer - pointer to string returned by z_mount_in_lz
* Returns: boolean_t
* == B_TRUE - successfully unmounted directory
* == B_FALSE - failed to unmount directory
*/
{
int err;
/* entry assertions */
/* entry debugging info */
/* if zones are not implemented, return TRUE */
if (z_zones_are_implemented() == B_FALSE) {
return (B_FALSE);
}
/* error if global zone path is not absolute */
if (*a_lzMountPoint != '/') {
return (B_FALSE);
}
/* verify mount point exists */
if (_z_is_directory(a_lzMountPoint) != 0) {
return (B_FALSE);
}
/* unmount */
if (err != 0) {
return (B_FALSE);
}
/* remove the mount point */
(void) remove(a_lzMountPoint);
/* return success */
return (B_TRUE);
}
/*
* Name: z_unlock_this_zone
* Description: unlock this zone
* Arguments: a_lflags - [RO, *RO] - (ZLOCKS_T)
* Flags indicating which locks to release
* Returns: boolean_t
* == B_TRUE - success specified locks released
* == B_FALSE - failure specified locks may not be released
* NOTE: the lock objects for "this zone" are maintained internally.
*/
{
boolean_t b;
char *zoneName;
/* entry assertions */
/* entry debugging info */
/* return if no objects locked */
return (B_TRUE);
}
zoneName = z_get_zonename();
/* unlock package administration */
if (a_lflags & ZLOCKS_PKG_ADMIN) {
if (!b) {
}
}
/* unlock zone administration */
if (a_lflags & ZLOCKS_ZONE_ADMIN) {
if (!b) {
}
}
return (!errors);
}
/*
* Name: z_unlock_zones
* Description: unlock specified zones
* Arguments: a_zlst - zoneList_t object describing zones to unlock
* a_lflags - [RO, *RO] - (ZLOCKS_T)
* Flags indicating which locks to release
* Returns: boolean_t
* == B_TRUE - success, zones unlocked
* == B_FALSE - failure, zones not unlocked
*/
{
boolean_t b;
int i;
/* entry assertions */
/* entry debugging info */
/* if zones are not implemented, return TRUE */
if (z_zones_are_implemented() == B_FALSE) {
return (B_TRUE);
}
/* ignore empty list */
/* unlock this zone before returning */
return (z_unlock_this_zone(a_lflags));
}
/* zones exist */
/*
* unlock each listed zone that is currently running
*/
/* ignore zone if not locked */
continue;
}
/* ignore zone if not running */
continue;
}
/* unlock this zone */
if (b != B_TRUE) {
} else {
/* mark zone as unlocked */
}
}
/* unlock this zone */
}
return (errors);
}
/*
* Name: z_verify_zone_spec
* Description: Verify list of zones on which actions will be performed.
* Arguments: None.
* Returns: 0 on success, -1 on error.
* NOTES: Will call _z_program_error if there are zones on the specified
* list that don't exist on the system. Requires that
* z_set_zone_root is called first (if it is called at all).
*/
int
z_verify_zone_spec(void)
{
if (!z_zones_are_implemented()) {
return (-1);
}
zoneIndexFP = setzoneent();
if (zoneIndexFP == NULL) {
return (-1);
}
break;
}
}
}
}
}
return (errors ? -1 : 0);
}
/*
* Name: z_zlist_change_zone_state
* Description: Change the current state of the specified zone
* Arguments: a_zlst - handle to zoneList_t object describing all zones
* a_zoneIndex - index into a_zlst of the zone to return the
* a_newState - the state to put the specified zone in
* Returns: boolean_t
* == B_TRUE - the zone is in the new state
* == B_FALSE - unable to transition the zone to the
* specified state
* NOTE: This changes the "current kernel" state of the specified
* zone. For example, to boot the zone, change the state
* to "ZONE_STATE_RUNNING". To halt the zone, change the
* state to "ZONE_STATE_INSTALLED".
*/
{
int i;
/* entry debugging info */
/* ignore empty list */
return (B_FALSE);
}
/* find the specified zone in the list */
for (i = 0; (i != a_zoneIndex) &&
;
/* return error if the specified zone does not exist */
return (B_FALSE);
}
/* return success if the zone is already in this state */
return (B_TRUE);
}
/* take action on new state to set zone to */
switch (a_newState) {
case ZONE_STATE_RUNNING:
case ZONE_STATE_MOUNTED:
/* these states mean "boot the zone" */
return (_z_make_zone_running(&a_zlst[i]));
case ZONE_STATE_DOWN:
case ZONE_STATE_INSTALLED:
/* these states mean "halt the zone" */
return (_z_make_zone_down(&a_zlst[i]));
case ZONE_STATE_READY:
return (_z_make_zone_ready(&a_zlst[i]));
case ZONE_STATE_CONFIGURED:
case ZONE_STATE_INCOMPLETE:
case ZONE_STATE_SHUTTING_DOWN:
default:
/* do not know how to change zone to this state */
return (B_FALSE);
}
}
/*
* Name: z_is_zone_branded
* Description: Determine whether zone has a non-native brand
* Arguments: a_zoneName - name of the zone to check for branding
* Returns: boolean_t
* == B_TRUE - zone has a non-native brand
* == B_FALSE - zone is native
*/
{
int err;
/* if zones are not implemented, return FALSE */
if (!z_zones_are_implemented()) {
return (B_FALSE);
}
/* if brands are not implemented, return FALSE */
if (!z_brands_are_implemented()) {
return (B_FALSE);
}
return (B_FALSE);
}
/*
* Both "native" and "cluster" are native brands
* that use the standard facilities in the areas
* of packaging/installation/update.
*/
return (B_FALSE);
} else {
return (B_TRUE);
}
}
/*
* Name: z_is_zone_brand_in_list
* Description: Determine whether zone's brand has a match in the list
* brands passed in.
* Arguments: zoneName - name of the zone to check for branding
* list - list of brands to check the zone against
* Returns: boolean_t
* == B_TRUE - zone has a matching brand
* == B_FALSE - zone brand is not in list
*/
{
int err;
return (B_FALSE);
/* if zones are not implemented, return FALSE */
if (!z_zones_are_implemented()) {
return (B_FALSE);
}
/* if brands are not implemented, return FALSE */
if (!z_brands_are_implemented()) {
return (B_FALSE);
}
return (B_FALSE);
}
return (B_TRUE);
}
}
return (B_FALSE);
}
/*
* Name: z_zlist_get_current_state
* Description: Determine the current kernel state of the specified zone
* Arguments: a_zlst - handle to zoneList_t object describing all zones
* a_zoneIndex - index into a_zlst of the zone to return
* Returns: zone_state_t
* The current state of the specified zone is returned
*/
{
int i;
/* ignore empty list */
return (ZONE_STATE_INCOMPLETE);
}
/* find the specified zone in the list */
for (i = 0; (i != a_zoneIndex) &&
;
/* return error if the specified zone does not exist */
return (ZONE_STATE_INCOMPLETE);
}
/* return selected zone's current kernel state */
return (a_zlst[i]._zlCurrKernelStatus);
}
/*
* Name: z_zlist_get_original_state
* Description: Return the original kernal state of the specified zone
* Arguments: a_zlst - handle to zoneList_t object describing all zones
* a_zoneIndex - index into a_zlst of the zone to return the
* Returns: zone_state_t
* The original state of the specified zone is returned.
* This is the state of the zone when the zoneList_t
* object was first generated.
*/
{
int i;
/* ignore empty list */
return (ZONE_STATE_INCOMPLETE);
}
/* find the specified zone in the list */
for (i = 0; (i != a_zoneIndex) &&
;
/* return error if the specified zone does not exist */
return (ZONE_STATE_INCOMPLETE);
}
/* return selected zone's original kernel state */
return (a_zlst[i]._zlOrigKernelStatus);
}
/*
* Name: z_zlist_get_scratch
* Description: Determine name of scratch zone
* Arguments: a_zlst - handle to zoneList_t object describing all zones
* a_zoneIndex - index into a_zlst of the zone to use
* Return: char *
* == NULL - zone name could not be determined
* != NULL - pointer to string representing scratch zone
* NOTE: Any name returned is placed in static storage that must
* NEVER be free()ed by the caller.
*/
char *
{
int i;
/* ignore empty list */
return (NULL);
/* find the specified zone in the list */
for (i = 0; i != a_zoneIndex; i++) {
return (NULL);
}
/* return selected zone's scratch name */
a_zlst[i]._zlScratchName);
}
/*
* Name: z_zlist_get_zonename
* Description: Determine name of specified zone
* Arguments: a_zlst - handle to zoneList_t object describing all zones
* a_zoneIndex - index into a_zlst of the zone to return the
* Return: char *
* == NULL - zone name could not be determined
* != NULL - pointer to string representing zone name
* NOTE: Any zoneList_t returned is placed in static storage that must
* NEVER be free()ed by the caller.
*/
char *
{
int i;
/* ignore empty list */
return ((char *)NULL);
}
/* find the specified zone in the list */
for (i = 0; (i != a_zoneIndex) &&
;
/* return error if the specified zone does not exist */
return (NULL);
}
/* return selected zone's name */
}
/*
* Name: z_zlist_get_zonepath
* Description: Determine zonepath of specified zone
* Arguments: a_zlst - handle to zoneList_t object describing all zones
* a_zoneIndex - index into a_zlst of the zone to return
* Return: char *
* == NULL - zonepath could not be determined
* != NULL - pointer to string representing zonepath
* NOTE: Any zoneList_t returned is placed in static storage that must
* NEVER be free()ed by the caller.
*/
char *
{
int i;
/* ignore empty list */
return ((char *)NULL);
}
/* find the specified zone in the list */
for (i = 0; (i != a_zoneIndex) &&
;
/* return error if the specified zone does not exist */
return (NULL);
}
/* return selected zone's zonepath */
}
{
int i;
/* if zones are not implemented, return error */
if (z_zones_are_implemented() == B_FALSE) {
return (B_FALSE);
}
/* ignore empty list */
return (B_FALSE);
}
/* find the specified zone in the list */
for (i = 0; (i != a_zoneIndex) &&
;
/* return error if the specified zone does not exist */
return (B_FALSE);
}
/* choose based on current state */
switch (a_zlst[i]._zlCurrKernelStatus) {
case ZONE_STATE_RUNNING:
case ZONE_STATE_MOUNTED:
/* already running */
return (B_TRUE);
case ZONE_STATE_INSTALLED:
case ZONE_STATE_DOWN:
case ZONE_STATE_READY:
case ZONE_STATE_SHUTTING_DOWN:
/* return false if the zone cannot be booted */
return (B_FALSE);
}
return (B_TRUE);
case ZONE_STATE_CONFIGURED:
case ZONE_STATE_INCOMPLETE:
default:
/* cannot transition (boot) these states */
return (B_FALSE);
}
}
/*
* Name: z_zlist_restore_zone_state
* Description: Return the zone to the state it was originally in
* Arguments: a_zlst - handle to zoneList_t object describing all zones
* a_zoneIndex - index into a_zlst of the zone to return the
* Returns: boolean_t
* == B_TRUE - the zone's state has been restored
* == B_FALSE - unable to transition the zone to its
* original state
*/
{
int i;
/* ignore empty list */
return (B_FALSE);
}
/* find the specified zone in the list */
for (i = 0; (i != a_zoneIndex) &&
;
/* return error if the specified zone does not exist */
return (B_FALSE);
}
/* transition the zone back to its original state */
return (z_zlist_change_zone_state(a_zlst,
}
/*
* Name: z_zone_exec
* Description: Execute a Unix command in a specified zone and return results
* Arguments: a_zoneName - pointer to string representing the name of the zone
* to execute the specified command in
* a_path - pointer to string representing the full path *in the
* non-global zone named by a_zoneName* of the Unix command
* to be executed
* a_argv[] - Pointer to array of character strings representing
* the arguments to be passed to the Unix command. The list
* must be termianted with an element that is (char *)NULL
* NOTE: a_argv[0] is the "command name" passed to the command
* a_stdoutPath - Pointer to string representing the path to a file
* into which all output to "stdout" from the Unix command
* is placed.
* == (char *)NULL - leave stdout open and pass through
* a_strerrPath - Pointer to string representing the path to a file
* into which all output to "stderr" from the Unix command
* is placed.
* == (char *)NULL - leave stderr open and pass through
* a_fds - Pointer to array of integers representing file
* descriptors to remain open during the call - all
* file descriptors above STDERR_FILENO not in this
* list will be closed.
* Returns: int
* The return (exit) code from the specified Unix command
* Special return codes:
* -1 : failure to exec process
* -2 : could not create contract for greenline
* -3 : fork() failed
* -4 : could not open stdout capture file
* -5 : error from 'waitpid' other than EINTR
* -6 : zones are not supported
* NOTE: All file descriptores other than 0, 1 and 2 are closed except
* for those file descriptors listed in the a_fds array.
*/
int
{
int final_status;
int lerrno;
int status;
int tmpl_fd;
void (*funcSighup)();
void (*funcSigint)();
/* if zones are not implemented, return TRUE */
if (z_zones_are_implemented() == B_FALSE) {
return (-6); /* -6 : zones are not supported */
}
return (-2); /* -2 : could not create greenline contract */
}
/*
* after the fork1() the parent and child need to setup their respective
* interrupt handling and release the hold on the signals
*/
/*
* fork off a new process to execute command in;
* fork1() is used instead of vfork() so the child process can
* perform operations that would modify the parent process if
* vfork() were used
*/
if (child_pid < 0) {
/*
* *************************************************************
* fork failed!
* *************************************************************
*/
(void) ct_tmpl_clear(tmpl_fd);
/* release hold on signals */
return (-3); /* -3 : fork() failed */
}
if (child_pid == 0) {
int i;
/*
* *************************************************************
* This is the forked (child) process
* *************************************************************
*/
(void) ct_tmpl_clear(tmpl_fd);
/* reset any signals to default */
for (i = 0; i < NSIG; i++) {
}
/*
* close all file descriptors not in the a_fds list
*/
/*
* if a file for stdout is present, open the file and use the
* file to capture stdout from the _zexec process
*/
if (a_stdoutPath != (char *)NULL) {
int stdoutfd;
if (stdoutfd < 0) {
return (-4);
}
}
/*
* if a file for stderr is present, open the file and use the
* file to capture stderr from the _zexec process
*/
if (a_stderrPath != (char *)NULL) {
int stderrfd;
if (stderrfd < 0) {
return (-4);
}
}
/* release all held signals */
/* execute command in the specified non-global zone */
}
/*
* *********************************************************************
* This is the forking (parent) process
* *********************************************************************
*/
/* register child process i.d. so signal handlers can pass signal on */
/*
* setup signal handlers for SIGINT and SIGHUP and release hold
*/
/* hook SIGINT to _z_sig_trap() */
} else {
}
/* hook SIGHUP to _z_sig_trap() */
} else {
}
/* release hold on signals */
(void) ct_tmpl_clear(tmpl_fd);
/*
* wait for the process to exit, reap child exit status
*/
for (;;) {
/* break loop if child process status reaped */
if (result_pid != -1) {
break;
}
/* break loop if not interrupted out of waitpid */
break;
}
}
/* reset child process i.d. so signal handlers do not pass signals on */
/*
* If the child process terminated due to a call to exit(), then
* set results equal to the 8-bit exit status of the child process;
* otherwise, set the exit status to "-1" indicating that the child
* exited via a signal.
*/
if ((_z_global_data._z_SigReceived != 0) &&
(final_status == 0)) {
final_status = 1;
}
} else {
}
/* determine proper exit code */
if (result_pid == -1) {
} else if (_z_global_data._z_SigReceived != 0) {
}
/*
* reset signal handlers
*/
/* reset SIGINT */
/* reset SIGHUP */
/*
* if signal received during command execution, interrupt
* this process now.
*/
if (_z_global_data._z_SigReceived != 0) {
}
/* set errno and return */
return (final_status);
}
/*
* Name: z_zones_are_implemented
* Description: Determine if any zone operations can be performed
* Arguments: void
* Returns: boolean_t
* == B_TRUE - zone operations are available
* == B_FALSE - no zone operations can be done
*/
z_zones_are_implemented(void)
{
/* if availability has not been determined, cache it now */
if (!_zonesImplementedDetermined) {
if (!_zonesAreImplemented) {
} else {
}
}
return (_zonesAreImplemented);
}