/*-
* Copyright (c) 2003, 2008 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Andrew Brown.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* linux sysctl system call
*/
int
linux_sys___sysctl(struct lwp *l, const struct linux_sys___sysctl_args *uap, register_t *retval)
{
struct linux___sysctl ls;
int error, nerror, name[CTL_MAXNAME];
size_t savelen = 0, oldlen = 0;
/*
* get linux args structure
*/
if ((error = copyin(SCARG(uap, lsp), &ls, sizeof(ls))))
return error;
/*
* get oldlen
*/
oldlen = 0;
if (ls.oldlenp != NULL) {
error = copyin(ls.oldlenp, &oldlen, sizeof(oldlen));
if (error)
return (error);
}
savelen = oldlen;
/*
* top-level sysctl names may or may not be non-terminal, but
* we don't care
*/
if (ls.nlen > CTL_MAXNAME || ls.nlen < 1)
return (ENOTDIR);
error = copyin(ls.name, &name, ls.nlen * sizeof(int));
if (error)
return (error);
ktrmib(name, ls.nlen);
/*
* dispatch request into linux sysctl tree
*/
sysctl_lock(ls.newval != NULL);
error = sysctl_dispatch(&name[0], ls.nlen,
ls.oldval, &oldlen,
ls.newval, ls.newlen,
&name[0], l, &linux_sysctl_root);
sysctl_unlock();
/*
* reset caller's oldlen, even if we got an error
*/
if (ls.oldlenp) {
nerror = copyout(&oldlen, ls.oldlenp, sizeof(oldlen));
if (error == 0)
error = nerror;
}
/*
* if the only problem is that we weren't given enough space,
* that's an ENOMEM error
*/
if (error == 0 && ls.oldval != NULL && savelen < oldlen)
error = ENOMEM;