zone.c revision 2b24ab6b3865caeede9eeb9db6b83e1d89dcd1ea
/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#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
{
}
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.
*/
typedef int (*zone_get_id_t)(const char *, zoneid_t *);
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().
*/
void *sym = (void *)(-1);
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
{
}
/*
* Underlying implementation for getzoneid and getzoneidbyname.
*/
static zoneid_t
zone_lookup(const char *name)
{
}
getzoneid(void)
{
return (zone_lookup(NULL));
}
getzoneidbyname(const char *zonename)
{
return (zone_lookup(zonename));
}
{
}
int
zone_version(int *version)
{
}
int
{
}
int
{
}
int
{
}
int
{
}