Subject: securelevel support incomplete, 'sysctl' missing (#219 - part 1 of 5) Index: sys,bin,lib,usr.lib,usr.bin/many 2.11BSD Description: The support for 'securelevel' is incomplete, part of it was added back in updates #197 thru 210 (when the 'chflags' syscall was implemented). But without a means of setting the security level of the system the level was fixed at -1. There is no 'sysctl' system call present. In addition to retrieving and setting the security level of the system the sysctl() call can be used to read many other kernel data structures without having to perform a nlist(3) on the kernel image. Also, there are present in the C library several obsolete (they were obsolete even when 2.11BSD was new) routines. Repeat-By: Observation. You may wish to refer to update #197 in which mention is made of the 'securelevel' feature. The manpages for sysctl(3) and sysctl(8) are in the shar file below. Fix: sysctl() was borrowed from 4.4BSD-Lite. Everything except the 'networking' portion has been ported - that will be done in the future. Initially only enough of sysctl() was going to be ported to manipulate the 'securelevel' of the system. As the porting effort got underway it became apparent that with not much extra effort the whole sysctl() call could be implemented. As a demonstration of how much faster sysctl() is than 'nlist()' a couple of the programs in the system have been converted to use sysctl() instead of nlist()+read() to fetch information from the kernel. You may wish to save the 'w' and 'welcome' programs in order to compare the runtimes before and after being converted. As time goes on additional utilities will be switched over from nlist() to sysctl(). This is part 1 of 5 (updates 219 thru 223). The contents of each part are as follow: Part/Update# Contents ============ ======== 1 / 219 shar file of new files added to the system 2 / 220 shell script to remove obsolete files 3 / 221 patch file 1 4 / 222 patch file 2 5 / 223 patch file 3 This part adds the following files to the system: /usr/src/sys/sys/kern_sysctl.c /usr/src/sys/h/sysctl.h /usr/src/bin/sysctl /usr/src/lib/libc/gen/sysctl.c /usr/src/lib/libc/gen/getloadavg.c /usr/src/lib/libc/pdp/sys/__sysctl.s /usr/src/man/man3/sysctl.3 /usr/src/man/man3/getloadavg.3 NOTE: None of these should exist in a current 2.11BSD system. If any of the above files exist they should be replaced with the versions in the shar file. Save the shar archive below to a file (/tmp/foo.shar), then extract the files with: sh /tmp/foo.shar DO NOT compile anything yet. Several of the kernel Makefiles need to be updated before the kernel can be built, and so on. =======================cut here======================== #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create: # /usr/src/sys/sys/kern_sysctl.c # /usr/src/sys/h/sysctl.h # /usr/src/bin/sysctl # /usr/src/lib/libc/gen/sysctl.c # /usr/src/lib/libc/gen/getloadavg.c # /usr/src/lib/libc/pdp/sys/__sysctl.s # /usr/src/man/man3/sysctl.3 # /usr/src/man/man3/getloadavg.3 # This archive created: Sat Jan 21 20:30:57 1995 export PATH; PATH=/bin:/usr/bin:$PATH if test -f '/usr/src/sys/sys/kern_sysctl.c' then echo shar: "will not over-write existing file '/usr/src/sys/sys/kern_sysctl.c'" else sed 's/^X//' << \SHAR_EOF > '/usr/src/sys/sys/kern_sysctl.c' X/*- X * Copyright (c) 1982, 1986, 1989, 1993 X * The Regents of the University of California. All rights reserved. X * X * This code is derived from software contributed to Berkeley by X * Mike Karels at Berkeley Software Design, Inc. X * X * Redistribution and use in source and binary forms, with or without X * modification, are permitted provided that the following conditions X * are met: X * 1. Redistributions of source code must retain the above copyright X * notice, this list of conditions and the following disclaimer. X * 2. Redistributions in binary form must reproduce the above copyright X * notice, this list of conditions and the following disclaimer in the X * documentation and/or other materials provided with the distribution. X * 3. All advertising materials mentioning features or use of this software X * must display the following acknowledgement: X * This product includes software developed by the University of X * California, Berkeley and its contributors. X * 4. Neither the name of the University nor the names of its contributors X * may be used to endorse or promote products derived from this software X * without specific prior written permission. X * X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE X * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF X * SUCH DAMAGE. X * X * @(#)kern_sysctl.c 8.4.1 (2.11BSD GTE) 1/15/95 X */ X X/* X * sysctl system call. X */ X X#include X#include X#include X#include X#include X#include X#include X#include X#include X#include X#include X#include X#include X#include X#include X Xsysctlfn kern_sysctl; Xsysctlfn hw_sysctl; X#ifdef DEBUG Xsysctlfn debug_sysctl; X#endif Xsysctlfn vm_sysctl; Xsysctlfn fs_sysctl; Xsysctlfn net_sysctl; Xsysctlfn cpu_sysctl; X X/* X * Locking and stats X */ Xstatic struct sysctl_lock { X int sl_lock; X int sl_want; X int sl_locked; X} memlock; X Xstruct sysctl_args { X int *name; X u_int namelen; X void *old; X size_t *oldlenp; X void *new; X size_t newlen; X}; X Xint X__sysctl() X{ X register struct sysctl_args *uap = (struct sysctl_args *)u.u_ap; X int error; X u_int savelen, oldlen = 0; X sysctlfn *fn; X int name[CTL_MAXNAME]; X X if (uap->new != NULL && !suser()) X return (u.u_error); /* XXX */ X /* X * all top-level sysctl names are non-terminal X */ X if (uap->namelen > CTL_MAXNAME || uap->namelen < 2) X return (u.u_error = EINVAL); X if (error = copyin(uap->name, &name, uap->namelen * sizeof(int))) X return (u.u_error = error); X X switch (name[0]) { X case CTL_KERN: X fn = kern_sysctl; X break; X case CTL_HW: X fn = hw_sysctl; X break; X case CTL_VM: X fn = vm_sysctl; X break; X case CTL_NET: X fn = net_sysctl; X break; X#ifdef notyet X case CTL_FS: X fn = fs_sysctl; X break; X#endif X case CTL_MACHDEP: X fn = cpu_sysctl; X break; X#ifdef DEBUG X case CTL_DEBUG: X fn = debug_sysctl; X break; X#endif X default: X return (u.u_error = EOPNOTSUPP); X } X X if (uap->oldlenp && X (error = copyin(uap->oldlenp, &oldlen, sizeof(oldlen)))) X return (u.u_error = error); X if (uap->old != NULL) { X while (memlock.sl_lock) { X memlock.sl_want = 1; X sleep((caddr_t)&memlock, PRIBIO+1); X memlock.sl_locked++; X } X memlock.sl_lock = 1; X savelen = oldlen; X } X error = (*fn)(name + 1, uap->namelen - 1, uap->old, &oldlen, X uap->new, uap->newlen); X if (uap->old != NULL) { X memlock.sl_lock = 0; X if (memlock.sl_want) { X memlock.sl_want = 0; X wakeup((caddr_t)&memlock); X } X } X if (error) X return (u.u_error = error); X if (uap->oldlenp) { X error = copyout(&oldlen, uap->oldlenp, sizeof(oldlen)); X if (error) X return(u.u_error = error); X } X u.u_r.r_val1 = oldlen; X return (0); X} X X/* X * kernel related system variables. X */ Xkern_sysctl(name, namelen, oldp, oldlenp, newp, newlen) X int *name; X u_int namelen; X void *oldp; X size_t *oldlenp; X void *newp; X size_t newlen; X{ X int error, level; X u_long longhostid; X char bsd[10]; X extern char version[]; X X /* all sysctl names at this level are terminal */ X if (namelen != 1 && !(name[0] == KERN_PROC || name[0] == KERN_PROF)) X return (ENOTDIR); /* overloaded */ X X switch (name[0]) { X case KERN_OSTYPE: X case KERN_OSRELEASE: X /* code is cheaper than D space */ X bsd[0]='2';bsd[1]='.';bsd[2]='1';bsd[3]='1';bsd[4]='B'; X bsd[5]='S';bsd[6]='D';bsd[7]='\0'; X return (sysctl_rdstring(oldp, oldlenp, newp, bsd)); X case KERN_OSREV: X return (sysctl_rdlong(oldp, oldlenp, newp, (long)BSD)); X case KERN_VERSION: X return (sysctl_rdstring(oldp, oldlenp, newp, version)); X case KERN_MAXINODES: X return(sysctl_rdint(oldp, oldlenp, newp, ninode)); X case KERN_MAXPROC: X return (sysctl_rdint(oldp, oldlenp, newp, nproc)); X case KERN_MAXFILES: X return (sysctl_rdint(oldp, oldlenp, newp, nfile)); X case KERN_MAXTEXTS: X return (sysctl_rdint(oldp, oldlenp, newp, ntext)); X case KERN_ARGMAX: X return (sysctl_rdint(oldp, oldlenp, newp, NCARGS)); X case KERN_SECURELVL: X level = securelevel; X if ((error = sysctl_int(oldp, oldlenp, newp, newlen, &level)) || X newp == NULL) X return (error); X if (level < securelevel && u.u_procp->p_pid != 1) X return (EPERM); X securelevel = level; X return (0); X case KERN_HOSTNAME: X error = sysctl_string(oldp, oldlenp, newp, newlen, X hostname, sizeof(hostname)); X if (newp && !error) X hostnamelen = newlen; X return (error); X case KERN_HOSTID: X longhostid = hostid; X error = sysctl_long(oldp, oldlenp, newp, newlen, &longhostid); X hostid = longhostid; X return (error); X case KERN_CLOCKRATE: X return (sysctl_clockrate(oldp, oldlenp)); X case KERN_BOOTTIME: X return (sysctl_rdstruct(oldp, oldlenp, newp, &boottime, X sizeof(struct timeval))); X case KERN_INODE: X return (sysctl_inode(oldp, oldlenp)); X case KERN_PROC: X return (sysctl_doproc(name + 1, namelen - 1, oldp, oldlenp)); X case KERN_FILE: X return (sysctl_file(oldp, oldlenp)); X case KERN_TEXT: X return (sysctl_text(oldp, oldlenp)); X#ifdef GPROF X case KERN_PROF: X return (sysctl_doprof(name + 1, namelen - 1, oldp, oldlenp, X newp, newlen)); X#endif X case KERN_NGROUPS: X return (sysctl_rdint(oldp, oldlenp, newp, NGROUPS)); X case KERN_JOB_CONTROL: X return (sysctl_rdint(oldp, oldlenp, newp, 1)); X case KERN_POSIX1: X case KERN_SAVED_IDS: X return (sysctl_rdint(oldp, oldlenp, newp, 0)); X default: X return (EOPNOTSUPP); X } X /* NOTREACHED */ X} X X/* X * hardware related system variables. X */ Xhw_sysctl(name, namelen, oldp, oldlenp, newp, newlen) X int *name; X u_int namelen; X void *oldp; X size_t *oldlenp; X void *newp; X size_t newlen; X{ X char m[10], c[10]; X char *cpu2str(); X extern size_t physmem; X X /* all sysctl names at this level are terminal */ X if (namelen != 1) X return (ENOTDIR); /* overloaded */ X X switch (name[0]) { X case HW_MACHINE: X m[0]='P';m[1]='D';m[2]='P';m[3]='1';m[4]='1';m[5]='\0'; X return (sysctl_rdstring(oldp, oldlenp, newp, m)); X case HW_MODEL: X return (sysctl_rdstring(oldp, oldlenp, newp, X cpu2str(c,sizeof (c)))); X case HW_NCPU: X return (sysctl_rdint(oldp, oldlenp, newp, 1)); /* XXX */ X case HW_BYTEORDER: X return (sysctl_rdint(oldp, oldlenp, newp, ENDIAN)); X case HW_PHYSMEM: X return (sysctl_rdlong(oldp, oldlenp, newp,ctob((long)physmem))); X case HW_USERMEM: X return (sysctl_rdlong(oldp, oldlenp, newp,ctob((long)freemem))); X case HW_PAGESIZE: X return (sysctl_rdint(oldp, oldlenp, newp, NBPG*CLSIZE)); X default: X return (EOPNOTSUPP); X } X /* NOTREACHED */ X} X Xstatic char * Xcpu2str(buf, len) X char *buf; X int len; X { X register char *cp = buf + len; X register int i = cputype; X X *--cp = '\0'; X do X { X *--cp = (i % 10) + '0'; X } while (i /= 10); X return(cp); X } X X#ifdef DEBUG X/* X * Debugging related system variables. X */ Xstruct ctldebug debug0, debug1, debug2, debug3, debug4; Xstruct ctldebug debug5, debug6, debug7, debug8, debug9; Xstruct ctldebug debug10, debug11, debug12, debug13, debug14; Xstruct ctldebug debug15, debug16, debug17, debug18, debug19; Xstatic struct ctldebug *debugvars[CTL_DEBUG_MAXID] = { X &debug0, &debug1, &debug2, &debug3, &debug4, X &debug5, &debug6, &debug7, &debug8, &debug9, X &debug10, &debug11, &debug12, &debug13, &debug14, X &debug15, &debug16, &debug17, &debug18, &debug19, X}; Xint Xdebug_sysctl(name, namelen, oldp, oldlenp, newp, newlen) X int *name; X u_int namelen; X void *oldp; X size_t *oldlenp; X void *newp; X size_t newlen; X{ X struct ctldebug *cdp; X X /* all sysctl names at this level are name and field */ X if (namelen != 2) X return (ENOTDIR); /* overloaded */ X cdp = debugvars[name[0]]; X if (cdp->debugname == 0) X return (EOPNOTSUPP); X switch (name[1]) { X case CTL_DEBUG_NAME: X return (sysctl_rdstring(oldp, oldlenp, newp, cdp->debugname)); X case CTL_DEBUG_VALUE: X return (sysctl_int(oldp, oldlenp, newp, newlen, cdp->debugvar)); X default: X return (EOPNOTSUPP); X } X /* NOTREACHED */ X} X#endif /* DEBUG */ X X/* X * In 4.4BSD-Lite these functions were scattered amoungst the various X * subsystems they dealt with. X * X * In 2.11BSD the kernel is overlaid and adding code to multiple X * files would have caused existing overlay structures to break. X * This module will be large enough that it will end up in an overlay X * by itself. Thus centralizing all sysctl handling in one place makes X * a lot of sense. The one exception is the networking related syctl X * functions. Because the networking code is not overlaid and runs X * in supervisor mode the sysctl handling can not be done here and X * will be implemented in the 4.4BSD manner (by modifying the networking X * modules). X*/ X Xint Xnet_sysctl(name, namelen, oldp, oldlenp, newp, newlen) X int *name; X u_int namelen; X void *oldp; X size_t *oldlenp; X void *newp; X size_t newlen; X{ X return(EOPNOTSUPP); /* Not yet. */ X} X X/* X * Rather useless - but it's not very big so let's do it. X*/ X Xint Xcpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen) X int *name; X u_int namelen; X void *oldp; X size_t *oldlenp; X void *newp; X size_t newlen; X{ X extern struct tty cons[]; X X /* all sysctl names at this level are terminal */ X if (namelen != 1) X return (ENOTDIR); /* overloaded */ X X switch (name[0]) { X case CPU_CONSDEV: X return (sysctl_rdstruct(oldp, oldlenp, newp, &cons[0].t_dev, X sizeof &cons[0].t_dev)); X default: X return (EOPNOTSUPP); X } X /* NOTREACHED */ X} X X/* X * Bit of a hack. 2.11 currently uses 'short avenrun[3]' and a fixed scale X * of 256. In order not to break all the applications which nlist() for X * 'avenrun' we build a local 'averunnable' structure here to return to the X * user. Eventually (after all applications which look up the load average X * the old way) have been converted we can change things. X * X * We do not call vmtotal(), that could get rather expensive, rather we rely X * on the 5 second update. X * X * The coremap and swapmap cases are 2.11BSD extensions. X*/ X Xint Xvm_sysctl(name, namelen, oldp, oldlenp, newp, newlen) X int *name; X u_int namelen; X void *oldp; X size_t *oldlenp; X void *newp; X size_t newlen; X{ X struct loadavg averunnable; /* loadavg in resource.h */ X X /* all sysctl names at this level are terminal */ X if (namelen != 1) X return (ENOTDIR); /* overloaded */ X X switch (name[0]) { X case VM_LOADAVG: X averunnable.fscale = 256; X averunnable.ldavg[0] = avenrun[0]; X averunnable.ldavg[1] = avenrun[1]; X averunnable.ldavg[2] = avenrun[2]; X return (sysctl_rdstruct(oldp, oldlenp, newp, &averunnable, X sizeof(averunnable))); X case VM_METER: X#ifdef notsure X vmtotal(); /* could be expensive to do this every time */ X#endif X return (sysctl_rdstruct(oldp, oldlenp, newp, &total, X sizeof(total))); X case VM_SWAPMAP: X if (oldp == NULL) { X *oldlenp = (char *)swapmap[0].m_limit - X (char *)swapmap[0].m_map; X return(0); X } X return (sysctl_rdstruct(oldp, oldlenp, newp, swapmap, X (int)swapmap[0].m_limit - (int)swapmap[0].m_map)); X case VM_COREMAP: X if (oldp == NULL) { X *oldlenp = (char *)coremap[0].m_limit - X (char *)coremap[0].m_map; X return(0); X } X return (sysctl_rdstruct(oldp, oldlenp, newp, coremap, X (int)coremap[0].m_limit - (int)coremap[0].m_map)); X default: X return (EOPNOTSUPP); X } X /* NOTREACHED */ X} X X/* X * Validate parameters and get old / set new parameters X * for an integer-valued sysctl function. X */ Xsysctl_int(oldp, oldlenp, newp, newlen, valp) X void *oldp; X size_t *oldlenp; X void *newp; X size_t newlen; X int *valp; X{ X int error = 0; X X if (oldp && *oldlenp < sizeof(int)) X return (ENOMEM); X if (newp && newlen != sizeof(int)) X return (EINVAL); X *oldlenp = sizeof(int); X if (oldp) X error = copyout(valp, oldp, sizeof(int)); X if (error == 0 && newp) X error = copyin(newp, valp, sizeof(int)); X return (error); X} X X/* X * As above, but read-only. X */ Xsysctl_rdint(oldp, oldlenp, newp, val) X void *oldp; X size_t *oldlenp; X void *newp; X int val; X{ X int error = 0; X X if (oldp && *oldlenp < sizeof(int)) X return (ENOMEM); X if (newp) X return (EPERM); X *oldlenp = sizeof(int); X if (oldp) X error = copyout((caddr_t)&val, oldp, sizeof(int)); X return (error); X} X X/* X * Validate parameters and get old / set new parameters X * for an long-valued sysctl function. X */ Xsysctl_long(oldp, oldlenp, newp, newlen, valp) X void *oldp; X size_t *oldlenp; X void *newp; X size_t newlen; X long *valp; X{ X int error = 0; X X if (oldp && *oldlenp < sizeof(long)) X return (ENOMEM); X if (newp && newlen != sizeof(long)) X return (EINVAL); X *oldlenp = sizeof(long); X if (oldp) X error = copyout(valp, oldp, sizeof(long)); X if (error == 0 && newp) X error = copyin(newp, valp, sizeof(long)); X return (error); X} X X/* X * As above, but read-only. X */ Xsysctl_rdlong(oldp, oldlenp, newp, val) X void *oldp; X size_t *oldlenp; X void *newp; X long val; X{ X int error = 0; X X if (oldp && *oldlenp < sizeof(long)) X return (ENOMEM); X if (newp) X return (EPERM); X *oldlenp = sizeof(long); X if (oldp) X error = copyout((caddr_t)&val, oldp, sizeof(long)); X return (error); X} X X/* X * Validate parameters and get old / set new parameters X * for a string-valued sysctl function. X */ Xsysctl_string(oldp, oldlenp, newp, newlen, str, maxlen) X void *oldp; X size_t *oldlenp; X void *newp; X size_t newlen; X char *str; X int maxlen; X{ X int len, error = 0; X X len = strlen(str) + 1; X if (oldp && *oldlenp < len) X return (ENOMEM); X if (newp && newlen >= maxlen) X return (EINVAL); X if (oldp) { X *oldlenp = len; X error = vcopyout(str, oldp, len); X } X if (error == 0 && newp) { X error = vcopyin(newp, str, newlen); X str[newlen] = 0; X } X return (error); X} X X/* X * As above, but read-only. X */ Xsysctl_rdstring(oldp, oldlenp, newp, str) X void *oldp; X size_t *oldlenp; X void *newp; X char *str; X{ X int len, error = 0; X X len = strlen(str) + 1; X if (oldp && *oldlenp < len) X return (ENOMEM); X if (newp) X return (EPERM); X *oldlenp = len; X if (oldp) X error = vcopyout(str, oldp, len); X return (error); X} X X/* X * Validate parameters and get old / set new parameters X * for a structure oriented sysctl function. X */ Xsysctl_struct(oldp, oldlenp, newp, newlen, sp, len) X void *oldp; X size_t *oldlenp; X void *newp; X size_t newlen; X void *sp; X int len; X{ X int error = 0; X X if (oldp && *oldlenp < len) X return (ENOMEM); X if (newp && newlen > len) X return (EINVAL); X if (oldp) { X *oldlenp = len; X error = copyout(sp, oldp, len); X } X if (error == 0 && newp) X error = copyin(newp, sp, len); X return (error); X} X X/* X * Validate parameters and get old parameters X * for a structure oriented sysctl function. X */ Xsysctl_rdstruct(oldp, oldlenp, newp, sp, len) X void *oldp; X size_t *oldlenp; X void *newp, *sp; X int len; X{ X int error = 0; X X if (oldp && *oldlenp < len) X return (ENOMEM); X if (newp) X return (EPERM); X *oldlenp = len; X if (oldp) X error = copyout(sp, oldp, len); X return (error); X} X X/* X * Get file structures. X */ Xsysctl_file(where, sizep) X char *where; X size_t *sizep; X{ X int buflen, error; X register struct file *fp; X struct file *fpp; X char *start = where; X register int i; X X buflen = *sizep; X if (where == NULL) { X for (i = 0, fp = file; fp < fileNFILE; fp++) X if (fp->f_count) i++; X X#define FPTRSZ sizeof (struct file *) X#define FILESZ sizeof (struct file) X /* X * overestimate by 5 files X */ X *sizep = (i + 5) * (FILESZ + FPTRSZ); X return (0); X } X X /* X * array of extended file structures: first the address then the X * file structure. X */ X for (fp = file; fp < fileNFILE; fp++) { X if (fp->f_count == 0) X continue; X if (buflen < (FPTRSZ + FILESZ)) { X *sizep = where - start; X return (ENOMEM); X } X fpp = fp; X if ((error = copyout(&fpp, where, FPTRSZ)) || X (error = copyout(fp, where + FPTRSZ, FILESZ))) X return (error); X buflen -= (FPTRSZ + FILESZ); X where += (FPTRSZ + FILESZ); X } X *sizep = where - start; X return (0); X} X X/* X * This one is in kern_clock.c in 4.4 but placed here for the reasons X * given earlier (back around line 367). X*/ X Xint Xsysctl_clockrate(where, sizep) X char *where; X size_t *sizep; X{ X struct clockinfo clkinfo; X X /* X * Construct clockinfo structure. X */ X clkinfo.hz = hz; X clkinfo.tick = 1000000L / hz; X clkinfo.profhz = 0; X clkinfo.stathz = hz; X return(sysctl_rdstruct(where, sizep, NULL, &clkinfo, sizeof (clkinfo))); X} X X/* X * Dump inode list (via sysctl). X * Copyout address of inode followed by inode. X */ X/* ARGSUSED */ Xsysctl_inode(where, sizep) X char *where; X size_t *sizep; X{ X register struct inode *ip; X register char *bp = where; X struct inode *ipp; X char *ewhere; X int error, numi; X X for (numi = 0, ip = inode; ip < inodeNINODE; ip++) X if (ip->i_count) numi++; X X#define IPTRSZ sizeof (struct inode *) X#define INODESZ sizeof (struct inode) X if (where == NULL) { X *sizep = (numi + 5) * (IPTRSZ + INODESZ); X return (0); X } X ewhere = where + *sizep; X X for (ip = inode; ip < inodeNINODE; ip++) { X if (ip->i_count == 0) X continue; X if (bp + IPTRSZ + INODESZ > ewhere) { X *sizep = bp - where; X return (ENOMEM); X } X ipp = ip; X if ((error = copyout((caddr_t)&ipp, bp, IPTRSZ)) || X (error = copyout((caddr_t)ip, bp + IPTRSZ, INODESZ))) X return (error); X bp += IPTRSZ + INODESZ; X } X X *sizep = bp - where; X return (0); X} X X/* X * Get text structures. This is a 2.11BSD extension. sysctl() is supposed X * to be extensible... X */ Xsysctl_text(where, sizep) X char *where; X size_t *sizep; X{ X int buflen, error; X register struct text *xp; X struct text *xpp; X char *start = where; X register int i; X X buflen = *sizep; X if (where == NULL) { X for (i = 0, xp = text; xp < textNTEXT; xp++) X if (xp->x_count) i++; X X#define TPTRSZ sizeof (struct text *) X#define TEXTSZ sizeof (struct text) X /* X * overestimate by 3 text structures X */ X *sizep = (i + 3) * (TEXTSZ + TPTRSZ); X return (0); X } X X /* X * array of extended file structures: first the address then the X * file structure. X */ X for (xp = text; xp < textNTEXT; xp++) { X if (xp->x_count == 0) X continue; X if (buflen < (TPTRSZ + TEXTSZ)) { X *sizep = where - start; X return (ENOMEM); X } X xpp = xp; X if ((error = copyout(&xpp, where, TPTRSZ)) || X (error = copyout(xp, where + TPTRSZ, TEXTSZ))) X return (error); X buflen -= (TPTRSZ + TEXTSZ); X where += (TPTRSZ + TEXTSZ); X } X *sizep = where - start; X return (0); X} X X/* X * try over estimating by 5 procs X */ X#define KERN_PROCSLOP (5 * sizeof (struct kinfo_proc)) X Xsysctl_doproc(name, namelen, where, sizep) X int *name; X u_int namelen; X char *where; X size_t *sizep; X{ X register struct proc *p; X register struct kinfo_proc *dp = (struct kinfo_proc *)where; X int needed = 0; X int buflen = where != NULL ? *sizep : 0; X int doingzomb; X struct eproc eproc; X int error = 0; X dev_t ttyd; X uid_t ruid; X struct tty *ttyp; X X if (namelen != 2 && !(namelen == 1 && name[0] == KERN_PROC_ALL)) X return (EINVAL); X p = (struct proc *)allproc; X doingzomb = 0; Xagain: X for (; p != NULL; p = p->p_nxt) { X /* X * Skip embryonic processes. X */ X if (p->p_stat == SIDL) X continue; X /* X * TODO - make more efficient (see notes below). X * do by session. X */ X switch (name[0]) { X X case KERN_PROC_PID: X /* could do this with just a lookup */ X if (p->p_pid != (pid_t)name[1]) X continue; X break; X X case KERN_PROC_PGRP: X /* could do this by traversing pgrp */ X if (p->p_pgrp != (pid_t)name[1]) X continue; X break; X X case KERN_PROC_TTY: X fill_from_u(p, &ruid, &ttyp, &ttyd); X if (!ttyp || ttyd != (dev_t)name[1]) X continue; X break; X X case KERN_PROC_UID: X if (p->p_uid != (uid_t)name[1]) X continue; X break; X X case KERN_PROC_RUID: X fill_from_u(p, &ruid, &ttyp, &ttyd); X if (ruid != (uid_t)name[1]) X continue; X break; X X case KERN_PROC_ALL: X break; X default: X return(EINVAL); X } X if (buflen >= sizeof(struct kinfo_proc)) { X fill_eproc(p, &eproc); X if (error = copyout((caddr_t)p, &dp->kp_proc, X sizeof(struct proc))) X return (error); X if (error = copyout((caddr_t)&eproc, &dp->kp_eproc, X sizeof(eproc))) X return (error); X dp++; X buflen -= sizeof(struct kinfo_proc); X } X needed += sizeof(struct kinfo_proc); X } X if (doingzomb == 0) { X p = zombproc; X doingzomb++; X goto again; X } X if (where != NULL) { X *sizep = (caddr_t)dp - where; X if (needed > *sizep) X return (ENOMEM); X } else { X needed += KERN_PROCSLOP; X *sizep = needed; X } X return (0); X} X X/* X * Fill in an eproc structure for the specified process. Slightly X * inefficient because we have to access the u area again for the X * information not kept in the proc structure itself. Can't afford X * to expand the proc struct so we take a slight speed hit here. X */ Xvoid Xfill_eproc(p, ep) X register struct proc *p; X register struct eproc *ep; X{ X struct tty *ttyp; X X ep->e_paddr = p; X fill_from_u(p, &ep->e_ruid, &ttyp, &ep->e_tdev); X if (ttyp) X ep->e_tpgid = ttyp->t_pgrp; X else X ep->e_tpgid = 0; X} X X/* X * Three pieces of information we need about a process are not kept in X * the proc table: real uid, controlling terminal device, and controlling X * terminal tty struct pointer. For these we must look in either the u X * area or the swap area. If the process is still in memory this is X * easy but if the process has been swapped out we have to read in the X * u area. X * X * XXX - We rely on the fact that u_ttyp, u_ttyd, and u_ruid are all within X * XXX - the first 1kb of the u area. If this ever changes the logic below X * XXX - will break (and badly). At the present time (1/19/95) the u area X * XXX - is 934 bytes long. X*/ X Xfill_from_u(p, rup, ttp, tdp) X struct proc *p; X uid_t *rup; X struct tty **ttp; X dev_t *tdp; X { X struct buf *bp; X dev_t ttyd; X uid_t ruid; X struct tty *ttyp; X struct user *up; X X if (p->p_flag & SLOAD) X { X mapseg5(p->p_addr, (((USIZE - 1) << 8) | RO)); X ttyd = ((struct user *)SEG5)->u_ttyd; X ttyp = ((struct user *)SEG5)->u_ttyp; X ruid = ((struct user *)SEG5)->u_ruid; X normalseg5(); X } X else X { X bp = bread(swapdev, (long)p->p_addr); X if (!bp) X { X ttyd = NODEV; X ttyp = NULL; X ruid = (uid_t)-2; X } X else X { X up = (struct user *)mapin(bp); X ruid = up->u_ruid; /* u_ruid = offset 164 */ X ttyd = up->u_ttyd; /* u_ttyd = offset 654 */ X ttyp = up->u_ttyp; /* u_ttyp = offset 652 */ X mapout(bp); X bp->b_flags |= B_AGE; X brelse(bp); X } X } X *rup = ruid; X *ttp = ttyp; X *tdp = ttyd; X return; X } SHAR_EOF chmod 644 '/usr/src/sys/sys/kern_sysctl.c' fi if test -f '/usr/src/sys/h/sysctl.h' then echo shar: "will not over-write existing file '/usr/src/sys/h/sysctl.h'" else sed 's/^X//' << \SHAR_EOF > '/usr/src/sys/h/sysctl.h' X/* X * Copyright (c) 1989, 1993 X * The Regents of the University of California. All rights reserved. X * X * This code is derived from software contributed to Berkeley by X * Mike Karels at Berkeley Software Design, Inc. X * X * Redistribution and use in source and binary forms, with or without X * modification, are permitted provided that the following conditions X * are met: X * 1. Redistributions of source code must retain the above copyright X * notice, this list of conditions and the following disclaimer. X * 2. Redistributions in binary form must reproduce the above copyright X * notice, this list of conditions and the following disclaimer in the X * documentation and/or other materials provided with the distribution. X * 3. All advertising materials mentioning features or use of this software X * must display the following acknowledgement: X * This product includes software developed by the University of X * California, Berkeley and its contributors. X * 4. Neither the name of the University nor the names of its contributors X * may be used to endorse or promote products derived from this software X * without specific prior written permission. X * X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE X * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF X * SUCH DAMAGE. X * X * @(#)sysctl.h 8.1.2 (2.11BSD GTE) 1/19/95 X */ X X#ifndef _SYS_SYSCTL_H_ X#define _SYS_SYSCTL_H_ X X/* X * These are for the eproc, etext, einode, efile and map structures. X */ X#ifndef KERNEL X#include X#include X#include X#include X#include X#include X#include X#include X#endif X X/* X * Definitions for sysctl call. The sysctl call uses a hierarchical name X * for objects that can be examined or modified. The name is expressed as X * a sequence of integers. Like a file path name, the meaning of each X * component depends on its place in the hierarchy. The top-level and kern X * identifiers are defined here, and other identifiers are defined in the X * respective subsystem header files. X */ X X#define CTL_MAXNAME 12 /* largest number of components supported */ X X/* X * Each subsystem defined by sysctl defines a list of variables X * for that subsystem. Each name is either a node with further X * levels defined below it, or it is a leaf of some particular X * type given below. Each sysctl level defines a set of name/type X * pairs to be used by sysctl(1) in manipulating the subsystem. X */ Xstruct ctlname { X char *ctl_name; /* subsystem name */ X int ctl_type; /* type of name */ X}; X#define CTLTYPE_NODE 1 /* name is a node */ X#define CTLTYPE_INT 2 /* name describes a 16-bit integer */ X#define CTLTYPE_STRING 3 /* name describes a string */ X#define CTLTYPE_LONG 4 /* name describes a 32-bit number */ X#define CTLTYPE_STRUCT 5 /* name describes a structure */ X X/* X * Top-level identifiers X */ X#define CTL_UNSPEC 0 /* unused */ X#define CTL_KERN 1 /* "high kernel": proc, limits */ X#define CTL_VM 2 /* virtual memory */ X#define CTL_FS 3 /* file system, mount type is next */ X#define CTL_NET 4 /* network, see socket.h */ X#define CTL_DEBUG 5 /* debugging parameters */ X#define CTL_HW 6 /* generic cpu/io */ X#define CTL_MACHDEP 7 /* machine dependent */ X#define CTL_USER 8 /* user-level */ X#define CTL_MAXID 9 /* number of valid top-level ids */ X X#ifndef KERNEL X#define CTL_NAMES { \ X { 0, 0 }, \ X { "kern", CTLTYPE_NODE }, \ X { "vm", CTLTYPE_NODE }, \ X { "fs", CTLTYPE_NODE }, \ X { "net", CTLTYPE_NODE }, \ X { "debug", CTLTYPE_NODE }, \ X { "hw", CTLTYPE_NODE }, \ X { "machdep", CTLTYPE_NODE }, \ X { "user", CTLTYPE_NODE }, \ X} X#endif X X/* X * CTL_KERN identifiers X */ X#define KERN_OSTYPE 1 /* string: system version */ X#define KERN_OSRELEASE 2 /* string: system release */ X#define KERN_OSREV 3 /* int: system revision */ X#define KERN_VERSION 4 /* string: compile time info */ X#define KERN_MAXINODES 5 /* int: max inodes */ X#define KERN_MAXPROC 6 /* int: max processes */ X#define KERN_MAXFILES 7 /* int: max open files */ X#define KERN_ARGMAX 8 /* int: max arguments to exec */ X#define KERN_SECURELVL 9 /* int: system security level */ X#define KERN_HOSTNAME 10 /* string: hostname */ X#define KERN_HOSTID 11 /* int: host identifier */ X#define KERN_CLOCKRATE 12 /* struct: struct clockrate */ X#define KERN_INODE 13 /* struct: inode structures */ X#define KERN_PROC 14 /* struct: process entries */ X#define KERN_FILE 15 /* struct: file entries */ X#define KERN_PROF 16 /* node: kernel profiling info */ X#define KERN_POSIX1 17 /* int: POSIX.1 version */ X#define KERN_NGROUPS 18 /* int: # of supplemental group ids */ X#define KERN_JOB_CONTROL 19 /* int: is job control available */ X#define KERN_SAVED_IDS 20 /* int: saved set-user/group-ID */ X#define KERN_BOOTTIME 21 /* struct: time kernel was booted */ X#define KERN_MAXTEXTS 22 /* int: # of text entries */ X#define KERN_TEXT 23 /* struct: text entries */ X#define KERN_MAXID 24 /* number of valid kern ids */ X X#ifndef KERNEL X#define CTL_KERN_NAMES { \ X { 0, 0 }, \ X { "ostype", CTLTYPE_STRING }, \ X { "osrelease", CTLTYPE_STRING }, \ X { "osrevision", CTLTYPE_LONG }, \ X { "version", CTLTYPE_STRING }, \ X { "maxinodes", CTLTYPE_INT }, \ X { "maxproc", CTLTYPE_INT }, \ X { "maxfiles", CTLTYPE_INT }, \ X { "argmax", CTLTYPE_INT }, \ X { "securelevel", CTLTYPE_INT }, \ X { "hostname", CTLTYPE_STRING }, \ X { "hostid", CTLTYPE_LONG }, \ X { "clockrate", CTLTYPE_STRUCT }, \ X { "inode", CTLTYPE_STRUCT }, \ X { "proc", CTLTYPE_STRUCT }, \ X { "file", CTLTYPE_STRUCT }, \ X { "profiling", CTLTYPE_NODE }, \ X { "posix1version", CTLTYPE_INT }, \ X { "ngroups", CTLTYPE_INT }, \ X { "job_control", CTLTYPE_INT }, \ X { "saved_ids", CTLTYPE_INT }, \ X { "boottime", CTLTYPE_STRUCT }, \ X { "maxtexts", CTLTYPE_INT }, \ X { "text", CTLTYPE_STRUCT }, \ X} X#endif X X/* X * KERN_PROC subtypes X */ X#define KERN_PROC_ALL 0 /* everything */ X#define KERN_PROC_PID 1 /* by process id */ X#define KERN_PROC_PGRP 2 /* by process group id */ X#define KERN_PROC_SESSION 3 /* by session of pid - NOT IN 2.11 */ X#define KERN_PROC_TTY 4 /* by controlling tty */ X#define KERN_PROC_UID 5 /* by effective uid */ X#define KERN_PROC_RUID 6 /* by real uid */ X X/* X * KERN_PROC subtype ops return arrays of augmented proc structures: X */ Xstruct kinfo_proc { X struct proc kp_proc; /* proc structure */ X struct eproc { X struct proc *e_paddr; /* address of proc */ X dev_t e_tdev; /* controlling tty dev */ X pid_t e_tpgid; /* tty process group id */ X uid_t e_ruid; /* real uid */ X } kp_eproc; X}; X X/* X * KERN_TEXT op returns array of augmented text structures: X*/ Xstruct kinfo_text { X struct text *kp_textp; /* address of text */ X struct text kp_text; /* text structure */ X}; X X/* X * KERN_INODE returns an array of augmented inode structures: X*/ Xstruct kinfo_inode { X struct inode *kp_inodep; /* address of inode */ X struct inode kp_inode; /* inode structure */ X}; X X/* X * KERN_FILE returns an array of augmented file structures: X*/ Xstruct kinfo_file { X struct file *kp_filep; /* address of file */ X struct file kp_file; /* file structure */ X}; X X/* X * CTL_HW identifiers X */ X#define HW_MACHINE 1 /* string: machine class */ X#define HW_MODEL 2 /* string: specific machine model */ X#define HW_NCPU 3 /* int: number of cpus */ X#define HW_BYTEORDER 4 /* int: machine byte order */ X#define HW_PHYSMEM 5 /* int: total memory */ X#define HW_USERMEM 6 /* int: non-kernel memory */ X#define HW_PAGESIZE 7 /* int: software page size */ X#define HW_DISKNAMES 8 /* strings: disk drive names */ X#define HW_DISKSTATS 9 /* struct: diskstats[] */ X#define HW_MAXID 10 /* number of valid hw ids */ X X#ifndef KERNEL X#define CTL_HW_NAMES { \ X { 0, 0 }, \ X { "machine", CTLTYPE_STRING }, \ X { "model", CTLTYPE_STRING }, \ X { "ncpu", CTLTYPE_INT }, \ X { "byteorder", CTLTYPE_INT }, \ X { "physmem", CTLTYPE_LONG }, \ X { "usermem", CTLTYPE_LONG }, \ X { "pagesize", CTLTYPE_INT }, \ X { "disknames", CTLTYPE_STRUCT }, \ X { "diskstats", CTLTYPE_STRUCT }, \ X} X#endif X X#ifndef KERNEL X/* X * CTL_USER definitions X */ X#define USER_CS_PATH 1 /* string: _CS_PATH */ X#define USER_BC_BASE_MAX 2 /* int: BC_BASE_MAX */ X#define USER_BC_DIM_MAX 3 /* int: BC_DIM_MAX */ X#define USER_BC_SCALE_MAX 4 /* int: BC_SCALE_MAX */ X#define USER_BC_STRING_MAX 5 /* int: BC_STRING_MAX */ X#define USER_COLL_WEIGHTS_MAX 6 /* int: COLL_WEIGHTS_MAX */ X#define USER_EXPR_NEST_MAX 7 /* int: EXPR_NEST_MAX */ X#define USER_LINE_MAX 8 /* int: LINE_MAX */ X#define USER_RE_DUP_MAX 9 /* int: RE_DUP_MAX */ X#define USER_POSIX2_VERSION 10 /* int: POSIX2_VERSION */ X#define USER_POSIX2_C_BIND 11 /* int: POSIX2_C_BIND */ X#define USER_POSIX2_C_DEV 12 /* int: POSIX2_C_DEV */ X#define USER_POSIX2_CHAR_TERM 13 /* int: POSIX2_CHAR_TERM */ X#define USER_POSIX2_FORT_DEV 14 /* int: POSIX2_FORT_DEV */ X#define USER_POSIX2_FORT_RUN 15 /* int: POSIX2_FORT_RUN */ X#define USER_POSIX2_LOCALEDEF 16 /* int: POSIX2_LOCALEDEF */ X#define USER_POSIX2_SW_DEV 17 /* int: POSIX2_SW_DEV */ X#define USER_POSIX2_UPE 18 /* int: POSIX2_UPE */ X#define USER_STREAM_MAX 19 /* int: POSIX2_STREAM_MAX */ X#define USER_TZNAME_MAX 20 /* int: POSIX2_TZNAME_MAX */ X#define USER_MAXID 21 /* number of valid user ids */ X X#define CTL_USER_NAMES { \ X { 0, 0 }, \ X { "cs_path", CTLTYPE_STRING }, \ X { "bc_base_max", CTLTYPE_INT }, \ X { "bc_dim_max", CTLTYPE_INT }, \ X { "bc_scale_max", CTLTYPE_INT }, \ X { "bc_string_max", CTLTYPE_INT }, \ X { "coll_weights_max", CTLTYPE_INT }, \ X { "expr_nest_max", CTLTYPE_INT }, \ X { "line_max", CTLTYPE_INT }, \ X { "re_dup_max", CTLTYPE_INT }, \ X { "posix2_version", CTLTYPE_INT }, \ X { "posix2_c_bind", CTLTYPE_INT }, \ X { "posix2_c_dev", CTLTYPE_INT }, \ X { "posix2_char_term", CTLTYPE_INT }, \ X { "posix2_fort_dev", CTLTYPE_INT }, \ X { "posix2_fort_run", CTLTYPE_INT }, \ X { "posix2_localedef", CTLTYPE_INT }, \ X { "posix2_sw_dev", CTLTYPE_INT }, \ X { "posix2_upe", CTLTYPE_INT }, \ X { "stream_max", CTLTYPE_INT }, \ X { "tzname_max", CTLTYPE_INT }, \ X} X#endif X X/* X * CTL_DEBUG definitions X * X * Second level identifier specifies which debug variable. X * Third level identifier specifies which stucture component. X */ X#define CTL_DEBUG_NAME 0 /* string: variable name */ X#define CTL_DEBUG_VALUE 1 /* int: variable value */ X#define CTL_DEBUG_MAXID 20 X X#ifdef KERNEL X#ifdef DEBUG X/* X * CTL_DEBUG variables. X * X * These are declared as separate variables so that they can be X * individually initialized at the location of their associated X * variable. The loader prevents multiple use by issuing errors X * if a variable is initialized in more than one place. They are X * aggregated into an array in debug_sysctl(), so that it can X * conveniently locate them when querried. If more debugging X * variables are added, they must also be declared here and also X * entered into the array. X */ Xstruct ctldebug { X char *debugname; /* name of debugging variable */ X int *debugvar; /* pointer to debugging variable */ X}; Xextern struct ctldebug debug0, debug1, debug2, debug3, debug4; Xextern struct ctldebug debug5, debug6, debug7, debug8, debug9; Xextern struct ctldebug debug10, debug11, debug12, debug13, debug14; Xextern struct ctldebug debug15, debug16, debug17, debug18, debug19; X#endif /* DEBUG */ X X/* X * Internal sysctl function calling convention: X * X * (*sysctlfn)(name, namelen, oldval, oldlenp, newval, newlen); X * X * The name parameter points at the next component of the name to be X * interpreted. The namelen parameter is the number of integers in X * the name. X */ Xtypedef int (sysctlfn)(); X Xint sysctl_int(); Xint sysctl_rdint(); Xint sysctl_string(); Xint sysctl_rdstring(); Xint sysctl_rdstruct(); Xvoid fill_eproc(); X X#else /* !KERNEL */ X Xint sysctl(); X#endif /* KERNEL */ X#endif /* !_SYS_SYSCTL_H_ */ SHAR_EOF chmod 644 '/usr/src/sys/h/sysctl.h' fi if test ! -d '/usr/src/bin/sysctl' then mkdir '/usr/src/bin/sysctl' fi cd '/usr/src/bin/sysctl' if test -f 'Makefile' then echo shar: "will not over-write existing file 'Makefile'" else sed 's/^X//' << \SHAR_EOF > 'Makefile' X# X# Public Domain. 1/15/1995 - Steven Schultz X# X# @(#)Makefile 1.0 (2.11BSD GTE) 1/15/95 X# XCFLAGS= -O XSEPFLAG= -i XVPATH= ../ls XSRCS= sysctl.c strsep.c XOBJS= sysctl.o strsep.o XMAN= sysctl.0 XMANSRC= sysctl.8 X Xall: sysctl sysctl.0 X Xsysctl: ${OBJS} X ${CC} ${CFLAGS} ${SEPFLAG} -o $@ ${OBJS} X Xsysctl.0: ${MANSRC} X /usr/man/manroff ${MANSRC} > ${MAN} X Xclean: X rm -f ${OBJS} ${MAN} sysctl tags X Xdepend: ${SRCS} X mkdep ${CFLAGS} ${SRCS} X Xinstall: sysctl X install -c -o bin -g bin -m 444 ${MAN} ${DESTDIR}/usr/man/cat8 X install -s -o root -g bin -m 755 sysctl ${DESTDIR}/bin/sysctl X Xlint: ${SRCS} X lint -hax ${SRCS} X Xtags: ${SRCS} X ctags ${SRCS} X# DO NOT DELETE THIS LINE -- mkdep uses it. X# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY. SHAR_EOF chmod 644 'Makefile' fi if test -f 'sysctl.8' then echo shar: "will not over-write existing file 'sysctl.8'" else sed 's/^X//' << \SHAR_EOF > 'sysctl.8' X.\" Copyright (c) 1993 X.\" The Regents of the University of California. All rights reserved. X.\" X.\" Redistribution and use in source and binary forms, with or without X.\" modification, are permitted provided that the following conditions X.\" are met: X.\" 1. Redistributions of source code must retain the above copyright X.\" notice, this list of conditions and the following disclaimer. X.\" 2. Redistributions in binary form must reproduce the above copyright X.\" notice, this list of conditions and the following disclaimer in the X.\" documentation and/or other materials provided with the distribution. X.\" 3. All advertising materials mentioning features or use of this software X.\" must display the following acknowledgement: X.\" This product includes software developed by the University of X.\" California, Berkeley and its contributors. X.\" 4. Neither the name of the University nor the names of its contributors X.\" may be used to endorse or promote products derived from this software X.\" without specific prior written permission. X.\" X.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND X.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE X.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE X.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE X.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL X.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS X.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) X.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT X.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY X.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF X.\" SUCH DAMAGE. X.\" X.\" @(#)sysctl.8 8.1.2 (2.11BSD GTE) 1/19/95 X.\" X.TH SYSCTL 8 "June 6, 1993" X.UC 4 X.SH NAME Xsysctl \- get or set kernel state X.SH SYNOPSIS X.B sysctl X[ X.B \-n X] X.I name ... X.br X.B sysctl X[ X.B \-n X] X.B \-w X.I name=value ... X.br X.B sysctl X[ X.B \-n X] X.B \-aA X.SH DESCRIPTION XThe X.B sysctl Xutility retrieves kernel state and allows processes with Xappropriate privilege to set kernel state. XThe state to be retrieved or set is described using a X``Management Information Base'' (``MIB'') style name, Xdescribed as a dotted set of components. XThe X.B \-a Xflag can be used to list all the currently available string or integer values. XThe X.B \-A Xflag will list all the known MIB names including tables. XThose with string or integer values will be printed as with the X.B \-a Xflag; for the table values, Xthe name of the utility to retrieve them is given. X.PP XThe X.B \-n Xflag specifies that the printing of the field name should be Xsuppressed and that only its value should be output. XThis flag is useful for setting shell variables. XFor example, to save the pagesize in variable psize, use: X.sp X.in +1.0 Xset psize=`sysctl -n hw.pagesize` X.in -1.0 X.PP XIf just a MIB style name is given, Xthe corresponding value is retrieved. XIf a value is to be set, the X.B \-w Xflag must be specified and the MIB name followed Xby an equal sign and the new value to be used. X.PP XThe information available from X.B sysctl Xconsists of integers, strings, and tables. XThe tabular information can only be retrieved by special Xpurpose programs such as X\fBps\fP, X\fBsystat\fP, Xand X\fBnetstat\fP. XThe string and integer information is summaried below. XFor a detailed description of these variable see X\fBsysctl(3)\fP. XThe changeable column indicates whether a process with appropriate Xprivilege can change the value. X.sp X.ta 0.5i 3.0i 4.0i X.nf X Name Type Changeable X kern.ostype string no X kern.osrelease string no X kern.osrevision long no X kern.version string no X kern.maxinodes integer no X kern.maxproc integer no X kern.maxfiles integer no X kern.maxtext integer no X kern.argmax integer no X kern.securelevel integer raise only X kern.hostname string yes X kern.hostid long yes X kern.clockrate struct no X kern.posix1version integer no X kern.ngroups integer no X kern.job_control integer no X kern.saved_ids integer no X.\" kern.link_max integer no X.\" kern.max_canon integer no X.\" kern.max_input integer no X.\" kern.name_max integer no X.\" kern.path_max integer no X.\" kern.pipe_buf integer no X.\" kern.chown_restricted integer no X.\" kern.no_trunc integer no X.\" kern.vdisable integer no X kern.boottime struct no X vm.loadavg struct no X machdep.console_device dev_t no X net.inet.ip.forwarding integer yes X net.inet.ip.redirect integer yes X net.inet.ip.ttl integer yes X net.inet.icmp.maskrepl integer yes X net.inet.udp.checksum integer yes X hw.machine string no X hw.model string no X hw.ncpu integer no X hw.byteorder integer no X hw.physmem long no X hw.usermem long no X hw.pagesize integer no X user.cs_path string no X user.bc_base_max integer no X user.bc_dim_max integer no X user.bc_scale_max integer no X user.bc_string_max integer no X user.coll_weights_max integer no X user.expr_nest_max integer no X user.line_max integer no X user.re_dup_max integer no X user.posix2_version integer no X user.posix2_c_bind integer no X user.posix2_c_dev integer no X user.posix2_char_term integer no X user.posix2_fort_dev integer no X user.posix2_fort_run integer no X user.posix2_localedef integer no X user.posix2_sw_dev integer no X user.posix2_upe integer no X.fi X.SH EXAMPLES X.PP XFor example, to retrieve the maximum number of processes allowed Xin the system, one would use the follow request: X.sp X.in +1.0i Xsysctl kern.maxproc X.br X.in -1.0i X.PP XTo set the hostname of the system Xto foo.bar.com, one would use the follow request: X.sp X.in +1.0i Xsysctl -w kern.hostname=foo.bar.com X.in -1.0i X.br X.PP XInformation about the system clock rate may be obtained with: X.sp X.in +1.0i Xsysctl kern.clockrate X.br X.in -1.0i X.PP XInformation about the load average history may be obtained with X.sp X.in +1.0i Xsysctl vm.loadavg X.br X.in -1.0i X.SH FILES X.TP 15 X Xdefinitions for top level identifiers, second level kernel and hardware Xidentifiers, and user level identifiers X.TP 15 X Xdefinitions for second level network identifiers X.TP 15 X Xdefinitions for third level profiling identifiers X.TP 15 X Xdefinitions for second level virtual memory identifiers X.TP 15 X Xdefinitions for third level Internet identifiers and Xfourth level IP identifiers X.TP 15 X Xdefinitions for fourth level ICMP identifiers X.TP 15 X Xdefinitions for fourth level UDP identifiers X.SH SEE ALSO Xsysctl(3) X.SH HISTORY X.B sysctl Xfirst appeared in 4.4BSD. SHAR_EOF chmod 644 'sysctl.8' fi if test -f 'sysctl.c' then echo shar: "will not over-write existing file 'sysctl.c'" else sed 's/^X//' << \SHAR_EOF > 'sysctl.c' X/* X * Copyright (c) 1993 X * The Regents of the University of California. All rights reserved. X * X * Redistribution and use in source and binary forms, with or without X * modification, are permitted provided that the following conditions X * are met: X * 1. Redistributions of source code must retain the above copyright X * notice, this list of conditions and the following disclaimer. X * 2. Redistributions in binary form must reproduce the above copyright X * notice, this list of conditions and the following disclaimer in the X * documentation and/or other materials provided with the distribution. X * 3. All advertising materials mentioning features or use of this software X * must display the following acknowledgement: X * This product includes software developed by the University of X * California, Berkeley and its contributors. X * 4. Neither the name of the University nor the names of its contributors X * may be used to endorse or promote products derived from this software X * without specific prior written permission. X * X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE X * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF X * SUCH DAMAGE. X */ X X#if !defined(lint) && defined(DOSCCS) Xstatic char copyright[] = X"@(#) Copyright (c) 1993\n\ X The Regents of the University of California. All rights reserved.\n"; X Xstatic char sccsid[] = "@(#)sysctl.c 8.1.1 (2.11BSD GTE) 1/12/95"; X#endif /* not lint */ X X#include X#include X#include X#include X#include X X#include X#include X#include X#include X#include X#include X#include X#include X X#include X#include X#include X#include X Xstruct ctlname topname[] = CTL_NAMES; Xstruct ctlname kernname[] = CTL_KERN_NAMES; Xstruct ctlname vmname[] = CTL_VM_NAMES; X#ifdef CTL_NET_NAMES Xstruct ctlname netname[] = CTL_NET_NAMES; X#endif Xstruct ctlname hwname[] = CTL_HW_NAMES; Xstruct ctlname username[] = CTL_USER_NAMES; Xstruct ctlname debugname[CTL_DEBUG_MAXID]; X#ifdef CTL_MACHDEP_NAMES Xstruct ctlname machdepname[] = CTL_MACHDEP_NAMES; X#endif Xchar names[BUFSIZ]; X Xstruct list { X struct ctlname *list; X int size; X}; Xstruct list toplist = { topname, CTL_MAXID }; Xstruct list secondlevel[] = { X { 0, 0 }, /* CTL_UNSPEC */ X { kernname, KERN_MAXID }, /* CTL_KERN */ X { vmname, VM_MAXID }, /* CTL_VM */ X { 0, 0 }, /* CTL_FS */ X#ifdef CTL_NET_NAMES X { netname, NET_MAXID }, /* CTL_NET */ X#else X { 0, 0 }, X#endif X { 0, CTL_DEBUG_MAXID }, /* CTL_DEBUG */ X { hwname, HW_MAXID }, /* CTL_HW */ X#ifdef CTL_MACHDEP_NAMES X { machdepname, CPU_MAXID }, /* CTL_MACHDEP */ X#else X { 0, 0 }, /* CTL_MACHDEP */ X#endif X { username, USER_MAXID }, /* CTL_USER_NAMES */ X}; X Xint Aflag, aflag, nflag, wflag; X Xextern char *optarg; Xextern int optind, errno; X X/* X * Variables requiring special processing. X */ X#define CLOCK 0x0001 X#define BOOTTIME 0x0002 X#define CONSDEV 0x0004 X Xint Xmain(argc, argv) X int argc; X char *argv[]; X{ X int ch, lvl1; X X while ((ch = getopt(argc, argv, "Aanw")) != EOF) { X switch (ch) { X X case 'A': X Aflag = 1; X break; X X case 'a': X aflag = 1; X break; X X case 'n': X nflag = 1; X break; X X case 'w': X wflag = 1; X break; X X default: X usage(); X } X } X argc -= optind; X argv += optind; X X if (Aflag || aflag) { X debuginit(); X for (lvl1 = 1; lvl1 < CTL_MAXID; lvl1++) X listall(topname[lvl1].ctl_name, &secondlevel[lvl1]); X exit(0); X } X if (argc == 0) X usage(); X while (argc-- > 0) X parse(*argv, 1); X exit(0); X} X X/* X * List all variables known to the system. X */ Xlistall(prefix, lp) X char *prefix; X struct list *lp; X{ X int lvl2; X char *cp, name[BUFSIZ]; X X if (lp->list == 0) X return; X strcpy(name, prefix); X cp = &name[strlen(name)]; X *cp++ = '.'; X for (lvl2 = 0; lvl2 < lp->size; lvl2++) { X if (lp->list[lvl2].ctl_name == 0) X continue; X strcpy(cp, lp->list[lvl2].ctl_name); X parse(name, Aflag); X } X} X X/* X * Parse a name into a MIB entry. X * Lookup and print out the MIB entry if it exists. X * Set a new value if requested. X */ Xparse(string, flags) X char *string; X int flags; X{ X int indx, type, state, size, len; X int special = 0; X void *newval = (void *)0; X int intval, newsize = 0; X long longval; X struct list *lp; X int mib[CTL_MAXNAME]; X char *cp, *bufp, buf[BUFSIZ], strval[BUFSIZ]; X X bufp = buf; X strcpy(buf, string); X if ((cp = strchr(string, '=')) != NULL) { X if (!wflag) { X fprintf(stderr, "Must specify -w to set variables\n"); X exit(2); X } X *strchr(buf, '=') = '\0'; X *cp++ = '\0'; X while (isspace(*cp)) X cp++; X newval = (void *)cp; X newsize = strlen(cp); X } X if ((indx = findname(string, "top", &bufp, &toplist)) == -1) X return; X mib[0] = indx; X if (indx == CTL_DEBUG) X debuginit(); X lp = &secondlevel[indx]; X if (lp->list == 0) { X fprintf(stderr, "%s: class is not implemented\n", X topname[indx]); X return; X } X if (bufp == NULL) { X listall(topname[indx].ctl_name, lp); X return; X } X if ((indx = findname(string, "second", &bufp, lp)) == -1) X return; X mib[1] = indx; X type = lp->list[indx].ctl_type; X len = 2; X switch (mib[0]) { X X case CTL_KERN: X switch (mib[1]) { X case KERN_PROF: X fprintf(stderr, X "kern.prof = not supported in 2.11BSD\n"); X return; X case KERN_INODE: X case KERN_FILE: X case KERN_TEXT: X if (flags == 0) X return; X fprintf(stderr, X "Use pstat to view %s information\n", string); X return; X case KERN_PROC: X if (flags == 0) X return; X fprintf(stderr, X "Use ps to view %s information\n", string); X return; X case KERN_CLOCKRATE: X special |= CLOCK; X break; X case KERN_BOOTTIME: X special |= BOOTTIME; X break; X } X break; X X case CTL_HW: X break; X X case CTL_VM: X if (mib[1] == VM_LOADAVG) { X double loads[3]; X X getloadavg(loads, 3); X if (!nflag) X fprintf(stdout, "%s: ", string); X fprintf(stdout, "%.2f %.2f %.2f\n", X loads[0], loads[1], loads[2]); X return; X } X if (flags == 0) X return; X fprintf(stderr, X "Use vmstat or pstat to view %s information\n", string); X return; X X case CTL_NET: X#ifdef notyet X if (mib[1] == PF_INET) { X len = sysctl_inet(string, &bufp, mib, flags, &type); X if (len >= 0) X break; X return; X } X#endif X if (flags == 0) X return; X fprintf(stderr, "Use netstat to view %s information\n", string); X return; X X case CTL_DEBUG: X mib[2] = CTL_DEBUG_VALUE; X len = 3; X break; X X case CTL_MACHDEP: X#ifdef CPU_CONSDEV X if (mib[1] == CPU_CONSDEV) X special |= CONSDEV; X#endif X break; X X case CTL_FS: X case CTL_USER: X break; X X default: X fprintf(stderr, "Illegal top level value: %d\n", mib[0]); X return; X X } X if (bufp) { X fprintf(stderr, "name %s in %s is unknown\n", *bufp, string); X return; X } X if (newsize > 0) { X switch (type) { X case CTLTYPE_INT: X intval = atoi(newval); X newval = (void *)&intval; X newsize = sizeof intval; X break; X X case CTLTYPE_LONG: X sscanf(newval, "%ld", &longval); X newval = (void *)&longval; X newsize = sizeof longval; X break; X } X } X size = BUFSIZ; X if (sysctl(mib, len, buf, &size, newsize ? newval : (void *)0, newsize) == -1) { X if (flags == 0) X return; X switch (errno) { X case EOPNOTSUPP: X fprintf(stderr, "%s: value is not available\n", string); X return; X case ENOTDIR: X fprintf(stderr, "%s: specification is incomplete\n", X string); X return; X case ENOMEM: X fprintf(stderr, "%s: type is unknown to this program\n", X string); X return; X default: X perror(string); X return; X } X } X if (special & CLOCK) { X struct clockinfo *clkp = (struct clockinfo *)buf; X X if (!nflag) X fprintf(stdout, "%s: ", string); X fprintf(stdout, X "hz = %d, tick = %d, profhz = %d, stathz = %d\n", X clkp->hz, clkp->tick, clkp->profhz, clkp->stathz); X return; X } X if (special & BOOTTIME) { X struct timeval *btp = (struct timeval *)buf; X X if (!nflag) X fprintf(stdout, "%s = %s", string, X ctime(&btp->tv_sec)); X else X fprintf(stdout, "%d\n", btp->tv_sec); X return; X } X if (special & CONSDEV) { X dev_t dev = *(dev_t *)buf; X X if (!nflag) X fprintf(stdout, "%s = %s\n", string, X#ifdef notyet X devname(dev, S_IFCHR)); X#else X "/dev/console"); X#endif X else X fprintf(stdout, "0x%x\n", dev); X return; X } X switch (type) { X case CTLTYPE_INT: X if (newsize == 0) { X if (!nflag) X fprintf(stdout, "%s = ", string); X fprintf(stdout, "%d\n", *(int *)buf); X } else { X if (!nflag) X fprintf(stdout, "%s: %d -> ", string, X *(int *)buf); X fprintf(stdout, "%d\n", *(int *)newval); X } X return; X X case CTLTYPE_STRING: X if (newsize == 0) { X if (!nflag) X fprintf(stdout, "%s = ", string); X fprintf(stdout, "%s\n", buf); X } else { X if (!nflag) X fprintf(stdout, "%s: %s -> ", string, buf); X fprintf(stdout, "%s\n", newval); X } X return; X X case CTLTYPE_LONG: X if (newsize == 0) { X if (!nflag) X fprintf(stdout, "%s = ", string); X fprintf(stdout, "%ld\n", *(long *)buf); X } else { X if (!nflag) X fprintf(stdout, "%s: %ld -> ", string, X *(long *)buf); X fprintf(stdout, "%ld\n", *(long *)newval); X } X return; X X case CTLTYPE_STRUCT: X fprintf(stderr, "%s: unknown structure returned\n", X string); X return; X X default: X case CTLTYPE_NODE: X fprintf(stderr, "%s: unknown type returned\n", X string); X return; X } X} X X/* X * Initialize the set of debugging names X */ Xdebuginit() X{ X int mib[3], size, loc, i; X X if (secondlevel[CTL_DEBUG].list != 0) X return; X secondlevel[CTL_DEBUG].list = debugname; X mib[0] = CTL_DEBUG; X mib[2] = CTL_DEBUG_NAME; X for (loc = 0, i = 0; i < CTL_DEBUG_MAXID; i++) { X mib[1] = i; X size = BUFSIZ - loc; X if (sysctl(mib, 3, &names[loc], &size, NULL, 0) == -1) X continue; X debugname[i].ctl_name = &names[loc]; X debugname[i].ctl_type = CTLTYPE_INT; X loc += size; X } X} X X#ifdef notyet X Xstruct ctlname inetname[] = CTL_IPPROTO_NAMES; Xstruct ctlname ipname[] = IPCTL_NAMES; Xstruct ctlname icmpname[] = ICMPCTL_NAMES; Xstruct ctlname udpname[] = UDPCTL_NAMES; Xstruct list inetlist = { inetname, IPPROTO_MAXID }; Xstruct list inetvars[] = { X { ipname, IPCTL_MAXID }, /* ip */ X { icmpname, ICMPCTL_MAXID }, /* icmp */ X { 0, 0 }, /* igmp */ X { 0, 0 }, /* ggmp */ X { 0, 0 }, X { 0, 0 }, X { 0, 0 }, /* tcp */ X { 0, 0 }, X { 0, 0 }, /* egp */ X { 0, 0 }, X { 0, 0 }, X { 0, 0 }, X { 0, 0 }, /* pup */ X { 0, 0 }, X { 0, 0 }, X { 0, 0 }, X { 0, 0 }, X { udpname, UDPCTL_MAXID }, /* udp */ X}; X X/* X * handle internet requests X */ Xsysctl_inet(string, bufpp, mib, flags, typep) X char *string; X char **bufpp; X int mib[]; X int flags; X int *typep; X{ X struct list *lp; X int indx; X X if (*bufpp == NULL) { X listall(string, &inetlist); X return (-1); X } X if ((indx = findname(string, "third", bufpp, &inetlist)) == -1) X return (-1); X mib[2] = indx; X if (indx <= IPPROTO_UDP && inetvars[indx].list != NULL) X lp = &inetvars[indx]; X else if (!flags) X return (-1); X else { X fprintf(stderr, "%s: no variables defined for this protocol\n", X string); X return (-1); X } X if (*bufpp == NULL) { X listall(string, lp); X return (-1); X } X if ((indx = findname(string, "fourth", bufpp, lp)) == -1) X return (-1); X mib[3] = indx; X *typep = lp->list[indx].ctl_type; X return (4); X} X#endif /* notyet */ X X/* X * Scan a list of names searching for a particular name. X */ Xfindname(string, level, bufp, namelist) X char *string; X char *level; X char **bufp; X struct list *namelist; X{ X char *name; X int i; X X if (namelist->list == 0 || (name = strsep(bufp, ".")) == NULL) { X fprintf(stderr, "%s: incomplete specification\n", string); X return (-1); X } X for (i = 0; i < namelist->size; i++) X if (namelist->list[i].ctl_name != NULL && X strcmp(name, namelist->list[i].ctl_name) == 0) X break; X if (i == namelist->size) { X fprintf(stderr, "%s level name %s in %s is invalid\n", X level, name, string); X return (-1); X } X return (i); X} X Xusage() X{ X X (void)fprintf(stderr, "usage:\t%s\n\t%s\n\t%s\n\t%s\n", X "sysctl [-n] variable ...", "sysctl [-n] -w variable=value ...", X "sysctl [-n] -a", "sysctl [-n] -A"); X exit(1); X} SHAR_EOF chmod 644 'sysctl.c' fi chmod 755 . cd .. if test -f '/usr/src/lib/libc/gen/sysctl.c' then echo shar: "will not over-write existing file '/usr/src/lib/libc/gen/sysctl.c'" else sed 's/^X//' << \SHAR_EOF > '/usr/src/lib/libc/gen/sysctl.c' X/*- X * Copyright (c) 1993 X * The Regents of the University of California. All rights reserved. X * X * Redistribution and use in source and binary forms, with or without X * modification, are permitted provided that the following conditions X * are met: X * 1. Redistributions of source code must retain the above copyright X * notice, this list of conditions and the following disclaimer. X * 2. Redistributions in binary form must reproduce the above copyright X * notice, this list of conditions and the following disclaimer in the X * documentation and/or other materials provided with the distribution. X * 3. All advertising materials mentioning features or use of this software X * must display the following acknowledgement: X * This product includes software developed by the University of X * California, Berkeley and its contributors. X * 4. Neither the name of the University nor the names of its contributors X * may be used to endorse or promote products derived from this software X * without specific prior written permission. X * X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE X * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF X * SUCH DAMAGE. X */ X X#if defined(LIBC_SCCS) && !defined(lint) Xstatic char sccsid[] = "@(#)sysctl.c 8.2.1 (2.11BSD GTE) 1/7/95"; X#endif /* LIBC_SCCS and not lint */ X X#include X#include X#include X#include X Xextern int errno; Xstatic Xchar _PATH_STDPATH[]="/usr/bin:/bin:/usr/ucb:/usr/local:/usr/new:/etc"; X X Xint Xsysctl(name, namelen, oldp, oldlenp, newp, newlen) X int *name; X u_int namelen; X void *oldp, *newp; X size_t *oldlenp, newlen; X{ X if (name[0] != CTL_USER) X return (__sysctl(name, namelen, oldp, oldlenp, newp, newlen)); X X if (newp != NULL) { X errno = EPERM; X return (-1); X } X if (namelen != 2) { X errno = EINVAL; X return (-1); X } X X/* X * This idea behind this section is silly. Other than 'bc' who cares about X * half of these? A 3/4 hearted attempt is made however to return numbers X * that are not totally bogus. X * X * Rather than port over the raft of include files with the attendant plethora X * of #define statements we just plug in the numbers from 4.4-Lite. X */ X X switch (name[1]) { X case USER_CS_PATH: X if (oldp && *oldlenp < sizeof(_PATH_STDPATH)) X return (ENOMEM); X *oldlenp = sizeof(_PATH_STDPATH); X if (oldp != NULL) X strcpy(oldp, _PATH_STDPATH); X return (0); X } X X if (oldp && *oldlenp < sizeof(int)) X return (ENOMEM); X *oldlenp = sizeof(int); X if (oldp == NULL) X return (0); X X switch (name[1]) { X case USER_BC_BASE_MAX: X case USER_BC_SCALE_MAX: X *(int *)oldp = 99; X return (0); X case USER_BC_DIM_MAX: X *(int *)oldp = 2048; X return (0); X case USER_BC_STRING_MAX: X *(int *)oldp = 1000; X return (0); X case USER_EXPR_NEST_MAX: X *(int *)oldp = 32; X return (0); X case USER_LINE_MAX: X *(int *)oldp = 1024; X return (0); X case USER_RE_DUP_MAX: X *(int *)oldp = 255; X return (0); X case USER_COLL_WEIGHTS_MAX: X case USER_POSIX2_VERSION: X case USER_POSIX2_C_BIND: X case USER_POSIX2_C_DEV: X case USER_POSIX2_CHAR_TERM: X case USER_POSIX2_FORT_DEV: X case USER_POSIX2_FORT_RUN: X case USER_POSIX2_LOCALEDEF: X case USER_POSIX2_SW_DEV: X case USER_POSIX2_UPE: X *(int *)oldp = 0; X return (0); X case USER_STREAM_MAX: X *(int *)oldp = 20; X return (0); X case USER_TZNAME_MAX: X *(int *)oldp = 63; X return (0); X default: X errno = EINVAL; X return (-1); X } X /* NOTREACHED */ X} SHAR_EOF chmod 644 '/usr/src/lib/libc/gen/sysctl.c' fi if test -f '/usr/src/lib/libc/gen/getloadavg.c' then echo shar: "will not over-write existing file '/usr/src/lib/libc/gen/getloadavg.c'" else sed 's/^X//' << \SHAR_EOF > '/usr/src/lib/libc/gen/getloadavg.c' X/*- X * Copyright (c) 1989, 1993 X * The Regents of the University of California. All rights reserved. X * X * Redistribution and use in source and binary forms, with or without X * modification, are permitted provided that the following conditions X * are met: X * 1. Redistributions of source code must retain the above copyright X * notice, this list of conditions and the following disclaimer. X * 2. Redistributions in binary form must reproduce the above copyright X * notice, this list of conditions and the following disclaimer in the X * documentation and/or other materials provided with the distribution. X * 3. All advertising materials mentioning features or use of this software X * must display the following acknowledgement: X * This product includes software developed by the University of X * California, Berkeley and its contributors. X * 4. Neither the name of the University nor the names of its contributors X * may be used to endorse or promote products derived from this software X * without specific prior written permission. X * X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE X * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF X * SUCH DAMAGE. X */ X X#if defined(LIBC_SCCS) && !defined(lint) Xstatic char sccsid[] = "@(#)getloadavg.c 8.1.1 (2.11BSD GTE) 1/15/95"; X#endif /* LIBC_SCCS and not lint */ X X#include X#include X#include X X/* X * getloadavg() -- Get system load averages. X * X * Put `nelem' samples into `loadavg' array. X * Return number of samples retrieved, or -1 on error. X */ Xint Xgetloadavg(loadavg, nelem) X double loadavg[]; X register int nelem; X{ X struct loadavg loadinfo; X register int i; X int mib[2]; X size_t size; X X mib[0] = CTL_VM; X mib[1] = VM_LOADAVG; X size = sizeof(loadinfo); X if (sysctl(mib, 2, &loadinfo, &size, NULL, 0) < 0) X return (-1); X X nelem = MIN(nelem, sizeof(loadinfo.ldavg) / sizeof(short)); X for (i = 0; i < nelem; i++) X loadavg[i] = (double) loadinfo.ldavg[i] / loadinfo.fscale; X return (nelem); X} SHAR_EOF chmod 644 '/usr/src/lib/libc/gen/getloadavg.c' fi if test -f '/usr/src/lib/libc/pdp/sys/__sysctl.s' then echo shar: "will not over-write existing file '/usr/src/lib/libc/pdp/sys/__sysctl.s'" else sed 's/^X//' << \SHAR_EOF > '/usr/src/lib/libc/pdp/sys/__sysctl.s' X/* X * No Copyright (c). Placed in the public domain 1995. Steven Schultz X * (sms@wlv.iipo.gtegsc.com). X */ X X#ifdef SYSLIBC_SCCS X_sccsid: <@(#)__sysctl.s 1.0 (2.11BSD GTE) 1/13/95\0> X .even X#endif SYSLIBC_SCCS X X#include "SYS.h" X XSYSCALL(__sysctl,norm) SHAR_EOF chmod 444 '/usr/src/lib/libc/pdp/sys/__sysctl.s' fi if test -f '/usr/src/man/man3/sysctl.3' then echo shar: "will not over-write existing file '/usr/src/man/man3/sysctl.3'" else sed 's/^X//' << \SHAR_EOF > '/usr/src/man/man3/sysctl.3' X.\" Copyright (c) 1993 X.\" The Regents of the University of California. All rights reserved. X.\" X.\" Redistribution and use in source and binary forms, with or without X.\" modification, are permitted provided that the following conditions X.\" are met: X.\" 1. Redistributions of source code must retain the above copyright X.\" notice, this list of conditions and the following disclaimer. X.\" 2. Redistributions in binary form must reproduce the above copyright X.\" notice, this list of conditions and the following disclaimer in the X.\" documentation and/or other materials provided with the distribution. X.\" 3. All advertising materials mentioning features or use of this software X.\" must display the following acknowledgement: X.\" This product includes software developed by the University of X.\" California, Berkeley and its contributors. X.\" 4. Neither the name of the University nor the names of its contributors X.\" may be used to endorse or promote products derived from this software X.\" without specific prior written permission. X.\" X.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND X.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE X.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE X.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE X.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL X.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS X.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) X.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT X.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY X.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF X.\" SUCH DAMAGE. X.\" X.\" @(#)sysctl.3 8.1.1 (2.11BSD GTE) 1/13/95 X.\" X.TH SYSCTL 3 "January 13, 1995" X.UC 4 X.SH NAME Xsysctl \- get or set system information X.SH SYNOPSIS X.nf X.ft B X#include X Xint Xsysctl(name, namelen, oldp, *oldlenp, *newp, newlen) X int *name; X u_int namelen; X void *oldp; X size_t *oldlenp; X void *newp; X size_t newlen X.ft R X.fi X.SH DESCRIPTION XThe X\fBsysctl\fP Xfunction retrieves system information and allows processes with Xappropriate privileges to set system information. XThe information available from X\fBsysctl\fP Xconsists of integers, strings, and tables. XInformation may be retrieved and set from the command interface Xusing the X\fIsysctl\fP(1) Xutility. X.PP XUnless explicitly noted below, X\fBsysctl\fP Xreturns a consistent snapshot of the data requested. XCalls to X\fBsysctl\fP Xare serialized to avoid deadlock. X.PP XThe state is described using a ``Management Information Base'' (MIB) Xstyle name, listed in X\fIname\fP , Xwhich is a X\fInamelen\fP Xlength array of integers. X.PP XThe information is copied into the buffer specified by X\fIoldp\fP . XThe size of the buffer is given by the location specified by X\fIoldlenp\fP Xbefore the call, Xand that location gives the amount of data copied after a successful call. XIf the amount of data available is greater Xthan the size of the buffer supplied, Xthe call supplies as much data as fits in the buffer provided Xand returns with the error code ENOMEM. XIf the old value is not desired, X\fIoldp\fP Xand X\fIoldlenp\fP Xshould be set to NULL. X.PP XThe size of the available data can be determined by calling X\fBsysctl\fP Xwith a NULL parameter for X\fIoldp\fP. XThe size of the available data will be returned in the location pointed to by X\fIoldlenp\fP. XFor some operations, the amount of space may change often. XFor these operations, Xthe system attempts to round up so that the returned size is Xlarge enough for a call to return the data shortly thereafter. X.PP XTo set a new value, X\fInewp\fP Xis set to point to a buffer of length X\fInewlen\fP Xfrom which the requested value is to be taken. XIf a new value is not to be set, X\fInewp\fP Xshould be set to NULL and X\fInewlen\fP Xset to 0. X.PP XThe top level names are defined with a CTL_ prefix in X\fI\fP, Xand are as follows. XThe next and subsequent levels down are found in the include files Xlisted here, and described in separate sections below. X.PP X.nf X.ta .25i 1.5i 3.75i 4.5i X Name Next level names Description X CTL\_DEBUG sys/sysctl.h Debugging X CTL\_FS sys/sysctl.h File system X CTL\_HW sys/sysctl.h Generic CPU, I/O X CTL\_KERN sys/sysctl.h High kernel limits X CTL\_MACHDEP sys/sysctl.h Machine dependent X CTL\_NET sys/socket.h Networking X CTL\_USER sys/sysctl.h User-level X CTL\_VM vm/vm_param.h Virtual memory X.fi X.PP XFor example, the following retrieves the maximum number of processes allowed Xin the system: X.sp X.nf X.in +.5i Xint mib[2], maxproc; Xsize_t len; X.sp Xmib[0] = CTL_KERN; Xmib[1] = KERN_MAXPROC; Xlen = sizeof(maxproc); Xsysctl(mib, 2, &maxproc, &len, NULL, 0); X.in -.5i X.sp XTo retrieve the standard search path for the system utilities: X.sp X.nf X.in +.5i Xint mib[2]; Xsize_t len; Xchar *p; X Xmib[0] = CTL_USER; Xmib[1] = USER_CS_PATH; Xsysctl(mib, 2, NULL, &len, NULL, 0); Xp = malloc(len); Xsysctl(mib, 2, p, &len, NULL, 0); X.in -.5i X.fi X.SH CTL_DEBUG XThe debugging variables vary from system to system. XA debugging variable may be added or deleted without need to recompile X\fBsysctl\fP Xto know about it. XEach time it runs, X\fBsysctl\fP Xgets the list of debugging variables from the kernel and Xdisplays their current values. XThe system defines twenty X\fIstruct ctldebug\fP Xvariables named X\fIdebug0\fP Xthrough X\fIdebug19\fP. XThey are declared as separate variables so that they can be Xindividually initialized at the location of their associated variable. XThe loader prevents multiple use of the same variable by issuing errors Xif a variable is initialized in more than one place. XFor example, to export the variable X\fIdospecialcheck\fP Xas a debugging variable, the following declaration would be used: X.sp X.nf X.in +.5i Xint dospecialcheck = 1; Xstruct ctldebug debug5 = { "dospecialcheck", &dospecialcheck }; X.in -.5i X.fi X.SH CTL_FS XThere are currently no second level names for the file system. X.SH CTL_HW XThe string and integer information available for the CTL_HW level Xis detailed below. XThe changeable column shows whether a process with appropriate Xprivilege may change the value. X.sp X.nf X.ta .25i 2.75i 3.75i X Second level name Type Changeable X HW\_MACHINE string no X HW\_MODEL string no X HW\_NCPU integer no X HW\_BYTEORDER integer no X HW\_PHYSMEM integer no X HW\_USERMEM integer no X HW\_PAGESIZE integer no X.\".It HW\_DISKNAMES integer no X.\".It HW\_DISKSTATS integer no X.fi X.PP X.ta .5i XHW_MACHINE X.br X The machine class. X.sp XHW_MODEL X.br X The machine model X.sp XHW_NCPU X.br X The number of cpus. X.sp XHW_BYTEORDER X.br X The byteorder (3412, 4321, or 1234). X.sp XHW_PHYSMEM X.br X The bytes of physical memory. X.sp XHW_USERMEM X.br X The bytes of non-kernel memory. X.sp XHW_PAGESIZE X.br X The software page size. X.sp X.\".It Fa HW_DISKNAMES X.\".It Fa HW_DISKSTATS X.SH CTL_KERN XThe string and integer information available for the CTL_KERN level Xis detailed below. XThe changeable column shows whether a process with appropriate Xprivilege may change the value. XThe types of data currently available are process information, Xsystem inodes, the open file entries, routing table entries, Xvirtual memory statistics, load average history, and clock rate Xinformation. X.sp X.nf X.ta .25i 2.75i 4.5i X X Second level name Type Changeable X KERN\_ARGMAX integer no X KERN\_BOOTTIME struct timeval no X KERN\_CHOWN\_RESTRICTED integer no X KERN\_CLOCKRATE struct clockinfo no X KERN\_FILE struct file no X KERN\_HOSTID long yes X KERN\_HOSTNAME string yes X KERN\_JOB\_CONTROL integer no X.\"KERN\_LINK\_MAX integer no X KERN\_MAXFILES integer no X KERN\_MAXPROC integer no X KERN\_MAXINODES integer no X KERN\_MAXTEXTS integer no X.\"KERN\_MAX\_CANON integer no X.\"KERN\_MAX\_INPUT integer no X.\"KERN\_NAME\_MAX integer no X KERN\_NGROUPS integer no X.\"KERN\_NO\_TRUNC integer no X KERN\_OSRELEASE string no X KERN\_OSREV integer no X KERN\_OSTYPE string no X.\"KERN\_PATH\_MAX integer no X.\"KERN\_PIPE\_BUF integer no X KERN\_POSIX1 integer no X KERN\_PROC struct proc no X KERN\_PROF node not applicable X KERN\_SAVED\_IDS integer no X KERN\_SECURELVL integer raise only X KERN\_TEXT struct text no X.\"KERN\_VDISABLE integer no X KERN\_VERSION string no X KERN\_INODE struct inode no X.fi X.PP XKERN_ARGMAX X.br X.in +.5i XThe maximum bytes of argument to \fBexec(2)\fP. X.sp X.in -.5i XKERN_BOOTTIME X.br X.in +.5i XA \fIstruct timeval\fP structure is returned. XThis structure contains the time that the system was booted. X.sp X.in -.5i X.\"KERN_CHOWN_RESTRICTED X.\"Return 1 if appropriate privileges are required for the X.\".Xr chown 2 X.\"system call, otherwise 0. XKERN_CLOCKRATE X.br X.in +.5i XA \fIstruct clockinfo\fP structure is returned. XThis structure contains the clock, statistics clock and profiling clock Xfrequencies, and the number of micro-seconds per hz tick. X.sp X.in -.5i XKERN_FILE X.br X.in +.5i XReturn the entire file table as an array of extended \fIfile\fP Xstructures. XEach element of the array contains the kernel address of a file X\fIstruct inode *\fP Xfollowed by the file itself X\fIstruct file\fP. There can never be more than \fBKERN_MAXFILES\fP Xinodes returned. X.sp X.in -.5i XKERN_HOSTID X.br X.in +.5i XGet or set the host id. X.sp X.in -.5i XKERN_HOSTNAME X.br X.in +.5i XGet or set the hostname. X.sp X.in -.5i XKERN_JOB_CONTROL X.br X.in +.5i XReturn 1 if job control is available on this system, otherwise 0. X.sp X.in -.5i X.\"KERN_LINK_MAX X.\"The maximum file link count. XKERN_MAXFILES X.br X.in +.5i XThe maximum number of open files that may be open in the system. X.sp X.in -.5i XKERN_MAXPROC X.br X.in +.5i XThe maximum number of simultaneous processes the system will allow. X.sp X.in -.5i XKERN_MAXINODES X.br X.in +.5i XThe maximum number of inodes available on the system. X.sp X.in -.5i XKERN_MAXTEXTS X.br X.in +.5i XThe maximum number of text structures available on the system. X.sp X.in -.5i X.\"KERN_MAX_CANON X.\"The maximum number of bytes in terminal canonical input line. X.\"KERN_MAX_INPUT X.\"The minimum maximum number of bytes for which space is available in X.\"a terminal input queue. X.\"KERN_NAME_MAX X.\"The maximum number of bytes in a file name. XKERN_NGROUPS X.br X.in +.5i XThe maximum number of supplemental groups. X.sp X.in -.5i X.\"KERN_NO_TRUNC X.\"Return 1 if file names longer than KERN_NAME_MAX are truncated. XKERN_OSRELEASE X.br X.in +.5i XThe system release string. X.sp X.in -.5i XKERN_OSREV X.br X.in +.5i XThe system revision string. X.sp X.in -.5i XKERN_OSTYPE X.br X.in +.5i XThe system type string. X.sp X.in -.5i X.\"KERN_PATH_MAX X.\"The maximum number of bytes in a pathname. X.\"KERN_PIPE_BUF X.\"The maximum number of bytes which will be written atomically to a pipe. XKERN_POSIX1 X.br X.in +.5i XThe version of ISO/IEC 9945 (POSIX 1003.1) with which the system Xattempts to comply. X.sp X.in -.5i XKERN_PROC X.br X.in +.5i XReturn the entire process table, or a subset of it. XAn array of X\fIstruct kinfo_proc\fP Xstructures is returned, Xwhose size depends on the current number of such objects in the system. X.sp X.in -.5i XThe third and fourth level names are as follows: X.sp X.nf X.ta .25i 3.0i X Third level name Fourth level is: X KERN\_PROC\_ALL None X KERN\_PROC\_PID A process ID X KERN\_PROC\_PGRP A process group X KERN\_PROC\_TTY A tty device X KERN\_PROC\_UID A user ID X KERN\_PROC\_RUID A real user ID X KERN\_PROF Return kernel profiling information. X.fi X.sp X.in + .5i XIf the kernel is not compiled for profiling, Xattempts to retrieve any of the KERN_PROF values will Xfail with EOPNOTSUPP. X.sp X.in -.5i XThe third level names for the string and integer profiling information Xis detailed below. XThe changeable column shows whether a process with appropriate Xprivilege may change the value. X.sp X.in +.5i X.nf X.ta .25i 2.25i 4.25i XThird level name Type Changeable X GPROF\_STATE integer yes X GPROF\_COUNT u_short[\|] yes X GPROF\_FROMS u_short[\|] yes X GPROF\_TOS struct tostruct yes X GPROF\_GMONPARAM struct gmonparam no X.fi X.PP XThe variables are as follows: X.sp XGPROF_STATE X.br X.in +.5i XReturns GMON_PROF_ON or GMON_PROF_OFF to show that profiling Xis running or stopped. X.sp X.in -.5i XGPROF_COUNT X.br X.in +.5i XArray of statistical program counter counts. X.sp X.in -.5i XGPROF_FROMS X.br X.in +.5i XArray indexed by program counter of call-from points. X.sp X.in -.5i XGPROF_TOS X.br X.in +.5i XArray of X\fIstruct tostruct\fP Xdescribing destination of calls and their counts. X.sp X.in -.5i XGPROF_GMONPARAM X.br X.in +.5i XStructure giving the sizes of the above arrays. X.in -.5i X.sp XKERN_SAVED_IDS X.br X.in +.5i XReturns 1 if saved set-group and saved set-user ID is available. X.sp X.in -.5i X.in -.5i XKERN_SECURELVL X.br X.in +.5i XThe system security level. XThis level may be raised by processes with appropriate privilege. XIt may only be lowered by process 1. X.sp X.in -.5i X.\"KERN_VDISABLE X.\"Returns the terminal character disabling value. XKERN_VERSION X.br X.in +.5i XThe system version string. X.sp X.in -.5i XKERN_INODE X.br X.in +.5i XReturn the entire inode table. XNote, the inode table is not necessarily a consistent snapshot of Xthe system. XThe returned data consists of an array whose size depends on the Xcurrent number of such objects in the system. XEach element of the array contains the kernel address of a inode X\fIstruct inode *\fP Xfollowed by the inode itself X\fIstruct inode\fP. There can never be more than \fBKERN_MAXINODES\fP Xinodes returned. X.sp X.in -.5i XKERN_TEXT X.br X.in +.5i XReturn the entire text table. The returned data consists of an array whose Xsize depends on the current number of such objects active in the system. XEach element of the array contains the kernel address of a text X\fIstruct text *\fP followed by the text structure itself X\fIstruct text\fP. There can never be more structures than returned Xby \fBKERN_MAXTEXTS\fP. X.in -.5i X.SH CTL_MACHDEP XThe set of variables defined is architecture dependent. XMost architectures define at least the following variables. X.nf X.sp X.ta .25i 2.75i 3.75i X Second level name Type Changeable X CPU_CONSDEV dev_t no X.fi X.SH CTL_NET XThe string and integer information available for the CTL_NET level Xis detailed below. XThe changeable column shows whether a process with appropriate Xprivilege may change the value. X.nf X.sp X.ta .25i 2.25i 4.0i X Second level name Type Changeable X PF\_ROUTE routing messages no X PF\_INET internet values yes X.fi X.PP XPF_ROUTE X.br X.in +.5i XReturn the entire routing table or a subset of it. XThe data is returned as a sequence of routing messages (see X\fIroute(4)\fP Xfor the header file, format and meaning). XThe length of each message is contained in the message header. X.in -.5i X.PP XThe third level name is a protocol number, which is currently always 0. XThe fourth level name is an address family, which may be set to 0 to Xselect all address families. XThe fifth and sixth level names are as follows: X.nf X.sp X.ta .25i 2.75i X Fifth level name Sixth level is: X NET\_RT\_FLAGS rtflags X NET\_RT\_DUMP None X NET\_RT\_IFLIST None X.fi X.sp XPF_INET X.br X.in +.5i XGet or set various global information about the internet protocols. XThe third level name is the protocol. XThe fourth level name is the variable name. XThe currently defined protocols and names are: X.sp X.in -.5i X.nf X.ta .25i 2.0i 3.75i 4.75i X Protocol name Variable name Type Changeable X ip forwarding integer yes X ip redirect integer yes X ip ttl integer yes X icmp maskrepl integer yes X udp checksum integer yes X.fi X.PP XThe variables are as follows: X.sp Xip.forwarding X.br X.in +.5i XReturns 1 when IP forwarding is enabled for the host, Xmeaning that the host is acting as a router. X.sp X.in -.5i Xip.redirect X.br X.in +.5i XReturns 1 when ICMP redirects may be sent by the host. XThis option is ignored unless the host is routing IP packets, Xand should normally be enabled on all systems. X.sp X.in -.5i Xip.ttl X.br X.in +.5i XThe maximum time-to-live (hop count) value for an IP packet sourced by Xthe system. XThis value applies to normal transport protocols, not to ICMP. X.sp X.in -.5i Xicmp.maskrepl X.br X.in +.5i XReturns 1 if ICMP network mask requests are to be answered. X.sp X.in -.5i Xudp.checksum X.br X.in +.5i XReturns 1 when UDP checksums are being computed and checked. XDisabling UDP checksums is strongly discouraged. X.sp X.in -.5i X.SH CTL_USER XThe string and integer information available for the CTL_USER level Xis detailed below. XThe changeable column shows whether a process with appropriate Xprivilege may change the value. X.sp X.nf X.ta .25i 3.0i 4.25i X Second level name Type Changeable X USER\_BC\_BASE\_MAX integer no X USER\_BC\_DIM\_MAX integer no X USER\_BC\_SCALE\_MAX integer no X USER\_BC\_STRING\_MAX integer no X USER\_COLL\_WEIGHTS\_MAX integer no X USER\_CS\_PATH string no X USER\_EXPR\_NEST\_MAX integer no X USER\_LINE\_MAX integer no X USER\_POSIX2\_CHAR\_TERM integer no X USER\_POSIX2\_C\_BIND integer no X USER\_POSIX2\_C\_DEV integer no X USER\_POSIX2\_FORT\_DEV integer no X USER\_POSIX2\_FORT\_RUN integer no X USER\_POSIX2\_LOCALEDEF integer no X USER\_POSIX2\_SW\_DEV integer no X USER\_POSIX2\_UPE integer no X USER\_POSIX2\_VERSION integer no X USER\_RE\_DUP\_MAX integer no X USER\_STREAM\_MAX integer no X USER\_TZNAME\_MAX integer no X.fi X.PP XUSER_BC_BASE_MAX X.br X.in +.5i XThe maximum ibase/obase values in the X\fIbc(1)\fP Xutility. X.sp X.in -.5i XUSER_BC_DIM_MAX X.br X.in +.5i XThe maximum array size in the X\fIbc(1)\fP Xutility. X.sp X.in -.5i XUSER_BC_SCALE_MAX X.br X.in +.5i XThe maximum scale value in the X\fIbc(1)\fP Xutility. X.sp X.in -.5i XUSER_BC_STRING_MAX X.br X.in +.5i XThe maximum string length in the X\fIbc(1)\fP Xutility. X.sp X.in -.5i XUSER_COLL_WEIGHTS_MAX X.br X.in +.5i XThe maximum number of weights that can be assigned to any entry of Xthe LC_COLLATE order keyword in the locale definition file. X.sp X.in -.5i XUSER_CS_PATH X.br X.in +.5i XReturn a value for the X\fIPATH\fP Xenvironment variable that finds all the standard utilities. X.sp X.in -.5i XUSER_EXPR_NEST_MAX X.br X.in +.5i XThe maximum number of expressions that can be nested within Xparenthesis by the X\fIexpr(1)\fP Xutility. X.sp X.in -.5i XUSER_LINE_MAX X.br X.in +.5i XThe maximum length in bytes of a text-processing utility's input Xline. X.sp X.in -.5i XUSER_POSIX2_CHAR_TERM X.br X.in +.5i XReturn 1 if the system supports at least one terminal type capable of Xall operations described in POSIX 1003.2, otherwise 0. X.sp X.in -.5i XUSER_POSIX2_C_BIND X.br X.in +.5i XReturn 1 if the system's C-language development facilities support the XC-Language Bindings Option, otherwise 0. X.sp X.in -.5i XUSER_POSIX2_C_DEV X.br X.in +.5i XReturn 1 if the system supports the C-Language Development Utilities Option, Xotherwise 0. X.sp X.in -.5i XUSER_POSIX2_FORT_DEV X.br X.in +.5i XReturn 1 if the system supports the FORTRAN Development Utilities Option, Xotherwise 0. X.sp X.in -.5i XUSER_POSIX2_FORT_RUN X.br X.in +.5i XReturn 1 if the system supports the FORTRAN Runtime Utilities Option, Xotherwise 0. X.sp X.in -.5i XUSER_POSIX2_LOCALEDEF X.br X.in +.5i XReturn 1 if the system supports the creation of locales, otherwise 0. X.sp X.in -.5i XUSER_POSIX2_SW_DEV X.br X.in +.5i XReturn 1 if the system supports the Software Development Utilities Option, Xotherwise 0. X.sp X.in -.5i XUSER_POSIX2_UPE X.br X.in +.5i XReturn 1 if the system supports the User Portability Utilities Option, Xotherwise 0. X.sp X.in -.5i XUSER_POSIX2_VERSION X.br X.in +.5i XThe version of POSIX 1003.2 with which the system attempts to comply. X.sp X.in -.5i XUSER_RE_DUP_MAX X.br X.in +.5i XThe maximum number of repeated occurrences of a regular expression Xpermitted when using interval notation. X.sp X.in -.5i XUSER_STREAM_MAX X.br X.in +.5i XThe minimum maximum number of streams that a process may have open Xat any one time. X.sp X.in -.5i XUSER_TZNAME_MAX X.br X.in +.5i XThe minimum maximum number of types supported for the name of a Xtimezone. X.br X.in -.5i X.SH CTL_VM XThe string and integer information available for the CTL_VM level Xis detailed below. XThe changeable column shows whether a process with appropriate Xprivilege may change the value. X.sp X.nf X.ta .25i 2.25i 4.0i X Second level name Type Changeable X VM\_LOADAVG struct loadavg no X VM\_METER struct vmtotal no X VM\_SWAPMAP struct map no X VM\_COREMAP struct map no X.fi X.PP XVM_LOADAVG X.br X.in +.5i XReturn the load average history. XThe returned data consists of a X\fIstruct loadavg\fP. X.sp X.in -.5i XVM_METER X.br X.in +.5i XReturn the system wide virtual memory statistics. XThe returned data consists of a X\fIstruct vmtotal\fP. X.br X.in -.5i X.sp XVM_SWAPMAP X.br X.in +.5i XReturn the swapmap. The size of this structure is fixed and may be Xdetermined by specifying a \fBoldlenp\fP initialized to zero, the kernel Xwill fill in the size of the swapmap. X.in -.5i X.sp XVM_COREMAP X.br X.in +.5i XSame as for swapmap above except that the core allocation map is Xreturned. X.in -.5i X.SH RETURN VALUES XIf the call to X\fBsysctl\fP Xis successful, 0 is returned. XOtherwise \-1 is returned and X\fIerrno\fP Xis set appropriately. X.SH ERRORS XThe following errors may be reported: X.TP 15 XEFAULT XThe buffer X\fIname\fP, X\fIoldp\fP , X\fInewp\fP , Xor length pointer X\fIoldlenp\fP Xcontains an invalid address. X.TP 15 XEINVAL XThe X\fIname\fP Xarray is less than two or greater than CTL_MAXNAME. X.TP 15 XEINVAL XA non-null X\fInewp\fP Xis given and its specified length in X\fInewlen\fP Xis too large or too small. X.TP 15 XENOMEM XThe length pointed to by X\fIoldlenp\fP Xis too short to hold the requested value. X.TP 15 XENOTDIR XThe X\fIname\fP Xarray specifies an intermediate rather than terminal name. X.TP 15 XEOPNOTSUPP XThe X\fIname\fP Xarray specifies a value that is unknown. X.TP 15 XEPERM XAn attempt is made to set a read-only value. X.TP 15 XEPERM XA process without appropriate privilege attempts to set a value. X.SH FILES X.TP 15 X Xdefinitions for top level identifiers, second level kernel and hardware Xidentifiers, and user level identifiers X.TP 15 X Xdefinitions for second level network identifiers X.TP 15 X Xdefinitions for third level profiling identifiers X.TP 15 X Xdefinitions for second level virtual memory identifiers X.TP 15 X Xdefinitions for third level Internet identifiers and Xfourth level IP identifiers X.TP 15 X Xdefinitions for fourth level ICMP identifiers X.TP 15 X Xdefinitions for fourth level UDP identifiers X.SH SEE ALSO X.I sysctl(8) X.SH HISTORY XThe X.B sysctl Xfunction first appeared in 4.4BSD. X.PP XThe KERN_TEXT, KERN_MAXTEXTS, VM_SWAPMAP, VM_COREMAP options are X2.11BSD specific extensions to the 4.4BSD \fIsysctl\fP implmentation. X.PP XHaving KERN_FILE return the address of the file structure before the Xactual \fIstruct file\fP is a 2.11BSD enhancement. The \fIinode\fP X(\fIvnode\fP under 4.4) table was handled this way. SHAR_EOF chmod 644 '/usr/src/man/man3/sysctl.3' fi if test -f '/usr/src/man/man3/getloadavg.3' then echo shar: "will not over-write existing file '/usr/src/man/man3/getloadavg.3'" else sed 's/^X//' << \SHAR_EOF > '/usr/src/man/man3/getloadavg.3' X.\" Copyright (c) 1989, 1991, 1993 X.\" The Regents of the University of California. All rights reserved. X.\" X.\" Redistribution and use in source and binary forms, with or without X.\" modification, are permitted provided that the following conditions X.\" are met: X.\" 1. Redistributions of source code must retain the above copyright X.\" notice, this list of conditions and the following disclaimer. X.\" 2. Redistributions in binary form must reproduce the above copyright X.\" notice, this list of conditions and the following disclaimer in the X.\" documentation and/or other materials provided with the distribution. X.\" 3. All advertising materials mentioning features or use of this software X.\" must display the following acknowledgement: X.\" This product includes software developed by the University of X.\" California, Berkeley and its contributors. X.\" 4. Neither the name of the University nor the names of its contributors X.\" may be used to endorse or promote products derived from this software X.\" without specific prior written permission. X.\" X.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND X.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE X.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE X.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE X.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL X.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS X.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) X.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT X.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY X.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF X.\" SUCH DAMAGE. X.\" X.\" @(#)getloadavg.3 8.1.1 (2.11BSD GTE) 1/15/95 X.\" X.TH GETLOADAVG 3 "January 15, 1995" X.UC 4 X.SH NAME Xgetloadavg \- get system load averages X.SH SYNOPSIS X.nf X.B getloadavg(loadavg, nelem) X double loadavg[]; X int nelem; X.fi X.SH DESCRIPTION XThe X\fIgetloadavg\fP Xfunction returns the number of processes in the system run queue Xaveraged over various periods of time. XUp to X\fInelem\fP Xsamples are retrieved and assigned to successive elements of X\fIloadavg\fP. XThe system imposes a maximum of 3 samples, representing averages Xover the last 1, 5, and 15 minutes, respectively. X.SH DIAGNOSTICS XIf the load average was unobtainable, \-1 is returned; otherwise, Xthe number of samples actually retrieved is returned. X.SH SEE ALSO Xuptime(1), sysctl(3), sysctl(8). X.SH HISTORY XThe X.B getloadavg Xfunction appeared in \fB4.3BSD-Reno\fP. X.PP XThis function replaces the 2.9BSD compatibility routine getla(). SHAR_EOF chmod 444 '/usr/src/man/man3/getloadavg.3' fi exit 0 # End of shell archive