kern_sysctl.c revision 1.108.4.1 1 /* $NetBSD: kern_sysctl.c,v 1.108.4.1 2003/08/24 09:33:27 tron Exp $ */
2
3 /*-
4 * Copyright (c) 1982, 1986, 1989, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Mike Karels at Berkeley Software Design, Inc.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)kern_sysctl.c 8.9 (Berkeley) 5/20/95
39 */
40
41 /*
42 * sysctl system call.
43 */
44
45 #include <sys/cdefs.h>
46 __KERNEL_RCSID(0, "$NetBSD: kern_sysctl.c,v 1.108.4.1 2003/08/24 09:33:27 tron Exp $");
47
48 #include "opt_ddb.h"
49 #include "opt_insecure.h"
50 #include "opt_defcorename.h"
51 #include "opt_pipe.h"
52 #include "opt_sysv.h"
53 #include "pty.h"
54
55 #include <sys/param.h>
56 #include <sys/systm.h>
57 #include <sys/kernel.h>
58 #include <sys/buf.h>
59 #include <sys/device.h>
60 #include <sys/disklabel.h>
61 #include <sys/dkstat.h>
62 #include <sys/exec.h>
63 #include <sys/file.h>
64 #include <sys/ioctl.h>
65 #include <sys/malloc.h>
66 #include <sys/mount.h>
67 #include <sys/msgbuf.h>
68 #include <sys/pool.h>
69 #include <sys/proc.h>
70 #include <sys/resource.h>
71 #include <sys/resourcevar.h>
72 #include <sys/syscallargs.h>
73 #include <sys/tty.h>
74 #include <sys/unistd.h>
75 #include <sys/vnode.h>
76 #include <sys/socketvar.h>
77 #define __SYSCTL_PRIVATE
78 #include <sys/sysctl.h>
79 #include <sys/lock.h>
80 #include <sys/namei.h>
81
82 #if defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM)
83 #include <sys/ipc.h>
84 #endif
85 #ifdef SYSVMSG
86 #include <sys/msg.h>
87 #endif
88 #ifdef SYSVSEM
89 #include <sys/sem.h>
90 #endif
91 #ifdef SYSVSHM
92 #include <sys/shm.h>
93 #endif
94
95 #include <dev/cons.h>
96
97 #if defined(DDB)
98 #include <ddb/ddbvar.h>
99 #endif
100
101 #ifndef PIPE_SOCKETPAIR
102 #include <sys/pipe.h>
103 #endif
104
105 #define PTRTOINT64(foo) ((u_int64_t)(uintptr_t)(foo))
106
107 static int sysctl_file(void *, size_t *);
108 #if defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM)
109 static int sysctl_sysvipc(int *, u_int, void *, size_t *);
110 #endif
111 static int sysctl_msgbuf(void *, size_t *);
112 static int sysctl_doeproc(int *, u_int, void *, size_t *);
113 static int sysctl_dotkstat(int *, u_int, void *, size_t *, void *);
114 #ifdef MULTIPROCESSOR
115 static int sysctl_docptime(void *, size_t *, void *);
116 static int sysctl_ncpus(void);
117 #endif
118 static void fill_kproc2(struct proc *, struct kinfo_proc2 *);
119 static int sysctl_procargs(int *, u_int, void *, size_t *, struct proc *);
120 #if NPTY > 0
121 static int sysctl_pty(void *, size_t *, void *, size_t);
122 #endif
123
124 /*
125 * The `sysctl_memlock' is intended to keep too many processes from
126 * locking down memory by doing sysctls at once. Whether or not this
127 * is really a good idea to worry about it probably a subject of some
128 * debate.
129 */
130 struct lock sysctl_memlock;
131
132 void
133 sysctl_init(void)
134 {
135
136 lockinit(&sysctl_memlock, PRIBIO|PCATCH, "sysctl", 0, 0);
137 }
138
139 int
140 sys___sysctl(struct proc *p, void *v, register_t *retval)
141 {
142 struct sys___sysctl_args /* {
143 syscallarg(int *) name;
144 syscallarg(u_int) namelen;
145 syscallarg(void *) old;
146 syscallarg(size_t *) oldlenp;
147 syscallarg(void *) new;
148 syscallarg(size_t) newlen;
149 } */ *uap = v;
150 int error;
151 size_t savelen = 0, oldlen = 0;
152 sysctlfn *fn;
153 int name[CTL_MAXNAME];
154 size_t *oldlenp;
155
156 /*
157 * all top-level sysctl names are non-terminal
158 */
159 if (SCARG(uap, namelen) > CTL_MAXNAME || SCARG(uap, namelen) < 2)
160 return (EINVAL);
161 error = copyin(SCARG(uap, name), &name,
162 SCARG(uap, namelen) * sizeof(int));
163 if (error)
164 return (error);
165
166 /*
167 * For all but CTL_PROC, must be root to change a value.
168 * For CTL_PROC, must be root, or owner of the proc (and not suid),
169 * this is checked in proc_sysctl() (once we know the targer proc).
170 */
171 if (SCARG(uap, new) != NULL && name[0] != CTL_PROC &&
172 (error = suser(p->p_ucred, &p->p_acflag)))
173 return error;
174
175 switch (name[0]) {
176 case CTL_KERN:
177 fn = kern_sysctl;
178 break;
179 case CTL_HW:
180 fn = hw_sysctl;
181 break;
182 case CTL_VM:
183 fn = uvm_sysctl;
184 break;
185 case CTL_NET:
186 fn = net_sysctl;
187 break;
188 case CTL_VFS:
189 fn = vfs_sysctl;
190 break;
191 case CTL_MACHDEP:
192 fn = cpu_sysctl;
193 break;
194 #ifdef DEBUG
195 case CTL_DEBUG:
196 fn = debug_sysctl;
197 break;
198 #endif
199 #ifdef DDB
200 case CTL_DDB:
201 fn = ddb_sysctl;
202 break;
203 #endif
204 case CTL_PROC:
205 fn = proc_sysctl;
206 break;
207
208 case CTL_EMUL:
209 fn = emul_sysctl;
210 break;
211 default:
212 return (EOPNOTSUPP);
213 }
214
215 /*
216 * XXX Hey, we wire `old', but what about `new'?
217 */
218
219 oldlenp = SCARG(uap, oldlenp);
220 if (oldlenp) {
221 if ((error = copyin(oldlenp, &oldlen, sizeof(oldlen))))
222 return (error);
223 oldlenp = &oldlen;
224 }
225 if (SCARG(uap, old) != NULL) {
226 error = lockmgr(&sysctl_memlock, LK_EXCLUSIVE, NULL);
227 if (error)
228 return (error);
229 error = uvm_vslock(p, SCARG(uap, old), oldlen, VM_PROT_WRITE);
230 if (error) {
231 (void) lockmgr(&sysctl_memlock, LK_RELEASE, NULL);
232 return error;
233 }
234 savelen = oldlen;
235 }
236 error = (*fn)(name + 1, SCARG(uap, namelen) - 1, SCARG(uap, old),
237 oldlenp, SCARG(uap, new), SCARG(uap, newlen), p);
238 if (SCARG(uap, old) != NULL) {
239 uvm_vsunlock(p, SCARG(uap, old), savelen);
240 (void) lockmgr(&sysctl_memlock, LK_RELEASE, NULL);
241 }
242 if (error)
243 return (error);
244 if (SCARG(uap, oldlenp))
245 error = copyout(&oldlen, SCARG(uap, oldlenp), sizeof(oldlen));
246 return (error);
247 }
248
249 /*
250 * Attributes stored in the kernel.
251 */
252 char hostname[MAXHOSTNAMELEN];
253 int hostnamelen;
254
255 char domainname[MAXHOSTNAMELEN];
256 int domainnamelen;
257
258 long hostid;
259
260 #ifdef INSECURE
261 int securelevel = -1;
262 #else
263 int securelevel = 0;
264 #endif
265
266 #ifndef DEFCORENAME
267 #define DEFCORENAME "%n.core"
268 #endif
269 char defcorename[MAXPATHLEN] = DEFCORENAME;
270 int defcorenamelen = sizeof(DEFCORENAME);
271
272 extern int kern_logsigexit;
273 extern fixpt_t ccpu;
274
275 #ifndef MULTIPROCESSOR
276 #define sysctl_ncpus() 1
277 #endif
278
279 #ifdef MULTIPROCESSOR
280
281 #ifndef CPU_INFO_FOREACH
282 #define CPU_INFO_ITERATOR int
283 #define CPU_INFO_FOREACH(cii, ci) cii = 0, ci = curcpu(); ci != NULL; ci = NULL
284 #endif
285
286 static int
287 sysctl_docptime(void *oldp, size_t *oldlenp, void *newp)
288 {
289 u_int64_t cp_time[CPUSTATES];
290 int i;
291 struct cpu_info *ci;
292 CPU_INFO_ITERATOR cii;
293
294 for (i=0; i<CPUSTATES; i++)
295 cp_time[i] = 0;
296
297 for (CPU_INFO_FOREACH(cii, ci)) {
298 for (i=0; i<CPUSTATES; i++)
299 cp_time[i] += ci->ci_schedstate.spc_cp_time[i];
300 }
301 return (sysctl_rdstruct(oldp, oldlenp, newp,
302 cp_time, sizeof(cp_time)));
303 }
304
305 static int
306 sysctl_ncpus(void)
307 {
308 struct cpu_info *ci;
309 CPU_INFO_ITERATOR cii;
310
311 int ncpus = 0;
312 for (CPU_INFO_FOREACH(cii, ci))
313 ncpus++;
314 return ncpus;
315 }
316
317 #endif
318
319 /*
320 * kernel related system variables.
321 */
322 int
323 kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
324 void *newp, size_t newlen, struct proc *p)
325 {
326 int error, level, inthostid;
327 int old_autonicetime;
328 int old_vnodes;
329 dev_t consdev;
330
331 /* All sysctl names at this level, except for a few, are terminal. */
332 switch (name[0]) {
333 case KERN_PROC:
334 case KERN_PROC2:
335 case KERN_PROF:
336 case KERN_MBUF:
337 case KERN_PROC_ARGS:
338 case KERN_SYSVIPC_INFO:
339 case KERN_PIPE:
340 case KERN_TKSTAT:
341 /* Not terminal. */
342 break;
343 default:
344 if (namelen != 1)
345 return (ENOTDIR); /* overloaded */
346 }
347
348 switch (name[0]) {
349 case KERN_OSTYPE:
350 return (sysctl_rdstring(oldp, oldlenp, newp, ostype));
351 case KERN_OSRELEASE:
352 return (sysctl_rdstring(oldp, oldlenp, newp, osrelease));
353 case KERN_OSREV:
354 return (sysctl_rdint(oldp, oldlenp, newp, __NetBSD_Version__));
355 case KERN_VERSION:
356 return (sysctl_rdstring(oldp, oldlenp, newp, version));
357 case KERN_MAXVNODES:
358 old_vnodes = desiredvnodes;
359 error = sysctl_int(oldp, oldlenp, newp, newlen, &desiredvnodes);
360 if (newp && !error) {
361 if (old_vnodes > desiredvnodes) {
362 desiredvnodes = old_vnodes;
363 return (EINVAL);
364 }
365 vfs_reinit();
366 nchreinit();
367 }
368 return (error);
369 case KERN_MAXPROC:
370 return (sysctl_int(oldp, oldlenp, newp, newlen, &maxproc));
371 case KERN_MAXFILES:
372 return (sysctl_int(oldp, oldlenp, newp, newlen, &maxfiles));
373 case KERN_ARGMAX:
374 return (sysctl_rdint(oldp, oldlenp, newp, ARG_MAX));
375 case KERN_SECURELVL:
376 level = securelevel;
377 if ((error = sysctl_int(oldp, oldlenp, newp, newlen, &level)) ||
378 newp == NULL)
379 return (error);
380 if (level < securelevel && p->p_pid != 1)
381 return (EPERM);
382 securelevel = level;
383 return (0);
384 case KERN_HOSTNAME:
385 error = sysctl_string(oldp, oldlenp, newp, newlen,
386 hostname, sizeof(hostname));
387 if (newp && !error)
388 hostnamelen = newlen;
389 return (error);
390 case KERN_DOMAINNAME:
391 error = sysctl_string(oldp, oldlenp, newp, newlen,
392 domainname, sizeof(domainname));
393 if (newp && !error)
394 domainnamelen = newlen;
395 return (error);
396 case KERN_HOSTID:
397 inthostid = hostid; /* XXX assumes sizeof long <= sizeof int */
398 error = sysctl_int(oldp, oldlenp, newp, newlen, &inthostid);
399 if (newp && !error)
400 hostid = inthostid;
401 return (error);
402 case KERN_CLOCKRATE:
403 return (sysctl_clockrate(oldp, oldlenp));
404 case KERN_BOOTTIME:
405 return (sysctl_rdstruct(oldp, oldlenp, newp, &boottime,
406 sizeof(struct timeval)));
407 case KERN_VNODE:
408 return (sysctl_vnode(oldp, oldlenp, p));
409 case KERN_PROC:
410 case KERN_PROC2:
411 return (sysctl_doeproc(name, namelen, oldp, oldlenp));
412 case KERN_PROC_ARGS:
413 return (sysctl_procargs(name + 1, namelen - 1,
414 oldp, oldlenp, p));
415 case KERN_FILE:
416 return (sysctl_file(oldp, oldlenp));
417 #ifdef GPROF
418 case KERN_PROF:
419 return (sysctl_doprof(name + 1, namelen - 1, oldp, oldlenp,
420 newp, newlen));
421 #endif
422 case KERN_POSIX1:
423 return (sysctl_rdint(oldp, oldlenp, newp, _POSIX_VERSION));
424 case KERN_NGROUPS:
425 return (sysctl_rdint(oldp, oldlenp, newp, NGROUPS_MAX));
426 case KERN_JOB_CONTROL:
427 return (sysctl_rdint(oldp, oldlenp, newp, 1));
428 case KERN_SAVED_IDS:
429 #ifdef _POSIX_SAVED_IDS
430 return (sysctl_rdint(oldp, oldlenp, newp, 1));
431 #else
432 return (sysctl_rdint(oldp, oldlenp, newp, 0));
433 #endif
434 case KERN_MAXPARTITIONS:
435 return (sysctl_rdint(oldp, oldlenp, newp, MAXPARTITIONS));
436 case KERN_RAWPARTITION:
437 return (sysctl_rdint(oldp, oldlenp, newp, RAW_PART));
438 #ifdef NTP
439 case KERN_NTPTIME:
440 return (sysctl_ntptime(oldp, oldlenp));
441 #endif
442 case KERN_AUTONICETIME:
443 old_autonicetime = autonicetime;
444 error = sysctl_int(oldp, oldlenp, newp, newlen, &autonicetime);
445 if (autonicetime < 0)
446 autonicetime = old_autonicetime;
447 return (error);
448 case KERN_AUTONICEVAL:
449 error = sysctl_int(oldp, oldlenp, newp, newlen, &autoniceval);
450 if (autoniceval < PRIO_MIN)
451 autoniceval = PRIO_MIN;
452 if (autoniceval > PRIO_MAX)
453 autoniceval = PRIO_MAX;
454 return (error);
455 case KERN_RTC_OFFSET:
456 return (sysctl_rdint(oldp, oldlenp, newp, rtc_offset));
457 case KERN_ROOT_DEVICE:
458 return (sysctl_rdstring(oldp, oldlenp, newp,
459 root_device->dv_xname));
460 case KERN_MSGBUFSIZE:
461 /*
462 * deal with cases where the message buffer has
463 * become corrupted.
464 */
465 if (!msgbufenabled || msgbufp->msg_magic != MSG_MAGIC) {
466 msgbufenabled = 0;
467 return (ENXIO);
468 }
469 return (sysctl_rdint(oldp, oldlenp, newp, msgbufp->msg_bufs));
470 case KERN_FSYNC:
471 return (sysctl_rdint(oldp, oldlenp, newp, 1));
472 case KERN_SYSVMSG:
473 #ifdef SYSVMSG
474 return (sysctl_rdint(oldp, oldlenp, newp, 1));
475 #else
476 return (sysctl_rdint(oldp, oldlenp, newp, 0));
477 #endif
478 case KERN_SYSVSEM:
479 #ifdef SYSVSEM
480 return (sysctl_rdint(oldp, oldlenp, newp, 1));
481 #else
482 return (sysctl_rdint(oldp, oldlenp, newp, 0));
483 #endif
484 case KERN_SYSVSHM:
485 #ifdef SYSVSHM
486 return (sysctl_rdint(oldp, oldlenp, newp, 1));
487 #else
488 return (sysctl_rdint(oldp, oldlenp, newp, 0));
489 #endif
490 case KERN_DEFCORENAME:
491 if (newp && newlen < 1)
492 return (EINVAL);
493 error = sysctl_string(oldp, oldlenp, newp, newlen,
494 defcorename, sizeof(defcorename));
495 if (newp && !error)
496 defcorenamelen = newlen;
497 return (error);
498 case KERN_SYNCHRONIZED_IO:
499 return (sysctl_rdint(oldp, oldlenp, newp, 1));
500 case KERN_IOV_MAX:
501 return (sysctl_rdint(oldp, oldlenp, newp, IOV_MAX));
502 case KERN_MBUF:
503 return (sysctl_dombuf(name + 1, namelen - 1, oldp, oldlenp,
504 newp, newlen));
505 case KERN_MAPPED_FILES:
506 return (sysctl_rdint(oldp, oldlenp, newp, 1));
507 case KERN_MEMLOCK:
508 return (sysctl_rdint(oldp, oldlenp, newp, 1));
509 case KERN_MEMLOCK_RANGE:
510 return (sysctl_rdint(oldp, oldlenp, newp, 1));
511 case KERN_MEMORY_PROTECTION:
512 return (sysctl_rdint(oldp, oldlenp, newp, 1));
513 case KERN_LOGIN_NAME_MAX:
514 return (sysctl_rdint(oldp, oldlenp, newp, LOGIN_NAME_MAX));
515 case KERN_LOGSIGEXIT:
516 return (sysctl_int(oldp, oldlenp, newp, newlen,
517 &kern_logsigexit));
518 case KERN_FSCALE:
519 return (sysctl_rdint(oldp, oldlenp, newp, FSCALE));
520 case KERN_CCPU:
521 return (sysctl_rdint(oldp, oldlenp, newp, ccpu));
522 case KERN_CP_TIME:
523 #ifndef MULTIPROCESSOR
524 return (sysctl_rdstruct(oldp, oldlenp, newp,
525 curcpu()->ci_schedstate.spc_cp_time,
526 sizeof(curcpu()->ci_schedstate.spc_cp_time)));
527 #else
528 return (sysctl_docptime(oldp, oldlenp, newp));
529 #endif
530 #if defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM)
531 case KERN_SYSVIPC_INFO:
532 return (sysctl_sysvipc(name + 1, namelen - 1, oldp, oldlenp));
533 #endif
534 case KERN_MSGBUF:
535 return (sysctl_msgbuf(oldp, oldlenp));
536 case KERN_CONSDEV:
537 if (cn_tab != NULL)
538 consdev = cn_tab->cn_dev;
539 else
540 consdev = NODEV;
541 return (sysctl_rdstruct(oldp, oldlenp, newp, &consdev,
542 sizeof consdev));
543 #if NPTY > 0
544 case KERN_MAXPTYS:
545 return sysctl_pty(oldp, oldlenp, newp, newlen);
546 #endif
547 #ifndef PIPE_SOCKETPAIR
548 case KERN_PIPE:
549 return (sysctl_dopipe(name + 1, namelen - 1, oldp, oldlenp,
550 newp, newlen));
551 #endif
552 case KERN_MAXPHYS:
553 return (sysctl_rdint(oldp, oldlenp, newp, MAXPHYS));
554 case KERN_SBMAX:
555 {
556 int new_sbmax = sb_max;
557
558 error = sysctl_int(oldp, oldlenp, newp, newlen, &new_sbmax);
559 if (newp && !error) {
560 if (new_sbmax < (16 * 1024)) /* sanity */
561 return (EINVAL);
562 sb_max = new_sbmax;
563 }
564 return (error);
565 }
566 case KERN_TKSTAT:
567 return (sysctl_dotkstat(name + 1, namelen - 1, oldp, oldlenp,
568 newp));
569 case KERN_MONOTONIC_CLOCK: /* XXX _POSIX_VERSION */
570 return (sysctl_rdint(oldp, oldlenp, newp, 200112));
571 default:
572 return (EOPNOTSUPP);
573 }
574 /* NOTREACHED */
575 }
576
577 /*
578 * hardware related system variables.
579 */
580 int
581 hw_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
582 void *newp, size_t newlen, struct proc *p)
583 {
584
585 /* All sysctl names at this level, except for a few, are terminal. */
586 switch (name[0]) {
587 case HW_DISKSTATS:
588 /* Not terminal. */
589 break;
590 default:
591 if (namelen != 1)
592 return (ENOTDIR); /* overloaded */
593 }
594
595 switch (name[0]) {
596 case HW_MACHINE:
597 return (sysctl_rdstring(oldp, oldlenp, newp, machine));
598 case HW_MACHINE_ARCH:
599 return (sysctl_rdstring(oldp, oldlenp, newp, machine_arch));
600 case HW_MODEL:
601 return (sysctl_rdstring(oldp, oldlenp, newp, cpu_model));
602 case HW_NCPU:
603 return (sysctl_rdint(oldp, oldlenp, newp, sysctl_ncpus()));
604 case HW_BYTEORDER:
605 return (sysctl_rdint(oldp, oldlenp, newp, BYTE_ORDER));
606 case HW_PHYSMEM:
607 return (sysctl_rdint(oldp, oldlenp, newp, ctob(physmem)));
608 case HW_USERMEM:
609 return (sysctl_rdint(oldp, oldlenp, newp,
610 ctob(physmem - uvmexp.wired)));
611 case HW_PAGESIZE:
612 return (sysctl_rdint(oldp, oldlenp, newp, PAGE_SIZE));
613 case HW_ALIGNBYTES:
614 return (sysctl_rdint(oldp, oldlenp, newp, ALIGNBYTES));
615 case HW_DISKNAMES:
616 return (sysctl_disknames(oldp, oldlenp));
617 case HW_DISKSTATS:
618 return (sysctl_diskstats(name + 1, namelen - 1, oldp, oldlenp));
619 case HW_CNMAGIC: {
620 char magic[CNS_LEN];
621 int error;
622
623 if (oldp)
624 cn_get_magic(magic, CNS_LEN);
625 error = sysctl_string(oldp, oldlenp, newp, newlen,
626 magic, sizeof(magic));
627 if (newp && !error) {
628 error = cn_set_magic(magic);
629 }
630 return (error);
631 }
632 default:
633 return (EOPNOTSUPP);
634 }
635 /* NOTREACHED */
636 }
637
638 #ifdef DEBUG
639 /*
640 * Debugging related system variables.
641 */
642 struct ctldebug /* debug0, */ /* debug1, */ debug2, debug3, debug4;
643 struct ctldebug debug5, debug6, debug7, debug8, debug9;
644 struct ctldebug debug10, debug11, debug12, debug13, debug14;
645 struct ctldebug debug15, debug16, debug17, debug18, debug19;
646 static struct ctldebug *debugvars[CTL_DEBUG_MAXID] = {
647 &debug0, &debug1, &debug2, &debug3, &debug4,
648 &debug5, &debug6, &debug7, &debug8, &debug9,
649 &debug10, &debug11, &debug12, &debug13, &debug14,
650 &debug15, &debug16, &debug17, &debug18, &debug19,
651 };
652
653 int
654 debug_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
655 void *newp, size_t newlen, struct proc *p)
656 {
657 struct ctldebug *cdp;
658
659 /* all sysctl names at this level are name and field */
660 if (namelen != 2)
661 return (ENOTDIR); /* overloaded */
662 if (name[0] >= CTL_DEBUG_MAXID)
663 return (EOPNOTSUPP);
664 cdp = debugvars[name[0]];
665 if (cdp->debugname == 0)
666 return (EOPNOTSUPP);
667 switch (name[1]) {
668 case CTL_DEBUG_NAME:
669 return (sysctl_rdstring(oldp, oldlenp, newp, cdp->debugname));
670 case CTL_DEBUG_VALUE:
671 return (sysctl_int(oldp, oldlenp, newp, newlen, cdp->debugvar));
672 default:
673 return (EOPNOTSUPP);
674 }
675 /* NOTREACHED */
676 }
677 #endif /* DEBUG */
678
679 int
680 proc_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
681 void *newp, size_t newlen, struct proc *p)
682 {
683 struct proc *ptmp = NULL;
684 const struct proclist_desc *pd;
685 int error = 0;
686 struct rlimit alim;
687 struct plimit *newplim;
688 char *tmps = NULL;
689 int i, curlen, len;
690
691 if (namelen < 2)
692 return EINVAL;
693
694 if (name[0] == PROC_CURPROC) {
695 ptmp = p;
696 } else {
697 proclist_lock_read();
698 for (pd = proclists; pd->pd_list != NULL; pd++) {
699 for (ptmp = LIST_FIRST(pd->pd_list); ptmp != NULL;
700 ptmp = LIST_NEXT(ptmp, p_list)) {
701 /* Skip embryonic processes. */
702 if (ptmp->p_stat == SIDL)
703 continue;
704 if (ptmp->p_pid == (pid_t)name[0])
705 break;
706 }
707 if (ptmp != NULL)
708 break;
709 }
710 proclist_unlock_read();
711 if (ptmp == NULL)
712 return(ESRCH);
713 if (p->p_ucred->cr_uid != 0) {
714 if(p->p_cred->p_ruid != ptmp->p_cred->p_ruid ||
715 p->p_cred->p_ruid != ptmp->p_cred->p_svuid)
716 return EPERM;
717 if (ptmp->p_cred->p_rgid != ptmp->p_cred->p_svgid)
718 return EPERM; /* sgid proc */
719 for (i = 0; i < p->p_ucred->cr_ngroups; i++) {
720 if (p->p_ucred->cr_groups[i] ==
721 ptmp->p_cred->p_rgid)
722 break;
723 }
724 if (i == p->p_ucred->cr_ngroups)
725 return EPERM;
726 }
727 }
728 if (name[1] == PROC_PID_CORENAME) {
729 if (namelen != 2)
730 return EINVAL;
731 /*
732 * Can't use sysctl_string() here because we may malloc a new
733 * area during the process, so we have to do it by hand.
734 */
735 curlen = strlen(ptmp->p_limit->pl_corename) + 1;
736 if (oldlenp && *oldlenp < curlen) {
737 if (!oldp)
738 *oldlenp = curlen;
739 return (ENOMEM);
740 }
741 if (newp) {
742 if (securelevel > 2)
743 return EPERM;
744 if (newlen > MAXPATHLEN)
745 return ENAMETOOLONG;
746 tmps = malloc(newlen + 1, M_TEMP, M_WAITOK);
747 if (tmps == NULL)
748 return ENOMEM;
749 error = copyin(newp, tmps, newlen + 1);
750 tmps[newlen] = '\0';
751 if (error)
752 goto cleanup;
753 /* Enforce to be either 'core' for end with '.core' */
754 if (newlen < 4) { /* c.o.r.e */
755 error = EINVAL;
756 goto cleanup;
757 }
758 len = newlen - 4;
759 if (len > 0) {
760 if (tmps[len - 1] != '.' &&
761 tmps[len - 1] != '/') {
762 error = EINVAL;
763 goto cleanup;
764 }
765 }
766 if (strcmp(&tmps[len], "core") != 0) {
767 error = EINVAL;
768 goto cleanup;
769 }
770 }
771 if (oldp && oldlenp) {
772 *oldlenp = curlen;
773 error = copyout(ptmp->p_limit->pl_corename, oldp,
774 curlen);
775 }
776 if (newp && error == 0) {
777 /* if the 2 strings are identical, don't limcopy() */
778 if (strcmp(tmps, ptmp->p_limit->pl_corename) == 0) {
779 error = 0;
780 goto cleanup;
781 }
782 if (ptmp->p_limit->p_refcnt > 1 &&
783 (ptmp->p_limit->p_lflags & PL_SHAREMOD) == 0) {
784 newplim = limcopy(ptmp->p_limit);
785 limfree(ptmp->p_limit);
786 ptmp->p_limit = newplim;
787 }
788 if (ptmp->p_limit->pl_corename != defcorename) {
789 free(ptmp->p_limit->pl_corename, M_TEMP);
790 }
791 ptmp->p_limit->pl_corename = tmps;
792 return (0);
793 }
794 cleanup:
795 if (tmps)
796 free(tmps, M_TEMP);
797 return (error);
798 }
799 if (name[1] == PROC_PID_LIMIT) {
800 if (namelen != 4 || name[2] < 1 ||
801 name[2] >= PROC_PID_LIMIT_MAXID)
802 return EINVAL;
803 memcpy(&alim, &ptmp->p_rlimit[name[2] - 1], sizeof(alim));
804 if (name[3] == PROC_PID_LIMIT_TYPE_HARD)
805 error = sysctl_quad(oldp, oldlenp, newp, newlen,
806 &alim.rlim_max);
807 else if (name[3] == PROC_PID_LIMIT_TYPE_SOFT)
808 error = sysctl_quad(oldp, oldlenp, newp, newlen,
809 &alim.rlim_cur);
810 else
811 error = EINVAL;
812
813 if (error)
814 return error;
815
816 if (newp)
817 error = dosetrlimit(ptmp, p->p_cred,
818 name[2] - 1, &alim);
819 return error;
820 }
821 return (EINVAL);
822 }
823
824 int
825 emul_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
826 void *newp, size_t newlen, struct proc *p)
827 {
828 static struct {
829 const char *name;
830 int type;
831 } emulations[] = CTL_EMUL_NAMES;
832 const struct emul *e;
833 const char *ename;
834 #ifdef LKM
835 extern struct lock exec_lock; /* XXX */
836 int error;
837 #else
838 extern int nexecs_builtin;
839 extern const struct execsw execsw_builtin[];
840 int i;
841 #endif
842
843 /* all sysctl names at this level are name and field */
844 if (namelen < 2)
845 return (ENOTDIR); /* overloaded */
846
847 if ((u_int) name[0] >= EMUL_MAXID || name[0] == 0)
848 return (EOPNOTSUPP);
849
850 ename = emulations[name[0]].name;
851
852 #ifdef LKM
853 lockmgr(&exec_lock, LK_SHARED, NULL);
854 if ((e = emul_search(ename))) {
855 error = (*e->e_sysctl)(name + 1, namelen - 1, oldp, oldlenp,
856 newp, newlen, p);
857 } else
858 error = EOPNOTSUPP;
859 lockmgr(&exec_lock, LK_RELEASE, NULL);
860
861 return (error);
862 #else
863 for (i = 0; i < nexecs_builtin; i++) {
864 e = execsw_builtin[i].es_emul;
865 if (e == NULL || strcmp(ename, e->e_name) != 0 ||
866 e->e_sysctl != NULL)
867 continue;
868
869 return (*e->e_sysctl)(name + 1, namelen - 1, oldp, oldlenp,
870 newp, newlen, p);
871 }
872
873 return (EOPNOTSUPP);
874 #endif
875 }
876 /*
877 * Convenience macros.
878 */
879
880 #define SYSCTL_SCALAR_CORE_LEN(oldp, oldlenp, valp, len) \
881 if (oldlenp) { \
882 if (!oldp) \
883 *oldlenp = len; \
884 else { \
885 if (*oldlenp < len) \
886 return(ENOMEM); \
887 *oldlenp = len; \
888 error = copyout((caddr_t)valp, oldp, len); \
889 } \
890 }
891
892 #define SYSCTL_SCALAR_CORE_TYP(oldp, oldlenp, valp, typ) \
893 SYSCTL_SCALAR_CORE_LEN(oldp, oldlenp, valp, sizeof(typ))
894
895 #define SYSCTL_SCALAR_NEWPCHECK_LEN(newp, newlen, len) \
896 if (newp && newlen != len) \
897 return (EINVAL);
898
899 #define SYSCTL_SCALAR_NEWPCHECK_TYP(newp, newlen, typ) \
900 SYSCTL_SCALAR_NEWPCHECK_LEN(newp, newlen, sizeof(typ))
901
902 #define SYSCTL_SCALAR_NEWPCOP_LEN(newp, valp, len) \
903 if (error == 0 && newp) \
904 error = copyin(newp, valp, len);
905
906 #define SYSCTL_SCALAR_NEWPCOP_TYP(newp, valp, typ) \
907 SYSCTL_SCALAR_NEWPCOP_LEN(newp, valp, sizeof(typ))
908
909 #define SYSCTL_STRING_CORE(oldp, oldlenp, str) \
910 if (oldlenp) { \
911 len = strlen(str) + 1; \
912 if (!oldp) \
913 *oldlenp = len; \
914 else { \
915 if (*oldlenp < len) { \
916 err2 = ENOMEM; \
917 len = *oldlenp; \
918 } else \
919 *oldlenp = len; \
920 error = copyout(str, oldp, len);\
921 if (error == 0) \
922 error = err2; \
923 } \
924 }
925
926 /*
927 * Validate parameters and get old / set new parameters
928 * for an integer-valued sysctl function.
929 */
930 int
931 sysctl_int(void *oldp, size_t *oldlenp, void *newp, size_t newlen, int *valp)
932 {
933 int error = 0;
934
935 SYSCTL_SCALAR_NEWPCHECK_TYP(newp, newlen, int)
936 SYSCTL_SCALAR_CORE_TYP(oldp, oldlenp, valp, int)
937 SYSCTL_SCALAR_NEWPCOP_TYP(newp, valp, int)
938
939 return (error);
940 }
941
942
943 /*
944 * As above, but read-only.
945 */
946 int
947 sysctl_rdint(void *oldp, size_t *oldlenp, void *newp, int val)
948 {
949 int error = 0;
950
951 if (newp)
952 return (EPERM);
953
954 SYSCTL_SCALAR_CORE_TYP(oldp, oldlenp, &val, int)
955
956 return (error);
957 }
958
959 /*
960 * Validate parameters and get old / set new parameters
961 * for an quad-valued sysctl function.
962 */
963 int
964 sysctl_quad(void *oldp, size_t *oldlenp, void *newp, size_t newlen,
965 quad_t *valp)
966 {
967 int error = 0;
968
969 SYSCTL_SCALAR_NEWPCHECK_TYP(newp, newlen, quad_t)
970 SYSCTL_SCALAR_CORE_TYP(oldp, oldlenp, valp, quad_t)
971 SYSCTL_SCALAR_NEWPCOP_TYP(newp, valp, quad_t)
972
973 return (error);
974 }
975
976 /*
977 * As above, but read-only.
978 */
979 int
980 sysctl_rdquad(void *oldp, size_t *oldlenp, void *newp, quad_t val)
981 {
982 int error = 0;
983
984 if (newp)
985 return (EPERM);
986
987 SYSCTL_SCALAR_CORE_TYP(oldp, oldlenp, &val, quad_t)
988
989 return (error);
990 }
991
992 /*
993 * Validate parameters and get old / set new parameters
994 * for a string-valued sysctl function.
995 */
996 int
997 sysctl_string(void *oldp, size_t *oldlenp, void *newp, size_t newlen, char *str,
998 int maxlen)
999 {
1000 int len, error = 0, err2 = 0;
1001
1002 if (newp && newlen >= maxlen)
1003 return (EINVAL);
1004
1005 SYSCTL_STRING_CORE(oldp, oldlenp, str);
1006
1007 if (error == 0 && newp) {
1008 error = copyin(newp, str, newlen);
1009 str[newlen] = 0;
1010 }
1011 return (error);
1012 }
1013
1014 /*
1015 * As above, but read-only.
1016 */
1017 int
1018 sysctl_rdstring(void *oldp, size_t *oldlenp, void *newp, const char *str)
1019 {
1020 int len, error = 0, err2 = 0;
1021
1022 if (newp)
1023 return (EPERM);
1024
1025 SYSCTL_STRING_CORE(oldp, oldlenp, str);
1026
1027 return (error);
1028 }
1029
1030 /*
1031 * Validate parameters and get old / set new parameters
1032 * for a structure oriented sysctl function.
1033 */
1034 int
1035 sysctl_struct(void *oldp, size_t *oldlenp, void *newp, size_t newlen, void *sp,
1036 int len)
1037 {
1038 int error = 0;
1039
1040 SYSCTL_SCALAR_NEWPCHECK_LEN(newp, newlen, len)
1041 SYSCTL_SCALAR_CORE_LEN(oldp, oldlenp, sp, len)
1042 SYSCTL_SCALAR_NEWPCOP_LEN(newp, sp, len)
1043
1044 return (error);
1045 }
1046
1047 /*
1048 * Validate parameters and get old parameters
1049 * for a structure oriented sysctl function.
1050 */
1051 int
1052 sysctl_rdstruct(void *oldp, size_t *oldlenp, void *newp, const void *sp,
1053 int len)
1054 {
1055 int error = 0;
1056
1057 if (newp)
1058 return (EPERM);
1059
1060 SYSCTL_SCALAR_CORE_LEN(oldp, oldlenp, sp, len)
1061
1062 return (error);
1063 }
1064
1065 /*
1066 * As above, but can return a truncated result.
1067 */
1068 int
1069 sysctl_rdminstruct(void *oldp, size_t *oldlenp, void *newp, const void *sp,
1070 int len)
1071 {
1072 int error = 0;
1073
1074 if (newp)
1075 return (EPERM);
1076
1077 len = min(*oldlenp, len);
1078 SYSCTL_SCALAR_CORE_LEN(oldp, oldlenp, sp, len)
1079
1080 return (error);
1081 }
1082
1083 /*
1084 * Get file structures.
1085 */
1086 static int
1087 sysctl_file(void *vwhere, size_t *sizep)
1088 {
1089 int buflen, error;
1090 struct file *fp;
1091 char *start, *where;
1092
1093 start = where = vwhere;
1094 buflen = *sizep;
1095 if (where == NULL) {
1096 /*
1097 * overestimate by 10 files
1098 */
1099 *sizep = sizeof(filehead) + (nfiles + 10) * sizeof(struct file);
1100 return (0);
1101 }
1102
1103 /*
1104 * first copyout filehead
1105 */
1106 if (buflen < sizeof(filehead)) {
1107 *sizep = 0;
1108 return (0);
1109 }
1110 error = copyout((caddr_t)&filehead, where, sizeof(filehead));
1111 if (error)
1112 return (error);
1113 buflen -= sizeof(filehead);
1114 where += sizeof(filehead);
1115
1116 /*
1117 * followed by an array of file structures
1118 */
1119 for (fp = filehead.lh_first; fp != 0; fp = fp->f_list.le_next) {
1120 if (buflen < sizeof(struct file)) {
1121 *sizep = where - start;
1122 return (ENOMEM);
1123 }
1124 error = copyout((caddr_t)fp, where, sizeof(struct file));
1125 if (error)
1126 return (error);
1127 buflen -= sizeof(struct file);
1128 where += sizeof(struct file);
1129 }
1130 *sizep = where - start;
1131 return (0);
1132 }
1133
1134 #if defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM)
1135 #define FILL_PERM(src, dst) do { \
1136 (dst)._key = (src)._key; \
1137 (dst).uid = (src).uid; \
1138 (dst).gid = (src).gid; \
1139 (dst).cuid = (src).cuid; \
1140 (dst).cgid = (src).cgid; \
1141 (dst).mode = (src).mode; \
1142 (dst)._seq = (src)._seq; \
1143 } while (0);
1144 #define FILL_MSG(src, dst) do { \
1145 FILL_PERM((src).msg_perm, (dst).msg_perm); \
1146 (dst).msg_qnum = (src).msg_qnum; \
1147 (dst).msg_qbytes = (src).msg_qbytes; \
1148 (dst)._msg_cbytes = (src)._msg_cbytes; \
1149 (dst).msg_lspid = (src).msg_lspid; \
1150 (dst).msg_lrpid = (src).msg_lrpid; \
1151 (dst).msg_stime = (src).msg_stime; \
1152 (dst).msg_rtime = (src).msg_rtime; \
1153 (dst).msg_ctime = (src).msg_ctime; \
1154 } while (0)
1155 #define FILL_SEM(src, dst) do { \
1156 FILL_PERM((src).sem_perm, (dst).sem_perm); \
1157 (dst).sem_nsems = (src).sem_nsems; \
1158 (dst).sem_otime = (src).sem_otime; \
1159 (dst).sem_ctime = (src).sem_ctime; \
1160 } while (0)
1161 #define FILL_SHM(src, dst) do { \
1162 FILL_PERM((src).shm_perm, (dst).shm_perm); \
1163 (dst).shm_segsz = (src).shm_segsz; \
1164 (dst).shm_lpid = (src).shm_lpid; \
1165 (dst).shm_cpid = (src).shm_cpid; \
1166 (dst).shm_atime = (src).shm_atime; \
1167 (dst).shm_dtime = (src).shm_dtime; \
1168 (dst).shm_ctime = (src).shm_ctime; \
1169 (dst).shm_nattch = (src).shm_nattch; \
1170 } while (0)
1171
1172 static int
1173 sysctl_sysvipc(int *name, u_int namelen, void *where, size_t *sizep)
1174 {
1175 #ifdef SYSVMSG
1176 struct msg_sysctl_info *msgsi;
1177 #endif
1178 #ifdef SYSVSEM
1179 struct sem_sysctl_info *semsi;
1180 #endif
1181 #ifdef SYSVSHM
1182 struct shm_sysctl_info *shmsi;
1183 #endif
1184 size_t infosize, dssize, tsize, buflen;
1185 void *buf = NULL;
1186 char *start;
1187 int32_t nds;
1188 int i, error, ret;
1189
1190 if (namelen != 1)
1191 return (EINVAL);
1192
1193 start = where;
1194 buflen = *sizep;
1195
1196 switch (*name) {
1197 case KERN_SYSVIPC_MSG_INFO:
1198 #ifdef SYSVMSG
1199 infosize = sizeof(msgsi->msginfo);
1200 nds = msginfo.msgmni;
1201 dssize = sizeof(msgsi->msgids[0]);
1202 break;
1203 #else
1204 return (EINVAL);
1205 #endif
1206 case KERN_SYSVIPC_SEM_INFO:
1207 #ifdef SYSVSEM
1208 infosize = sizeof(semsi->seminfo);
1209 nds = seminfo.semmni;
1210 dssize = sizeof(semsi->semids[0]);
1211 break;
1212 #else
1213 return (EINVAL);
1214 #endif
1215 case KERN_SYSVIPC_SHM_INFO:
1216 #ifdef SYSVSHM
1217 infosize = sizeof(shmsi->shminfo);
1218 nds = shminfo.shmmni;
1219 dssize = sizeof(shmsi->shmids[0]);
1220 break;
1221 #else
1222 return (EINVAL);
1223 #endif
1224 default:
1225 return (EINVAL);
1226 }
1227 /*
1228 * Round infosize to 64 bit boundary if requesting more than just
1229 * the info structure or getting the total data size.
1230 */
1231 if (where == NULL || *sizep > infosize)
1232 infosize = ((infosize + 7) / 8) * 8;
1233 tsize = infosize + nds * dssize;
1234
1235 /* Return just the total size required. */
1236 if (where == NULL) {
1237 *sizep = tsize;
1238 return (0);
1239 }
1240
1241 /* Not enough room for even the info struct. */
1242 if (buflen < infosize) {
1243 *sizep = 0;
1244 return (ENOMEM);
1245 }
1246 buf = malloc(min(tsize, buflen), M_TEMP, M_WAITOK);
1247 memset(buf, 0, min(tsize, buflen));
1248
1249 switch (*name) {
1250 #ifdef SYSVMSG
1251 case KERN_SYSVIPC_MSG_INFO:
1252 msgsi = (struct msg_sysctl_info *)buf;
1253 msgsi->msginfo = msginfo;
1254 break;
1255 #endif
1256 #ifdef SYSVSEM
1257 case KERN_SYSVIPC_SEM_INFO:
1258 semsi = (struct sem_sysctl_info *)buf;
1259 semsi->seminfo = seminfo;
1260 break;
1261 #endif
1262 #ifdef SYSVSHM
1263 case KERN_SYSVIPC_SHM_INFO:
1264 shmsi = (struct shm_sysctl_info *)buf;
1265 shmsi->shminfo = shminfo;
1266 break;
1267 #endif
1268 }
1269 buflen -= infosize;
1270
1271 ret = 0;
1272 if (buflen > 0) {
1273 /* Fill in the IPC data structures. */
1274 for (i = 0; i < nds; i++) {
1275 if (buflen < dssize) {
1276 ret = ENOMEM;
1277 break;
1278 }
1279 switch (*name) {
1280 #ifdef SYSVMSG
1281 case KERN_SYSVIPC_MSG_INFO:
1282 FILL_MSG(msqids[i], msgsi->msgids[i]);
1283 break;
1284 #endif
1285 #ifdef SYSVSEM
1286 case KERN_SYSVIPC_SEM_INFO:
1287 FILL_SEM(sema[i], semsi->semids[i]);
1288 break;
1289 #endif
1290 #ifdef SYSVSHM
1291 case KERN_SYSVIPC_SHM_INFO:
1292 FILL_SHM(shmsegs[i], shmsi->shmids[i]);
1293 break;
1294 #endif
1295 }
1296 buflen -= dssize;
1297 }
1298 }
1299 *sizep -= buflen;
1300 error = copyout(buf, start, *sizep);
1301 /* If copyout succeeded, use return code set earlier. */
1302 if (error == 0)
1303 error = ret;
1304 if (buf)
1305 free(buf, M_TEMP);
1306 return (error);
1307 }
1308 #endif /* SYSVMSG || SYSVSEM || SYSVSHM */
1309
1310 static int
1311 sysctl_msgbuf(void *vwhere, size_t *sizep)
1312 {
1313 char *where = vwhere;
1314 size_t len, maxlen = *sizep;
1315 long beg, end;
1316 int error;
1317
1318 /*
1319 * deal with cases where the message buffer has
1320 * become corrupted.
1321 */
1322 if (!msgbufenabled || msgbufp->msg_magic != MSG_MAGIC) {
1323 msgbufenabled = 0;
1324 return (ENXIO);
1325 }
1326
1327 if (where == NULL) {
1328 /* always return full buffer size */
1329 *sizep = msgbufp->msg_bufs;
1330 return (0);
1331 }
1332
1333 error = 0;
1334 maxlen = min(msgbufp->msg_bufs, maxlen);
1335
1336 /*
1337 * First, copy from the write pointer to the end of
1338 * message buffer.
1339 */
1340 beg = msgbufp->msg_bufx;
1341 end = msgbufp->msg_bufs;
1342 while (maxlen > 0) {
1343 len = min(end - beg, maxlen);
1344 if (len == 0)
1345 break;
1346 error = copyout(&msgbufp->msg_bufc[beg], where, len);
1347 if (error)
1348 break;
1349 where += len;
1350 maxlen -= len;
1351
1352 /*
1353 * ... then, copy from the beginning of message buffer to
1354 * the write pointer.
1355 */
1356 beg = 0;
1357 end = msgbufp->msg_bufx;
1358 }
1359 return (error);
1360 }
1361
1362 /*
1363 * try over estimating by 5 procs
1364 */
1365 #define KERN_PROCSLOP (5 * sizeof(struct kinfo_proc))
1366
1367 static int
1368 sysctl_doeproc(int *name, u_int namelen, void *vwhere, size_t *sizep)
1369 {
1370 struct eproc eproc;
1371 struct kinfo_proc2 kproc2;
1372 struct kinfo_proc *dp;
1373 struct proc *p;
1374 const struct proclist_desc *pd;
1375 char *where, *dp2;
1376 int type, op, arg, elem_size, elem_count;
1377 int buflen, needed, error;
1378
1379 dp = vwhere;
1380 dp2 = where = vwhere;
1381 buflen = where != NULL ? *sizep : 0;
1382 error = needed = 0;
1383 type = name[0];
1384
1385 if (type == KERN_PROC) {
1386 if (namelen != 3 && !(namelen == 2 && name[1] == KERN_PROC_ALL))
1387 return (EINVAL);
1388 op = name[1];
1389 if (op != KERN_PROC_ALL)
1390 arg = name[2];
1391 } else {
1392 if (namelen != 5)
1393 return (EINVAL);
1394 op = name[1];
1395 arg = name[2];
1396 elem_size = name[3];
1397 elem_count = name[4];
1398 }
1399
1400 proclist_lock_read();
1401
1402 pd = proclists;
1403 again:
1404 for (p = LIST_FIRST(pd->pd_list); p != NULL; p = LIST_NEXT(p, p_list)) {
1405 /*
1406 * Skip embryonic processes.
1407 */
1408 if (p->p_stat == SIDL)
1409 continue;
1410 /*
1411 * TODO - make more efficient (see notes below).
1412 * do by session.
1413 */
1414 switch (op) {
1415
1416 case KERN_PROC_PID:
1417 /* could do this with just a lookup */
1418 if (p->p_pid != (pid_t)arg)
1419 continue;
1420 break;
1421
1422 case KERN_PROC_PGRP:
1423 /* could do this by traversing pgrp */
1424 if (p->p_pgrp->pg_id != (pid_t)arg)
1425 continue;
1426 break;
1427
1428 case KERN_PROC_SESSION:
1429 if (p->p_session->s_sid != (pid_t)arg)
1430 continue;
1431 break;
1432
1433 case KERN_PROC_TTY:
1434 if (arg == KERN_PROC_TTY_REVOKE) {
1435 if ((p->p_flag & P_CONTROLT) == 0 ||
1436 p->p_session->s_ttyp == NULL ||
1437 p->p_session->s_ttyvp != NULL)
1438 continue;
1439 } else if ((p->p_flag & P_CONTROLT) == 0 ||
1440 p->p_session->s_ttyp == NULL) {
1441 if ((dev_t)arg != KERN_PROC_TTY_NODEV)
1442 continue;
1443 } else if (p->p_session->s_ttyp->t_dev != (dev_t)arg)
1444 continue;
1445 break;
1446
1447 case KERN_PROC_UID:
1448 if (p->p_ucred->cr_uid != (uid_t)arg)
1449 continue;
1450 break;
1451
1452 case KERN_PROC_RUID:
1453 if (p->p_cred->p_ruid != (uid_t)arg)
1454 continue;
1455 break;
1456
1457 case KERN_PROC_GID:
1458 if (p->p_ucred->cr_gid != (uid_t)arg)
1459 continue;
1460 break;
1461
1462 case KERN_PROC_RGID:
1463 if (p->p_cred->p_rgid != (uid_t)arg)
1464 continue;
1465 break;
1466
1467 case KERN_PROC_ALL:
1468 /* allow everything */
1469 break;
1470
1471 default:
1472 error = EINVAL;
1473 goto cleanup;
1474 }
1475 if (type == KERN_PROC) {
1476 if (buflen >= sizeof(struct kinfo_proc)) {
1477 fill_eproc(p, &eproc);
1478 error = copyout((caddr_t)p, &dp->kp_proc,
1479 sizeof(struct proc));
1480 if (error)
1481 goto cleanup;
1482 error = copyout((caddr_t)&eproc, &dp->kp_eproc,
1483 sizeof(eproc));
1484 if (error)
1485 goto cleanup;
1486 dp++;
1487 buflen -= sizeof(struct kinfo_proc);
1488 }
1489 needed += sizeof(struct kinfo_proc);
1490 } else { /* KERN_PROC2 */
1491 if (buflen >= elem_size && elem_count > 0) {
1492 fill_kproc2(p, &kproc2);
1493 /*
1494 * Copy out elem_size, but not larger than
1495 * the size of a struct kinfo_proc2.
1496 */
1497 error = copyout(&kproc2, dp2,
1498 min(sizeof(kproc2), elem_size));
1499 if (error)
1500 goto cleanup;
1501 dp2 += elem_size;
1502 buflen -= elem_size;
1503 elem_count--;
1504 }
1505 needed += elem_size;
1506 }
1507 }
1508 pd++;
1509 if (pd->pd_list != NULL)
1510 goto again;
1511 proclist_unlock_read();
1512
1513 if (where != NULL) {
1514 if (type == KERN_PROC)
1515 *sizep = (caddr_t)dp - where;
1516 else
1517 *sizep = dp2 - where;
1518 if (needed > *sizep)
1519 return (ENOMEM);
1520 } else {
1521 needed += KERN_PROCSLOP;
1522 *sizep = needed;
1523 }
1524 return (0);
1525 cleanup:
1526 proclist_unlock_read();
1527 return (error);
1528 }
1529
1530 /*
1531 * Fill in an eproc structure for the specified process.
1532 */
1533 void
1534 fill_eproc(struct proc *p, struct eproc *ep)
1535 {
1536 struct tty *tp;
1537
1538 ep->e_paddr = p;
1539 ep->e_sess = p->p_session;
1540 ep->e_pcred = *p->p_cred;
1541 ep->e_ucred = *p->p_ucred;
1542 if (p->p_stat == SIDL || P_ZOMBIE(p)) {
1543 ep->e_vm.vm_rssize = 0;
1544 ep->e_vm.vm_tsize = 0;
1545 ep->e_vm.vm_dsize = 0;
1546 ep->e_vm.vm_ssize = 0;
1547 /* ep->e_vm.vm_pmap = XXX; */
1548 } else {
1549 struct vmspace *vm = p->p_vmspace;
1550
1551 ep->e_vm.vm_rssize = vm_resident_count(vm);
1552 ep->e_vm.vm_tsize = vm->vm_tsize;
1553 ep->e_vm.vm_dsize = vm->vm_dsize;
1554 ep->e_vm.vm_ssize = vm->vm_ssize;
1555 }
1556 if (p->p_pptr)
1557 ep->e_ppid = p->p_pptr->p_pid;
1558 else
1559 ep->e_ppid = 0;
1560 ep->e_pgid = p->p_pgrp->pg_id;
1561 ep->e_sid = ep->e_sess->s_sid;
1562 ep->e_jobc = p->p_pgrp->pg_jobc;
1563 if ((p->p_flag & P_CONTROLT) &&
1564 (tp = ep->e_sess->s_ttyp)) {
1565 ep->e_tdev = tp->t_dev;
1566 ep->e_tpgid = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PID;
1567 ep->e_tsess = tp->t_session;
1568 } else
1569 ep->e_tdev = NODEV;
1570 if (p->p_wmesg)
1571 strncpy(ep->e_wmesg, p->p_wmesg, WMESGLEN);
1572 ep->e_xsize = ep->e_xrssize = 0;
1573 ep->e_xccount = ep->e_xswrss = 0;
1574 ep->e_flag = ep->e_sess->s_ttyvp ? EPROC_CTTY : 0;
1575 if (SESS_LEADER(p))
1576 ep->e_flag |= EPROC_SLEADER;
1577 strncpy(ep->e_login, ep->e_sess->s_login, MAXLOGNAME);
1578 }
1579
1580 /*
1581 * Fill in an eproc structure for the specified process.
1582 */
1583 static void
1584 fill_kproc2(struct proc *p, struct kinfo_proc2 *ki)
1585 {
1586 struct tty *tp;
1587
1588 memset(ki, 0, sizeof(*ki));
1589
1590 ki->p_forw = PTRTOINT64(p->p_forw);
1591 ki->p_back = PTRTOINT64(p->p_back);
1592 ki->p_paddr = PTRTOINT64(p);
1593
1594 ki->p_addr = PTRTOINT64(p->p_addr);
1595 ki->p_fd = PTRTOINT64(p->p_fd);
1596 ki->p_cwdi = PTRTOINT64(p->p_cwdi);
1597 ki->p_stats = PTRTOINT64(p->p_stats);
1598 ki->p_limit = PTRTOINT64(p->p_limit);
1599 ki->p_vmspace = PTRTOINT64(p->p_vmspace);
1600 ki->p_sigacts = PTRTOINT64(p->p_sigacts);
1601 ki->p_sess = PTRTOINT64(p->p_session);
1602 ki->p_tsess = 0; /* may be changed if controlling tty below */
1603 ki->p_ru = PTRTOINT64(p->p_ru);
1604
1605 ki->p_eflag = 0;
1606 ki->p_exitsig = p->p_exitsig;
1607 ki->p_flag = p->p_flag;
1608
1609 ki->p_pid = p->p_pid;
1610 if (p->p_pptr)
1611 ki->p_ppid = p->p_pptr->p_pid;
1612 else
1613 ki->p_ppid = 0;
1614 ki->p_sid = p->p_session->s_sid;
1615 ki->p__pgid = p->p_pgrp->pg_id;
1616
1617 ki->p_tpgid = NO_PID; /* may be changed if controlling tty below */
1618
1619 ki->p_uid = p->p_ucred->cr_uid;
1620 ki->p_ruid = p->p_cred->p_ruid;
1621 ki->p_gid = p->p_ucred->cr_gid;
1622 ki->p_rgid = p->p_cred->p_rgid;
1623
1624 memcpy(ki->p_groups, p->p_cred->pc_ucred->cr_groups,
1625 min(sizeof(ki->p_groups), sizeof(p->p_cred->pc_ucred->cr_groups)));
1626 ki->p_ngroups = p->p_cred->pc_ucred->cr_ngroups;
1627
1628 ki->p_jobc = p->p_pgrp->pg_jobc;
1629 if ((p->p_flag & P_CONTROLT) && (tp = p->p_session->s_ttyp)) {
1630 ki->p_tdev = tp->t_dev;
1631 ki->p_tpgid = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PID;
1632 ki->p_tsess = PTRTOINT64(tp->t_session);
1633 } else {
1634 ki->p_tdev = NODEV;
1635 }
1636
1637 ki->p_estcpu = p->p_estcpu;
1638 ki->p_rtime_sec = p->p_rtime.tv_sec;
1639 ki->p_rtime_usec = p->p_rtime.tv_usec;
1640 ki->p_cpticks = p->p_cpticks;
1641 ki->p_pctcpu = p->p_pctcpu;
1642 ki->p_swtime = p->p_swtime;
1643 ki->p_slptime = p->p_slptime;
1644 if (p->p_stat == SONPROC) {
1645 KDASSERT(p->p_cpu != NULL);
1646 ki->p_schedflags = p->p_cpu->ci_schedstate.spc_flags;
1647 } else
1648 ki->p_schedflags = 0;
1649
1650 ki->p_uticks = p->p_uticks;
1651 ki->p_sticks = p->p_sticks;
1652 ki->p_iticks = p->p_iticks;
1653
1654 ki->p_tracep = PTRTOINT64(p->p_tracep);
1655 ki->p_traceflag = p->p_traceflag;
1656
1657 ki->p_holdcnt = p->p_holdcnt;
1658
1659 memcpy(&ki->p_siglist, &p->p_sigctx.ps_siglist, sizeof(ki_sigset_t));
1660 memcpy(&ki->p_sigmask, &p->p_sigctx.ps_sigmask, sizeof(ki_sigset_t));
1661 memcpy(&ki->p_sigignore, &p->p_sigctx.ps_sigignore,sizeof(ki_sigset_t));
1662 memcpy(&ki->p_sigcatch, &p->p_sigctx.ps_sigcatch, sizeof(ki_sigset_t));
1663
1664 ki->p_stat = p->p_stat;
1665 ki->p_priority = p->p_priority;
1666 ki->p_usrpri = p->p_usrpri;
1667 ki->p_nice = p->p_nice;
1668
1669 ki->p_xstat = p->p_xstat;
1670 ki->p_acflag = p->p_acflag;
1671
1672 strncpy(ki->p_comm, p->p_comm,
1673 min(sizeof(ki->p_comm), sizeof(p->p_comm)));
1674
1675 if (p->p_wmesg)
1676 strncpy(ki->p_wmesg, p->p_wmesg, sizeof(ki->p_wmesg));
1677 ki->p_wchan = PTRTOINT64(p->p_wchan);
1678
1679 strncpy(ki->p_login, p->p_session->s_login, sizeof(ki->p_login));
1680
1681 if (p->p_stat == SIDL || P_ZOMBIE(p)) {
1682 ki->p_vm_rssize = 0;
1683 ki->p_vm_tsize = 0;
1684 ki->p_vm_dsize = 0;
1685 ki->p_vm_ssize = 0;
1686 } else {
1687 struct vmspace *vm = p->p_vmspace;
1688
1689 ki->p_vm_rssize = vm_resident_count(vm);
1690 ki->p_vm_tsize = vm->vm_tsize;
1691 ki->p_vm_dsize = vm->vm_dsize;
1692 ki->p_vm_ssize = vm->vm_ssize;
1693 }
1694
1695 if (p->p_session->s_ttyvp)
1696 ki->p_eflag |= EPROC_CTTY;
1697 if (SESS_LEADER(p))
1698 ki->p_eflag |= EPROC_SLEADER;
1699
1700 /* XXX Is this double check necessary? */
1701 if ((p->p_flag & P_INMEM) == 0 || P_ZOMBIE(p)) {
1702 ki->p_uvalid = 0;
1703 } else {
1704 ki->p_uvalid = 1;
1705
1706 ki->p_ustart_sec = p->p_stats->p_start.tv_sec;
1707 ki->p_ustart_usec = p->p_stats->p_start.tv_usec;
1708
1709 ki->p_uutime_sec = p->p_stats->p_ru.ru_utime.tv_sec;
1710 ki->p_uutime_usec = p->p_stats->p_ru.ru_utime.tv_usec;
1711 ki->p_ustime_sec = p->p_stats->p_ru.ru_stime.tv_sec;
1712 ki->p_ustime_usec = p->p_stats->p_ru.ru_stime.tv_usec;
1713
1714 ki->p_uru_maxrss = p->p_stats->p_ru.ru_maxrss;
1715 ki->p_uru_ixrss = p->p_stats->p_ru.ru_ixrss;
1716 ki->p_uru_idrss = p->p_stats->p_ru.ru_idrss;
1717 ki->p_uru_isrss = p->p_stats->p_ru.ru_isrss;
1718 ki->p_uru_minflt = p->p_stats->p_ru.ru_minflt;
1719 ki->p_uru_majflt = p->p_stats->p_ru.ru_majflt;
1720 ki->p_uru_nswap = p->p_stats->p_ru.ru_nswap;
1721 ki->p_uru_inblock = p->p_stats->p_ru.ru_inblock;
1722 ki->p_uru_oublock = p->p_stats->p_ru.ru_oublock;
1723 ki->p_uru_msgsnd = p->p_stats->p_ru.ru_msgsnd;
1724 ki->p_uru_msgrcv = p->p_stats->p_ru.ru_msgrcv;
1725 ki->p_uru_nsignals = p->p_stats->p_ru.ru_nsignals;
1726 ki->p_uru_nvcsw = p->p_stats->p_ru.ru_nvcsw;
1727 ki->p_uru_nivcsw = p->p_stats->p_ru.ru_nivcsw;
1728
1729 ki->p_uctime_sec = p->p_stats->p_cru.ru_utime.tv_sec +
1730 p->p_stats->p_cru.ru_stime.tv_sec;
1731 ki->p_uctime_usec = p->p_stats->p_cru.ru_utime.tv_usec +
1732 p->p_stats->p_cru.ru_stime.tv_usec;
1733 }
1734 #ifdef MULTIPROCESSOR
1735 if (p->p_cpu != NULL)
1736 ki->p_cpuid = p->p_cpu->ci_cpuid;
1737 else
1738 #endif
1739 ki->p_cpuid = KI_NOCPU;
1740 }
1741
1742 int
1743 sysctl_procargs(int *name, u_int namelen, void *where, size_t *sizep,
1744 struct proc *up)
1745 {
1746 struct ps_strings pss;
1747 struct proc *p;
1748 size_t len, upper_bound, xlen;
1749 struct uio auio;
1750 struct iovec aiov;
1751 vaddr_t argv;
1752 pid_t pid;
1753 int nargv, type, error, i;
1754 char *arg;
1755 char *tmp;
1756
1757 if (namelen != 2)
1758 return (EINVAL);
1759 pid = name[0];
1760 type = name[1];
1761
1762 switch (type) {
1763 case KERN_PROC_ARGV:
1764 case KERN_PROC_NARGV:
1765 case KERN_PROC_ENV:
1766 case KERN_PROC_NENV:
1767 /* ok */
1768 break;
1769 default:
1770 return (EINVAL);
1771 }
1772
1773 /* check pid */
1774 if ((p = pfind(pid)) == NULL)
1775 return (EINVAL);
1776
1777 /* only root or same user change look at the environment */
1778 if (type == KERN_PROC_ENV || type == KERN_PROC_NENV) {
1779 if (up->p_ucred->cr_uid != 0) {
1780 if (up->p_cred->p_ruid != p->p_cred->p_ruid ||
1781 up->p_cred->p_ruid != p->p_cred->p_svuid)
1782 return (EPERM);
1783 }
1784 }
1785
1786 if (sizep != NULL && where == NULL) {
1787 if (type == KERN_PROC_NARGV || type == KERN_PROC_NENV)
1788 *sizep = sizeof (int);
1789 else
1790 *sizep = ARG_MAX; /* XXX XXX XXX */
1791 return (0);
1792 }
1793 if (where == NULL || sizep == NULL)
1794 return (EINVAL);
1795
1796 /*
1797 * Zombies don't have a stack, so we can't read their psstrings.
1798 * System processes also don't have a user stack.
1799 */
1800 if (P_ZOMBIE(p) || (p->p_flag & P_SYSTEM) != 0)
1801 return (EINVAL);
1802
1803 /*
1804 * Lock the process down in memory.
1805 */
1806 /* XXXCDC: how should locking work here? */
1807 if ((p->p_flag & P_WEXIT) || (p->p_vmspace->vm_refcnt < 1))
1808 return (EFAULT);
1809 p->p_vmspace->vm_refcnt++; /* XXX */
1810
1811 /*
1812 * Allocate a temporary buffer to hold the arguments.
1813 */
1814 arg = malloc(PAGE_SIZE, M_TEMP, M_WAITOK);
1815
1816 /*
1817 * Read in the ps_strings structure.
1818 */
1819 aiov.iov_base = &pss;
1820 aiov.iov_len = sizeof(pss);
1821 auio.uio_iov = &aiov;
1822 auio.uio_iovcnt = 1;
1823 auio.uio_offset = (vaddr_t)p->p_psstr;
1824 auio.uio_resid = sizeof(pss);
1825 auio.uio_segflg = UIO_SYSSPACE;
1826 auio.uio_rw = UIO_READ;
1827 auio.uio_procp = NULL;
1828 error = uvm_io(&p->p_vmspace->vm_map, &auio);
1829 if (error)
1830 goto done;
1831
1832 if (type == KERN_PROC_ARGV || type == KERN_PROC_NARGV)
1833 memcpy(&nargv, (char *)&pss + p->p_psnargv, sizeof(nargv));
1834 else
1835 memcpy(&nargv, (char *)&pss + p->p_psnenv, sizeof(nargv));
1836 if (type == KERN_PROC_NARGV || type == KERN_PROC_NENV) {
1837 error = copyout(&nargv, where, sizeof(nargv));
1838 *sizep = sizeof(nargv);
1839 goto done;
1840 }
1841 /*
1842 * Now read the address of the argument vector.
1843 */
1844 switch (type) {
1845 case KERN_PROC_ARGV:
1846 /* XXX compat32 stuff here */
1847 memcpy(&tmp, (char *)&pss + p->p_psargv, sizeof(tmp));
1848 break;
1849 case KERN_PROC_ENV:
1850 memcpy(&tmp, (char *)&pss + p->p_psenv, sizeof(tmp));
1851 break;
1852 default:
1853 return (EINVAL);
1854 }
1855 auio.uio_offset = (off_t)(long)tmp;
1856 aiov.iov_base = &argv;
1857 aiov.iov_len = sizeof(argv);
1858 auio.uio_iov = &aiov;
1859 auio.uio_iovcnt = 1;
1860 auio.uio_resid = sizeof(argv);
1861 auio.uio_segflg = UIO_SYSSPACE;
1862 auio.uio_rw = UIO_READ;
1863 auio.uio_procp = NULL;
1864 error = uvm_io(&p->p_vmspace->vm_map, &auio);
1865 if (error)
1866 goto done;
1867
1868 /*
1869 * Now copy in the actual argument vector, one page at a time,
1870 * since we don't know how long the vector is (though, we do
1871 * know how many NUL-terminated strings are in the vector).
1872 */
1873 len = 0;
1874 upper_bound = *sizep;
1875 for (; nargv != 0 && len < upper_bound; len += xlen) {
1876 aiov.iov_base = arg;
1877 aiov.iov_len = PAGE_SIZE;
1878 auio.uio_iov = &aiov;
1879 auio.uio_iovcnt = 1;
1880 auio.uio_offset = argv + len;
1881 xlen = PAGE_SIZE - ((argv + len) & PAGE_MASK);
1882 auio.uio_resid = xlen;
1883 auio.uio_segflg = UIO_SYSSPACE;
1884 auio.uio_rw = UIO_READ;
1885 auio.uio_procp = NULL;
1886 error = uvm_io(&p->p_vmspace->vm_map, &auio);
1887 if (error)
1888 goto done;
1889
1890 for (i = 0; i < xlen && nargv != 0; i++) {
1891 if (arg[i] == '\0')
1892 nargv--; /* one full string */
1893 }
1894
1895 /* make sure we don't copyout past the end of the user's buffer */
1896 if (len + i > upper_bound)
1897 i = upper_bound - len;
1898
1899 error = copyout(arg, (char *)where + len, i);
1900 if (error)
1901 break;
1902
1903 if (nargv == 0) {
1904 len += i;
1905 break;
1906 }
1907 }
1908 *sizep = len;
1909
1910 done:
1911 uvmspace_free(p->p_vmspace);
1912
1913 free(arg, M_TEMP);
1914 return (error);
1915 }
1916
1917 #if NPTY > 0
1918 int pty_maxptys(int, int); /* defined in kern/tty_pty.c */
1919
1920 /*
1921 * Validate parameters and get old / set new parameters
1922 * for pty sysctl function.
1923 */
1924 static int
1925 sysctl_pty(void *oldp, size_t *oldlenp, void *newp, size_t newlen)
1926 {
1927 int error = 0;
1928 int oldmax = 0, newmax = 0;
1929
1930 /* get current value of maxptys */
1931 oldmax = pty_maxptys(0, 0);
1932
1933 SYSCTL_SCALAR_CORE_TYP(oldp, oldlenp, &oldmax, int)
1934
1935 if (!error && newp) {
1936 SYSCTL_SCALAR_NEWPCHECK_TYP(newp, newlen, int)
1937 SYSCTL_SCALAR_NEWPCOP_TYP(newp, &newmax, int)
1938
1939 if (newmax != pty_maxptys(newmax, (newp != NULL)))
1940 return (EINVAL);
1941
1942 }
1943
1944 return (error);
1945 }
1946 #endif /* NPTY > 0 */
1947
1948 static int
1949 sysctl_dotkstat(name, namelen, where, sizep, newp)
1950 int *name;
1951 u_int namelen;
1952 void *where;
1953 size_t *sizep;
1954 void *newp;
1955 {
1956 /* all sysctl names at this level are terminal */
1957 if (namelen != 1)
1958 return (ENOTDIR); /* overloaded */
1959
1960 switch (name[0]) {
1961 case KERN_TKSTAT_NIN:
1962 return (sysctl_rdquad(where, sizep, newp, tk_nin));
1963 case KERN_TKSTAT_NOUT:
1964 return (sysctl_rdquad(where, sizep, newp, tk_nout));
1965 case KERN_TKSTAT_CANCC:
1966 return (sysctl_rdquad(where, sizep, newp, tk_cancc));
1967 case KERN_TKSTAT_RAWCC:
1968 return (sysctl_rdquad(where, sizep, newp, tk_rawcc));
1969 default:
1970 return (EOPNOTSUPP);
1971 }
1972 }
1973