kern_sysctl.c revision 3396
1/*- 2 * Copyright (c) 1982, 1986, 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Mike Karels at Berkeley Software Design, Inc. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by the University of 19 * California, Berkeley and its contributors. 20 * 4. Neither the name of the University nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * @(#)kern_sysctl.c 8.4 (Berkeley) 4/14/94 37 * $Id: kern_sysctl.c,v 1.16 1994/10/02 17:35:19 phk Exp $ 38 */ 39 40/* 41 * sysctl system call. 42 */ 43 44#include <sys/param.h> 45#include <sys/systm.h> 46#include <sys/kernel.h> 47#include <sys/malloc.h> 48#include <sys/proc.h> 49#include <sys/file.h> 50#include <sys/vnode.h> 51#include <sys/unistd.h> 52#include <sys/buf.h> 53#include <sys/ioctl.h> 54#include <sys/tty.h> 55#include <vm/vm.h> 56#include <sys/sysctl.h> 57 58sysctlfn kern_sysctl; 59sysctlfn hw_sysctl; 60#ifdef DEBUG 61sysctlfn debug_sysctl; 62#endif 63extern sysctlfn vm_sysctl; 64extern sysctlfn fs_sysctl; 65extern sysctlfn net_sysctl; 66extern sysctlfn cpu_sysctl; 67extern sysctlfn ntp_sysctl; 68 69/* 70 * Locking and stats 71 */ 72static struct sysctl_lock { 73 int sl_lock; 74 int sl_want; 75 int sl_locked; 76} memlock; 77 78struct sysctl_args { 79 int *name; 80 u_int namelen; 81 void *old; 82 size_t *oldlenp; 83 void *new; 84 size_t newlen; 85}; 86 87int 88__sysctl(p, uap, retval) 89 struct proc *p; 90 register struct sysctl_args *uap; 91 int *retval; 92{ 93 int error, dolock = 1; 94 u_int savelen = 0, oldlen = 0; 95 sysctlfn *fn; 96 int name[CTL_MAXNAME]; 97 98 if (uap->new != NULL && (error = suser(p->p_ucred, &p->p_acflag))) 99 return (error); 100 /* 101 * all top-level sysctl names are non-terminal 102 */ 103 if (uap->namelen > CTL_MAXNAME || uap->namelen < 2) 104 return (EINVAL); 105 error = copyin(uap->name, &name, uap->namelen * sizeof(int)); 106 if (error) 107 return (error); 108 109 switch (name[0]) { 110 case CTL_KERN: 111 fn = kern_sysctl; 112 if (name[1] != KERN_VNODE) /* XXX */ 113 dolock = 0; 114 break; 115 case CTL_HW: 116 fn = hw_sysctl; 117 break; 118 case CTL_VM: 119 fn = vm_sysctl; 120 break; 121 case CTL_NET: 122 fn = net_sysctl; 123 break; 124 case CTL_FS: 125 fn = fs_sysctl; 126 break; 127 case CTL_MACHDEP: 128 fn = cpu_sysctl; 129 break; 130#ifdef DEBUG 131 case CTL_DEBUG: 132 fn = debug_sysctl; 133 break; 134#endif 135 default: 136 return (EOPNOTSUPP); 137 } 138 139 if (uap->oldlenp && 140 (error = copyin(uap->oldlenp, &oldlen, sizeof(oldlen)))) 141 return (error); 142 if (uap->old != NULL) { 143 if (!useracc(uap->old, oldlen, B_WRITE)) 144 return (EFAULT); 145 while (memlock.sl_lock) { 146 memlock.sl_want = 1; 147 (void) tsleep((caddr_t)&memlock, PRIBIO+1, "sysctl", 0); 148 memlock.sl_locked++; 149 } 150 memlock.sl_lock = 1; 151 if (dolock) 152 vslock(uap->old, oldlen); 153 savelen = oldlen; 154 } 155 error = (*fn)(name + 1, uap->namelen - 1, uap->old, &oldlen, 156 uap->new, uap->newlen, p); 157 if (uap->old != NULL) { 158 if (dolock) 159 vsunlock(uap->old, savelen, B_WRITE); 160 memlock.sl_lock = 0; 161 if (memlock.sl_want) { 162 memlock.sl_want = 0; 163 wakeup((caddr_t)&memlock); 164 } 165 } 166 if (error) 167 return (error); 168 if (uap->oldlenp) 169 error = copyout(&oldlen, uap->oldlenp, sizeof(oldlen)); 170 *retval = oldlen; 171 return (0); 172} 173 174/* 175 * Attributes stored in the kernel. 176 */ 177char hostname[MAXHOSTNAMELEN]; 178int hostnamelen; 179char domainname[MAXHOSTNAMELEN]; 180int domainnamelen; 181long hostid; 182int securelevel = -1; 183char kernelname[MAXPATHLEN] = "/kernel"; 184extern int vfs_update_wakeup; 185extern int vfs_update_interval; 186extern int osreldate; 187 188/* 189 * kernel related system variables. 190 */ 191int 192kern_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p) 193 int *name; 194 u_int namelen; 195 void *oldp; 196 size_t *oldlenp; 197 void *newp; 198 size_t newlen; 199 struct proc *p; 200{ 201 int error, level, inthostid; 202 extern char ostype[], osrelease[]; 203 204 /* all sysctl names at this level are terminal */ 205 if (namelen != 1 && !(name[0] == KERN_PROC || name[0] == KERN_PROF 206 || name[0] == KERN_NTP_PLL)) 207 return (ENOTDIR); /* overloaded */ 208 209 switch (name[0]) { 210 case KERN_OSTYPE: 211 return (sysctl_rdstring(oldp, oldlenp, newp, ostype)); 212 case KERN_OSRELEASE: 213 return (sysctl_rdstring(oldp, oldlenp, newp, osrelease)); 214 case KERN_OSREV: 215 return (sysctl_rdint(oldp, oldlenp, newp, BSD)); 216 case KERN_VERSION: 217 return (sysctl_rdstring(oldp, oldlenp, newp, version)); 218 case KERN_OSRELDATE: 219 return (sysctl_rdint(oldp, oldlenp, newp, osreldate)); 220 case KERN_BOOTFILE: 221 return (sysctl_string(oldp, oldlenp, newp, newlen, 222 kernelname, sizeof kernelname)); 223 case KERN_MAXVNODES: 224 return(sysctl_int(oldp, oldlenp, newp, newlen, &desiredvnodes)); 225 case KERN_MAXPROC: 226 return (sysctl_int(oldp, oldlenp, newp, newlen, &maxproc)); 227 case KERN_MAXFILES: 228 return (sysctl_int(oldp, oldlenp, newp, newlen, &maxfiles)); 229 case KERN_UPDATEINTERVAL: 230 /* 231 * NB: this simple-minded approach only works because 232 * `tsleep' takes a timeout argument of 0 as meaning 233 * `no timeout'. 234 */ 235 error = sysctl_int(oldp, oldlenp, newp, newlen, 236 &vfs_update_interval); 237 if(!error) { 238 wakeup(&vfs_update_wakeup); 239 } 240 return error; 241 case KERN_ARGMAX: 242 return (sysctl_rdint(oldp, oldlenp, newp, ARG_MAX)); 243 case KERN_SECURELVL: 244 level = securelevel; 245 if ((error = sysctl_int(oldp, oldlenp, newp, newlen, &level)) || 246 newp == NULL) 247 return (error); 248 if (level < securelevel && p->p_pid != 1) 249 return (EPERM); 250 securelevel = level; 251 return (0); 252 case KERN_HOSTNAME: 253 error = sysctl_string(oldp, oldlenp, newp, newlen, 254 hostname, sizeof(hostname)); 255 if (newp && !error) 256 hostnamelen = newlen; 257 return (error); 258 case KERN_DOMAINNAME: 259 error = sysctl_string(oldp, oldlenp, newp, newlen, 260 domainname, sizeof(domainname)); 261 if (newp && !error) 262 domainnamelen = newlen; 263 return (error); 264 case KERN_HOSTID: 265 inthostid = hostid; /* XXX assumes sizeof long <= sizeof int */ 266 error = sysctl_int(oldp, oldlenp, newp, newlen, &inthostid); 267 hostid = inthostid; 268 return (error); 269 case KERN_CLOCKRATE: 270 return (sysctl_clockrate(oldp, oldlenp)); 271 case KERN_BOOTTIME: 272 return (sysctl_rdstruct(oldp, oldlenp, newp, &boottime, 273 sizeof(struct timeval))); 274 case KERN_VNODE: 275 return (sysctl_vnode(oldp, oldlenp)); 276 case KERN_PROC: 277 return (sysctl_doproc(name + 1, namelen - 1, oldp, oldlenp)); 278 case KERN_FILE: 279 return (sysctl_file(oldp, oldlenp)); 280#ifdef GPROF 281 case KERN_PROF: 282 return (sysctl_doprof(name + 1, namelen - 1, oldp, oldlenp, 283 newp, newlen)); 284#endif 285 case KERN_POSIX1: 286 return (sysctl_rdint(oldp, oldlenp, newp, _POSIX_VERSION)); 287 case KERN_NGROUPS: 288 return (sysctl_rdint(oldp, oldlenp, newp, NGROUPS_MAX)); 289 case KERN_JOB_CONTROL: 290 return (sysctl_rdint(oldp, oldlenp, newp, 1)); 291 case KERN_SAVED_IDS: 292#ifdef _POSIX_SAVED_IDS 293 return (sysctl_rdint(oldp, oldlenp, newp, 1)); 294#else 295 return (sysctl_rdint(oldp, oldlenp, newp, 0)); 296#endif 297 case KERN_NTP_PLL: 298 return (ntp_sysctl(name + 1, namelen - 1, oldp, oldlenp, 299 newp, newlen, p)); 300 default: 301 return (EOPNOTSUPP); 302 } 303 /* NOTREACHED */ 304} 305 306/* 307 * hardware related system variables. 308 */ 309int 310hw_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p) 311 int *name; 312 u_int namelen; 313 void *oldp; 314 size_t *oldlenp; 315 void *newp; 316 size_t newlen; 317 struct proc *p; 318{ 319 extern char machine[], cpu_model[]; 320 extern int hw_float; 321 322 /* all sysctl names at this level are terminal */ 323 if (namelen != 1) 324 return (ENOTDIR); /* overloaded */ 325 326 switch (name[0]) { 327 case HW_MACHINE: 328 return (sysctl_rdstring(oldp, oldlenp, newp, machine)); 329 case HW_MODEL: 330 return (sysctl_rdstring(oldp, oldlenp, newp, cpu_model)); 331 case HW_NCPU: 332 return (sysctl_rdint(oldp, oldlenp, newp, 1)); /* XXX */ 333 case HW_BYTEORDER: 334 return (sysctl_rdint(oldp, oldlenp, newp, BYTE_ORDER)); 335 case HW_PHYSMEM: 336 return (sysctl_rdint(oldp, oldlenp, newp, ctob(physmem))); 337 case HW_USERMEM: 338 return (sysctl_rdint(oldp, oldlenp, newp, 339 ctob(physmem - cnt.v_wire_count))); 340 case HW_PAGESIZE: 341 return (sysctl_rdint(oldp, oldlenp, newp, PAGE_SIZE)); 342 case HW_FLOATINGPT: 343 return (sysctl_rdint(oldp, oldlenp, newp, hw_float)); 344 default: 345 return (EOPNOTSUPP); 346 } 347 /* NOTREACHED */ 348} 349 350#ifdef DEBUG 351/* 352 * Debugging related system variables. 353 */ 354struct ctldebug debug0, debug1, debug2, debug3, debug4; 355struct ctldebug debug5, debug6, debug7, debug8, debug9; 356struct ctldebug debug10, debug11, debug12, debug13, debug14; 357struct ctldebug debug15, debug16, debug17, debug18, debug19; 358static struct ctldebug *debugvars[CTL_DEBUG_MAXID] = { 359 &debug0, &debug1, &debug2, &debug3, &debug4, 360 &debug5, &debug6, &debug7, &debug8, &debug9, 361 &debug10, &debug11, &debug12, &debug13, &debug14, 362 &debug15, &debug16, &debug17, &debug18, &debug19, 363}; 364int 365debug_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p) 366 int *name; 367 u_int namelen; 368 void *oldp; 369 size_t *oldlenp; 370 void *newp; 371 size_t newlen; 372 struct proc *p; 373{ 374 struct ctldebug *cdp; 375 376 /* all sysctl names at this level are name and field */ 377 if (namelen != 2) 378 return (ENOTDIR); /* overloaded */ 379 cdp = debugvars[name[0]]; 380 if (cdp->debugname == 0) 381 return (EOPNOTSUPP); 382 switch (name[1]) { 383 case CTL_DEBUG_NAME: 384 return (sysctl_rdstring(oldp, oldlenp, newp, cdp->debugname)); 385 case CTL_DEBUG_VALUE: 386 return (sysctl_int(oldp, oldlenp, newp, newlen, cdp->debugvar)); 387 default: 388 return (EOPNOTSUPP); 389 } 390 /* NOTREACHED */ 391} 392#endif /* DEBUG */ 393 394/* 395 * Validate parameters and get old / set new parameters 396 * for an integer-valued sysctl function. 397 */ 398int 399sysctl_int(oldp, oldlenp, newp, newlen, valp) 400 void *oldp; 401 size_t *oldlenp; 402 void *newp; 403 size_t newlen; 404 int *valp; 405{ 406 int error = 0; 407 408 if (oldp && *oldlenp < sizeof(int)) 409 return (ENOMEM); 410 if (newp && newlen != sizeof(int)) 411 return (EINVAL); 412 *oldlenp = sizeof(int); 413 if (oldp) 414 error = copyout(valp, oldp, sizeof(int)); 415 if (error == 0 && newp) 416 error = copyin(newp, valp, sizeof(int)); 417 return (error); 418} 419 420/* 421 * As above, but read-only. 422 */ 423int 424sysctl_rdint(oldp, oldlenp, newp, val) 425 void *oldp; 426 size_t *oldlenp; 427 void *newp; 428 int val; 429{ 430 int error = 0; 431 432 if (oldp && *oldlenp < sizeof(int)) 433 return (ENOMEM); 434 if (newp) 435 return (EPERM); 436 *oldlenp = sizeof(int); 437 if (oldp) 438 error = copyout((caddr_t)&val, oldp, sizeof(int)); 439 return (error); 440} 441 442/* 443 * Validate parameters and get old / set new parameters 444 * for a string-valued sysctl function. 445 */ 446int 447sysctl_string(oldp, oldlenp, newp, newlen, str, maxlen) 448 void *oldp; 449 size_t *oldlenp; 450 void *newp; 451 size_t newlen; 452 char *str; 453 int maxlen; 454{ 455 int len, error = 0; 456 457 len = strlen(str) + 1; 458 if (oldp && *oldlenp < len) 459 return (ENOMEM); 460 if (newp && newlen >= maxlen) 461 return (EINVAL); 462 if (oldp) { 463 *oldlenp = len; 464 error = copyout(str, oldp, len); 465 } 466 if (error == 0 && newp) { 467 error = copyin(newp, str, newlen); 468 str[newlen] = 0; 469 } 470 return (error); 471} 472 473/* 474 * As above, but read-only. 475 */ 476int 477sysctl_rdstring(oldp, oldlenp, newp, str) 478 void *oldp; 479 size_t *oldlenp; 480 void *newp; 481 char *str; 482{ 483 int len, error = 0; 484 485 len = strlen(str) + 1; 486 if (oldp && *oldlenp < len) 487 return (ENOMEM); 488 if (newp) 489 return (EPERM); 490 *oldlenp = len; 491 if (oldp) 492 error = copyout(str, oldp, len); 493 return (error); 494} 495 496/* 497 * Validate parameters and get old / set new parameters 498 * for a structure oriented sysctl function. 499 */ 500int 501sysctl_struct(oldp, oldlenp, newp, newlen, sp, len) 502 void *oldp; 503 size_t *oldlenp; 504 void *newp; 505 size_t newlen; 506 void *sp; 507 int len; 508{ 509 int error = 0; 510 511 if (oldp && *oldlenp < len) 512 return (ENOMEM); 513 if (newp && newlen > len) 514 return (EINVAL); 515 if (oldp) { 516 *oldlenp = len; 517 error = copyout(sp, oldp, len); 518 } 519 if (error == 0 && newp) 520 error = copyin(newp, sp, len); 521 return (error); 522} 523 524/* 525 * Validate parameters and get old parameters 526 * for a structure oriented sysctl function. 527 */ 528int 529sysctl_rdstruct(oldp, oldlenp, newp, sp, len) 530 void *oldp; 531 size_t *oldlenp; 532 void *newp, *sp; 533 int len; 534{ 535 int error = 0; 536 537 if (oldp && *oldlenp < len) 538 return (ENOMEM); 539 if (newp) 540 return (EPERM); 541 *oldlenp = len; 542 if (oldp) 543 error = copyout(sp, oldp, len); 544 return (error); 545} 546 547/* 548 * Get file structures. 549 */ 550int 551sysctl_file(where, sizep) 552 char *where; 553 size_t *sizep; 554{ 555 int buflen, error; 556 struct file *fp; 557 char *start = where; 558 559 buflen = *sizep; 560 if (where == NULL) { 561 /* 562 * overestimate by 10 files 563 */ 564 *sizep = sizeof(filehead) + (nfiles + 10) * sizeof(struct file); 565 return (0); 566 } 567 568 /* 569 * first copyout filehead 570 */ 571 if (buflen < sizeof(filehead)) { 572 *sizep = 0; 573 return (0); 574 } 575 error = copyout((caddr_t)&filehead, where, sizeof(filehead)); 576 if (error) 577 return (error); 578 buflen -= sizeof(filehead); 579 where += sizeof(filehead); 580 581 /* 582 * followed by an array of file structures 583 */ 584 for (fp = filehead; fp != NULL; fp = fp->f_filef) { 585 if (buflen < sizeof(struct file)) { 586 *sizep = where - start; 587 return (ENOMEM); 588 } 589 error = copyout((caddr_t)fp, where, sizeof (struct file)); 590 if (error) 591 return (error); 592 buflen -= sizeof(struct file); 593 where += sizeof(struct file); 594 } 595 *sizep = where - start; 596 return (0); 597} 598 599/* 600 * try over estimating by 5 procs 601 */ 602#define KERN_PROCSLOP (5 * sizeof (struct kinfo_proc)) 603 604int 605sysctl_doproc(name, namelen, where, sizep) 606 int *name; 607 u_int namelen; 608 char *where; 609 size_t *sizep; 610{ 611 register struct proc *p; 612 register struct kinfo_proc *dp = (struct kinfo_proc *)where; 613 register int needed = 0; 614 int buflen = where != NULL ? *sizep : 0; 615 int doingzomb; 616 struct eproc eproc; 617 int error = 0; 618 619 if (namelen != 2 && !(namelen == 1 && name[0] == KERN_PROC_ALL)) 620 return (EINVAL); 621 p = (struct proc *)allproc; 622 doingzomb = 0; 623again: 624 for (; p != NULL; p = p->p_next) { 625 /* 626 * Skip embryonic processes. 627 */ 628 if (p->p_stat == SIDL) 629 continue; 630 /* 631 * TODO - make more efficient (see notes below). 632 * do by session. 633 */ 634 switch (name[0]) { 635 636 case KERN_PROC_PID: 637 /* could do this with just a lookup */ 638 if (p->p_pid != (pid_t)name[1]) 639 continue; 640 break; 641 642 case KERN_PROC_PGRP: 643 /* could do this by traversing pgrp */ 644 if (p->p_pgrp->pg_id != (pid_t)name[1]) 645 continue; 646 break; 647 648 case KERN_PROC_TTY: 649 if ((p->p_flag & P_CONTROLT) == 0 || 650 p->p_session->s_ttyp == NULL || 651 p->p_session->s_ttyp->t_dev != (dev_t)name[1]) 652 continue; 653 break; 654 655 case KERN_PROC_UID: 656 if (p->p_ucred->cr_uid != (uid_t)name[1]) 657 continue; 658 break; 659 660 case KERN_PROC_RUID: 661 if (p->p_cred->p_ruid != (uid_t)name[1]) 662 continue; 663 break; 664 } 665 if (buflen >= sizeof(struct kinfo_proc)) { 666 fill_eproc(p, &eproc); 667 error = copyout((caddr_t)p, &dp->kp_proc, 668 sizeof(struct proc)); 669 if (error) 670 return (error); 671 error = copyout((caddr_t)&eproc, &dp->kp_eproc, 672 sizeof(eproc)); 673 if (error) 674 return (error); 675 dp++; 676 buflen -= sizeof(struct kinfo_proc); 677 } 678 needed += sizeof(struct kinfo_proc); 679 } 680 if (doingzomb == 0) { 681 p = zombproc; 682 doingzomb++; 683 goto again; 684 } 685 if (where != NULL) { 686 *sizep = (caddr_t)dp - where; 687 if (needed > *sizep) 688 return (ENOMEM); 689 } else { 690 needed += KERN_PROCSLOP; 691 *sizep = needed; 692 } 693 return (0); 694} 695 696/* 697 * Fill in an eproc structure for the specified process. 698 */ 699void 700fill_eproc(p, ep) 701 register struct proc *p; 702 register struct eproc *ep; 703{ 704 register struct tty *tp; 705 706 ep->e_paddr = p; 707 ep->e_sess = p->p_pgrp->pg_session; 708 ep->e_pcred = *p->p_cred; 709 ep->e_ucred = *p->p_ucred; 710 if (p->p_stat == SIDL || p->p_stat == SZOMB) { 711 ep->e_vm.vm_rssize = 0; 712 ep->e_vm.vm_tsize = 0; 713 ep->e_vm.vm_dsize = 0; 714 ep->e_vm.vm_ssize = 0; 715#ifndef sparc 716 /* ep->e_vm.vm_pmap = XXX; */ 717#endif 718 } else { 719 register struct vmspace *vm = p->p_vmspace; 720 721#ifdef pmap_resident_count 722 ep->e_vm.vm_rssize = pmap_resident_count(&vm->vm_pmap); /*XXX*/ 723#else 724 ep->e_vm.vm_rssize = vm->vm_rssize; 725#endif 726 ep->e_vm.vm_tsize = vm->vm_tsize; 727 ep->e_vm.vm_dsize = vm->vm_dsize; 728 ep->e_vm.vm_ssize = vm->vm_ssize; 729#ifndef sparc 730 ep->e_vm.vm_pmap = vm->vm_pmap; 731#endif 732 } 733 if (p->p_pptr) 734 ep->e_ppid = p->p_pptr->p_pid; 735 else 736 ep->e_ppid = 0; 737 ep->e_pgid = p->p_pgrp->pg_id; 738 ep->e_jobc = p->p_pgrp->pg_jobc; 739 if ((p->p_flag & P_CONTROLT) && 740 (tp = ep->e_sess->s_ttyp)) { 741 ep->e_tdev = tp->t_dev; 742 ep->e_tpgid = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PID; 743 ep->e_tsess = tp->t_session; 744 } else 745 ep->e_tdev = NODEV; 746 ep->e_flag = ep->e_sess->s_ttyvp ? EPROC_CTTY : 0; 747 if (SESS_LEADER(p)) 748 ep->e_flag |= EPROC_SLEADER; 749 if (p->p_wmesg) 750 strncpy(ep->e_wmesg, p->p_wmesg, WMESGLEN); 751 ep->e_xsize = ep->e_xrssize = 0; 752 ep->e_xccount = ep->e_xswrss = 0; 753} 754 755#ifdef COMPAT_43 756#include <sys/socket.h> 757#define KINFO_PROC (0<<8) 758#define KINFO_RT (1<<8) 759#define KINFO_VNODE (2<<8) 760#define KINFO_FILE (3<<8) 761#define KINFO_METER (4<<8) 762#define KINFO_LOADAVG (5<<8) 763#define KINFO_CLOCKRATE (6<<8) 764 765struct getkerninfo_args { 766 int op; 767 char *where; 768 int *size; 769 int arg; 770}; 771 772int 773ogetkerninfo(p, uap, retval) 774 struct proc *p; 775 register struct getkerninfo_args *uap; 776 int *retval; 777{ 778 int error, name[5]; 779 u_int size; 780 781 if (uap->size && 782 (error = copyin((caddr_t)uap->size, (caddr_t)&size, sizeof(size)))) 783 return (error); 784 785 switch (uap->op & 0xff00) { 786 787 case KINFO_RT: 788 name[0] = PF_ROUTE; 789 name[1] = 0; 790 name[2] = (uap->op & 0xff0000) >> 16; 791 name[3] = uap->op & 0xff; 792 name[4] = uap->arg; 793 error = net_sysctl(name, 5, uap->where, &size, NULL, 0, p); 794 break; 795 796 case KINFO_VNODE: 797 name[0] = KERN_VNODE; 798 error = kern_sysctl(name, 1, uap->where, &size, NULL, 0, p); 799 break; 800 801 case KINFO_PROC: 802 name[0] = KERN_PROC; 803 name[1] = uap->op & 0xff; 804 name[2] = uap->arg; 805 error = kern_sysctl(name, 3, uap->where, &size, NULL, 0, p); 806 break; 807 808 case KINFO_FILE: 809 name[0] = KERN_FILE; 810 error = kern_sysctl(name, 1, uap->where, &size, NULL, 0, p); 811 break; 812 813 case KINFO_METER: 814 name[0] = VM_METER; 815 error = vm_sysctl(name, 1, uap->where, &size, NULL, 0, p); 816 break; 817 818 case KINFO_LOADAVG: 819 name[0] = VM_LOADAVG; 820 error = vm_sysctl(name, 1, uap->where, &size, NULL, 0, p); 821 break; 822 823 case KINFO_CLOCKRATE: 824 name[0] = KERN_CLOCKRATE; 825 error = kern_sysctl(name, 1, uap->where, &size, NULL, 0, p); 826 break; 827 828 default: 829 return (EOPNOTSUPP); 830 } 831 if (error) 832 return (error); 833 *retval = size; 834 if (uap->size) 835 error = copyout((caddr_t)&size, (caddr_t)uap->size, 836 sizeof(size)); 837 return (error); 838} 839#endif /* COMPAT_43 */ 840