Home | History | Annotate | Line # | Download | only in common
kern_info_43.c revision 1.2
      1 /*	$NetBSD: kern_info_43.c,v 1.2 1995/09/19 22:01:58 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1982, 1986, 1991, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the University of
     18  *	California, Berkeley and its contributors.
     19  * 4. Neither the name of the University nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  *
     35  *	@(#)subr_xxx.c	8.1 (Berkeley) 6/10/93
     36  */
     37 
     38 #include <sys/param.h>
     39 #include <sys/systm.h>
     40 #include <sys/filedesc.h>
     41 #include <sys/kernel.h>
     42 #include <sys/vnode.h>
     43 #include <sys/proc.h>
     44 #include <sys/file.h>
     45 #include <sys/socket.h>
     46 #include <sys/socketvar.h>
     47 #include <sys/stat.h>
     48 #include <sys/ioctl.h>
     49 #include <sys/fcntl.h>
     50 #include <sys/malloc.h>
     51 #include <sys/syslog.h>
     52 #include <sys/unistd.h>
     53 #include <sys/resourcevar.h>
     54 #include <vm/vm.h>
     55 #include <sys/sysctl.h>
     56 
     57 #include <sys/mount.h>
     58 #include <sys/syscallargs.h>
     59 
     60 int
     61 compat_43_getdtablesize(p, uap, retval)
     62 	struct proc *p;
     63 	void *uap;
     64 	register_t *retval;
     65 {
     66 
     67 	*retval = min((int)p->p_rlimit[RLIMIT_NOFILE].rlim_cur, maxfiles);
     68 	return (0);
     69 }
     70 
     71 
     72 /* ARGSUSED */
     73 int
     74 compat_43_gethostid(p, uap, retval)
     75 	struct proc *p;
     76 	void *uap;
     77 	register_t *retval;
     78 {
     79 
     80 	*(int32_t *)retval = hostid;
     81 	return (0);
     82 }
     83 
     84 
     85 /*ARGSUSED*/
     86 int
     87 compat_43_gethostname(p, v, retval)
     88 	struct proc *p;
     89 	void *v;
     90 	register_t *retval;
     91 {
     92 	struct compat_43_gethostname_args /* {
     93 		syscallarg(char *) hostname;
     94 		syscallarg(u_int) len;
     95 	} */ *uap = v;
     96 	int name;
     97 
     98 	name = KERN_HOSTNAME;
     99 	return (kern_sysctl(&name, 1, SCARG(uap, hostname), &SCARG(uap, len),
    100 	    0, 0));
    101 }
    102 
    103 #define	KINFO_PROC		(0<<8)
    104 #define	KINFO_RT		(1<<8)
    105 #define	KINFO_VNODE		(2<<8)
    106 #define	KINFO_FILE		(3<<8)
    107 #define	KINFO_METER		(4<<8)
    108 #define	KINFO_LOADAVG		(5<<8)
    109 #define	KINFO_CLOCKRATE		(6<<8)
    110 
    111 int
    112 compat_43_getkerninfo(p, v, retval)
    113 	struct proc *p;
    114 	void *v;
    115 	register_t *retval;
    116 {
    117 	register struct compat_43_getkerninfo_args /* {
    118 		syscallarg(int) op;
    119 		syscallarg(char *) where;
    120 		syscallarg(int *) size;
    121 		syscallarg(int) arg;
    122 	} */ *uap = v;
    123 	int error, name[5];
    124 	size_t size;
    125 
    126 	if (SCARG(uap, size) && (error = copyin((caddr_t)SCARG(uap, size),
    127 	    (caddr_t)&size, sizeof(size))))
    128 		return (error);
    129 
    130 	switch (SCARG(uap, op) & 0xff00) {
    131 
    132 	case KINFO_RT:
    133 		name[0] = PF_ROUTE;
    134 		name[1] = 0;
    135 		name[2] = (SCARG(uap, op) & 0xff0000) >> 16;
    136 		name[3] = SCARG(uap, op) & 0xff;
    137 		name[4] = SCARG(uap, arg);
    138 		error =
    139 		    net_sysctl(name, 5, SCARG(uap, where), &size, NULL, 0, p);
    140 		break;
    141 
    142 	case KINFO_VNODE:
    143 		name[0] = KERN_VNODE;
    144 		error =
    145 		    kern_sysctl(name, 1, SCARG(uap, where), &size, NULL, 0, p);
    146 		break;
    147 
    148 	case KINFO_PROC:
    149 		name[0] = KERN_PROC;
    150 		name[1] = SCARG(uap, op) & 0xff;
    151 		name[2] = SCARG(uap, arg);
    152 		error =
    153 		    kern_sysctl(name, 3, SCARG(uap, where), &size, NULL, 0, p);
    154 		break;
    155 
    156 	case KINFO_FILE:
    157 		name[0] = KERN_FILE;
    158 		error =
    159 		    kern_sysctl(name, 1, SCARG(uap, where), &size, NULL, 0, p);
    160 		break;
    161 
    162 	case KINFO_METER:
    163 		name[0] = VM_METER;
    164 		error =
    165 		    vm_sysctl(name, 1, SCARG(uap, where), &size, NULL, 0, p);
    166 		break;
    167 
    168 	case KINFO_LOADAVG:
    169 		name[0] = VM_LOADAVG;
    170 		error =
    171 		    vm_sysctl(name, 1, SCARG(uap, where), &size, NULL, 0, p);
    172 		break;
    173 
    174 	case KINFO_CLOCKRATE:
    175 		name[0] = KERN_CLOCKRATE;
    176 		error =
    177 		    kern_sysctl(name, 1, SCARG(uap, where), &size, NULL, 0, p);
    178 		break;
    179 
    180 	default:
    181 		return (EOPNOTSUPP);
    182 	}
    183 	if (error)
    184 		return (error);
    185 	*retval = size;
    186 	if (SCARG(uap, size))
    187 		error = copyout((caddr_t)&size, (caddr_t)SCARG(uap, size),
    188 		    sizeof(size));
    189 	return (error);
    190 }
    191 
    192 
    193 /* ARGSUSED */
    194 int
    195 compat_43_sethostid(p, v, retval)
    196 	struct proc *p;
    197 	void *v;
    198 	register_t *retval;
    199 {
    200 	struct compat_43_sethostid_args /* {
    201 		syscallarg(int32_t) hostid;
    202 	} */ *uap = v;
    203 	int error;
    204 
    205 	if (error = suser(p->p_ucred, &p->p_acflag))
    206 		return (error);
    207 	hostid = SCARG(uap, hostid);
    208 	return (0);
    209 }
    210 
    211 
    212 /* ARGSUSED */
    213 int
    214 compat_43_sethostname(p, v, retval)
    215 	struct proc *p;
    216 	void *v;
    217 	register_t *retval;
    218 {
    219 	struct compat_43_sethostname_args *uap = v;
    220 	int name;
    221 	int error;
    222 
    223 	if (error = suser(p->p_ucred, &p->p_acflag))
    224 		return (error);
    225 	name = KERN_HOSTNAME;
    226 	return (kern_sysctl(&name, 1, 0, 0, SCARG(uap, hostname),
    227 	    SCARG(uap, len)));
    228 }
    229