sysctl.c revision 9acbbeaf2a1ffe5c14b244867d427714fab43c5c
/*
* 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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <alloca.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/lx_syscall.h>
#include <sys/lx_debug.h>
/*
* sysctl() implementation. The full set of possible values is incredibly
* large; we only implement the bare minimum here, namely basic kernel
* information.
*
* For the moment, we also print out debugging messages if the application
* attempts to write or access any other values, so we can tell if we are not
* supporting something we should be.
*/
struct lx_sysctl_args {
int *name;
int nlen;
void *oldval;
void *newval;
};
#define LX_CTL_KERN 1
#define LX_KERN_OSTYPE 1
#define LX_KERN_OSRELEASE 2
#define LX_KERN_OSREV 3
#define LX_KERN_VERSION 4
int
{
struct lx_sysctl_args args;
int name[2];
char *namebuf;
return (-EFAULT);
/*
* We only allow [ CTL_KERN, KERN_* ] pairs, so reject anything that
* doesn't have exactly two values starting with LX_CTL_KERN.
*/
return (-ENOTDIR);
return (-EFAULT);
if (name[0] != LX_CTL_KERN) {
lx_debug("sysctl: read of [%d, %d] unsupported",
return (-ENOTDIR);
}
/* We don't support writing new sysctl values. */
lx_debug("sysctl: write of [%d, %d] unsupported",
return (-EPERM);
}
/*
* It may seem silly, but passing in a NULL oldval pointer and not
* writing any new values is a perfectly legal thing to do and should
* succeed.
*/
return (0);
/*
* Likewise, Linux specifies that setting a non-NULL oldval but a
* zero *oldlenp should result in an errno of EFAULT.
*/
(oldlen == 0))
return (-EFAULT);
return (-ENOMEM);
switch (name[1]) {
case LX_KERN_OSTYPE:
break;
case LX_KERN_OSRELEASE:
break;
case LX_KERN_VERSION:
break;
default:
return (-ENOTDIR);
}
return (-EFAULT);
return (0);
}