/*
* 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
*/
/*
*/
#include "lint.h"
#include <priv_private.h>
#include <zone.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <errno.h>
{
priv_data_t *d;
LOADPRIVDATA(d);
}
int
{
}
int
{
}
int
{
}
{
int error;
if (error)
(void) __set_errno(error);
}
{
int error;
if (error)
(void) __set_errno(error);
}
int
{
}
int
{
}
/*
* Get id (if any) for specified zone.
*
* Call the real zone_get_id() in libzonecfg.so.1 if it can be found.
* Otherwise, perform a stripped-down version of the function.
* Any changes in one version should probably be reflected in the other.
*
* This stripped-down version of the function only checks for active
* (booted) zones, by numeric id or name.
*/
int
{
char *cp;
/*
* The first time we are called, attempt to dlopen() libzonecfg.so.1
* and get a pointer to the real zone_get_id().
* If we fail, set our pointer to -1 so we won't try again.
*/
if (real_zone_get_id == NULL) {
/*
* There's no harm in doing this more than once, even
* concurrently. We will get the same result each time,
* and the dynamic linker will single-thread the dlopen()
* with its own internal lock. The worst that can happen
* is that the handle gets a reference count greater than
* one, which doesn't matter since we never dlclose()
* the handle if we successfully find the symbol; the
* library just stays in the address space until exit().
*/
sym = (void *)(-1);
}
}
/*
* If we've successfully loaded it, call the real zone_get_id().
* Otherwise, perform our stripped-down version of the code.
*/
/* first try looking for active zone by id */
errno = 0;
return (0);
}
/* then look for active zone by name */
return (0);
}
/* not an active zone, return error */
return (-1);
}
int
{
}
int
{
}
/*
* Underlying implementation for getzoneid and getzoneidbyname.
*/
static zoneid_t
{
}
getzoneid(void)
{
return (zone_lookup(NULL));
}
{
return (zone_lookup(zonename));
}
{
}
int
{
}
int
{
}
int
{
}
int
{
}
/*
* Do a dance with the kernel to allocate sufficient memory to hold an
* array of zoneids and to gather the list of zoneids into said array.
*
* This is a convenience wrapper around zone_list.
*
* The number of zones may change while we're doing this, but the loop
* below guarantees that we'll keep going until we have a consistent
* snapshot.
*
* NOTE: This routine allocates memory, which you must free!
*/
int
{
nzids = 1;
for (;;) {
/* Shouldn't happen, since the global zone always exists */
if (nzids == 0) {
*nzoneids = 0;
return (0);
}
/*
* Pad the number of zones a bit, in case the number of zones on
* the system is increasing rapidly.
*/
return (-1);
return (-1);
}
/* list grew or something weird happened, try again */
continue;
}
break;
}
return (0);
}