lx_support.c revision 5679c89fcd2facbb4334df8870d3d7a4d2b11673
/*
* 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.
*/
/*
* lx_support is a small cli utility used to perform some brand-specific
* tasks when booting, halting, or verifying a zone. This utility is not
* intended to be called by users - it is intended to be invoked by the
* zones utilities.
*/
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <libgen.h>
#include <limits.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <stropts.h>
#include <sys/systeminfo.h>
#include <unistd.h>
#include <libintl.h>
#include <locale.h>
#include <libzonecfg.h>
#include <sys/lx_audio.h>
#include <sys/lx_brand.h>
static void usage(void) __NORETURN;
#define LXA_AUDIO_DEV "/dev/brand/lx/audio_devctl"
#define INTSTRLEN 32
#define KVSTRLEN 10
#if !defined(TEXT_DOMAIN) /* should be defined by cc -D */
#endif
static void
{
char buf[1024];
/*LINTED*/
exit(1);
/*NOTREACHED*/
}
/*
* FIFO. Since any attempt to create a file in /dev will fail, we must
* create it here.
*/
static void
{
char path[MAXPATHLEN];
char special[MAXPATHLEN];
int err;
sizeof (special))
gettext("zoneroot is too long"));
sizeof (path))
gettext("zoneroot is too long"));
lxs_err("%s: %s",
lxs_err("%s: %s",
}
} else {
lxs_err("%s: %s",
gettext("It already exists, and is not a FIFO."));
}
/*
*/
gettext("zoneroot is too long"));
}
}
/*
* fsck gets really confused when run inside a zone. Removing this file
* prevents it from running
*/
static void
{
char path[MAXPATHLEN];
int err;
gettext("zoneroot is too long"));
lxs_err("%s: %s",
gettext("Failed to remove /.autofsck"),
}
}
/*
* Extract any lx-supported attributes from the zone configuration file.
*/
static void
{
struct zone_attrtab attrtab;
int err;
/* initialize the attribute iterator */
}
}
}
/* some kind of error while looking up attributes */
if (err != Z_NO_ENTRY)
}
static int
lxs_iodev_ok(char *dev)
{
int i, j;
return (1);
return (1);
return (1);
for (i = 0; i < j; i++) {
return (0);
}
return (1);
}
/*
* The audio configuration settings are read from the zone configuration
* file. Audio configuration is specified via the following attributes
* (settable via zonecfg):
* attr name: audio
* attr type: boolean
*
* attr name: audio-inputdev
* attr type: string
* attr values: "none" | [0-9]+
*
* attr name: audio-outputdev
* attr type: string
* attr values: "none" | [0-9]+
*
* for a zone by setting the "audio" attribute to true. (The absence of
* this attribute leads to an assumed value of false.)
*
* If the "audio" attribute is set to true and "audio-inputdev" and
* "audio-outputdev" are not set, then when a linux applications access
* audio devices these access will be mapped to the system default audio
*
* If "audio-inputdev" is set to none, then audio input will be disabled.
* If "audio-inputdev" is set to an integer, then when a Linux application
* attempts to access audio devices these access will be mapped to
* apply to the "audio-outputdev" attribute for linux audio output
* device accesses.
*
* If "audio-inputdev" or "audio-outputdev" exist but the audio attribute
* is missing (or set to false) audio will not be enabled for the zone.
*/
static void
{
/* sanity check the input and output device properties */
if (!lxs_iodev_ok(idev))
"audio-inputdev");
if (!lxs_iodev_ok(odev))
"audio-outputdev");
/* initialize the zone name in the ioctl request */
sizeof (lxa_zr.lxa_zr_zone_name));
/* initialize the input device property in the ioctl request */
sizeof (lxa_zr.lxa_zr_inputdev));
/*
* if no input device was specified, set the input device
* to "default"
*/
sizeof (lxa_zr.lxa_zr_inputdev));
}
/* initialize the output device property in the ioctl request */
sizeof (lxa_zr.lxa_zr_outputdev));
/*
* if no output device was specified, set the output device
* to "default"
*/
sizeof (lxa_zr.lxa_zr_outputdev));
}
/* open the audio device control node */
/* enable audio for this zone */
if (err != 0)
}
static int
lxs_boot()
{
int kversnum;
}
/* Extract any relevant attributes from the config file. */
/* Configure the zone's audio support (if any). */
/*
* Let the kernel know whether or not this zone's init process
* should be automatically restarted on its death.
*/
sizeof (boolean_t)) == -1)
else
sizeof (int)) < 0)
return (0);
}
static int
lxs_halt()
{
/*
* We don't bother to check if audio is configured for this zone
* before issuing a request to unconfigure it. There's no real
* reason to do this, it would require looking up the xml zone and
* brand configuration information (which could have been changed
* since the zone was booted), and it would involve more library
* calls there by increasing chances for failure.
*/
/* initialize the zone name in the ioctl request */
sizeof (lxa_zr.lxa_zr_zone_name));
/* open the audio device control node */
/*
* disable audio for this zone
*
* we ignore ENOENT errors here because it's possible that
* audio is not configured for this zone. (either it was
* already unconfigured or someone could have added the
* audio resource to this zone after it was booted.)
*/
return (0);
/*NOTREACHED*/
}
static int
lxs_verify(char *xmlfile)
{
struct zone_fstab fstab;
struct zone_dstab dstab;
struct zone_devtab devtab;
char hostidp[HW_HOSTID_LEN];
}
/*
* Check to see whether the zone has any inherit-pkg-dirs
* configured.
*/
}
}
/*
* Check to see whether the zone has any ZFS datasets configured.
*/
}
}
/*
* Check to see whether the zone has any devices configured.
*/
}
}
/*
* Check to see whether the zone has ip-type configured as exclusive
*/
}
if (iptype == ZS_EXCLUSIVE) {
"ip-type"));
}
/*
* Check to see whether the zone has hostid emulation enabled.
*/
}
/* Extract any relevant attributes from the config file. */
if (audio) {
/* sanity check the input and output device properties */
if (!lxs_iodev_ok(idev))
"audio-inputdev");
if (!lxs_iodev_ok(odev))
"audio-outputdev");
}
if (kvers) {
"kernel-version");
}
return (0);
}
static void
usage()
{
exit(1);
}
int
{
(void) textdomain(TEXT_DOMAIN);
if (argc < 3)
usage();
if (argc != 4)
return (lxs_boot());
}
if (argc != 4)
return (lxs_halt());
}
if (argc != 3)
bname);
}
usage();
/*NOTREACHED*/
}