init_sysctl.c revision 1.104 1 /* $NetBSD: init_sysctl.c,v 1.104 2007/08/06 11:51:46 yamt Exp $ */
2
3 /*-
4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Brown.
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 NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.104 2007/08/06 11:51:46 yamt Exp $");
41
42 #include "opt_sysv.h"
43 #include "opt_multiprocessor.h"
44 #include "opt_posix.h"
45 #include "opt_compat_netbsd32.h"
46 #include "opt_ktrace.h"
47 #include "pty.h"
48 #include "rnd.h"
49
50 #include <sys/types.h>
51 #include <sys/param.h>
52 #include <sys/sysctl.h>
53 #include <sys/cpu.h>
54 #include <sys/errno.h>
55 #include <sys/systm.h>
56 #include <sys/kernel.h>
57 #include <sys/unistd.h>
58 #include <sys/disklabel.h>
59 #include <sys/rnd.h>
60 #include <sys/vnode.h>
61 #include <sys/mount.h>
62 #include <sys/namei.h>
63 #include <sys/msgbuf.h>
64 #include <dev/cons.h>
65 #include <sys/socketvar.h>
66 #include <sys/file.h>
67 #include <sys/filedesc.h>
68 #include <sys/tty.h>
69 #include <sys/malloc.h>
70 #include <sys/resource.h>
71 #include <sys/resourcevar.h>
72 #include <sys/exec.h>
73 #include <sys/conf.h>
74 #include <sys/device.h>
75 #include <sys/stat.h>
76 #include <sys/kauth.h>
77 #ifdef KTRACE
78 #include <sys/ktrace.h>
79 #endif
80
81 #ifdef COMPAT_NETBSD32
82 #include <compat/netbsd32/netbsd32.h>
83 #endif
84
85 #include <machine/cpu.h>
86
87 /* XXX this should not be here */
88 int security_setidcore_dump;
89 char security_setidcore_path[MAXPATHLEN] = "/var/crash/%n.core";
90 uid_t security_setidcore_owner = 0;
91 gid_t security_setidcore_group = 0;
92 mode_t security_setidcore_mode = (S_IRUSR|S_IWUSR);
93
94 static const u_int sysctl_flagmap[] = {
95 PK_ADVLOCK, P_ADVLOCK,
96 PK_EXEC, P_EXEC,
97 PK_NOCLDWAIT, P_NOCLDWAIT,
98 PK_32, P_32,
99 PK_CLDSIGIGN, P_CLDSIGIGN,
100 PK_PAXMPROTECT, P_PAXMPROTECT,
101 PK_PAXNOMPROTECT, P_PAXNOMPROTECT,
102 PK_SYSTRACE, P_SYSTRACE,
103 PK_SUGID, P_SUGID,
104 0
105 };
106
107 static const u_int sysctl_sflagmap[] = {
108 PS_NOCLDSTOP, P_NOCLDSTOP,
109 PS_PPWAIT, P_PPWAIT,
110 PS_WEXIT, P_WEXIT,
111 PS_STOPFORK, P_STOPFORK,
112 PS_STOPEXEC, P_STOPEXEC,
113 PS_STOPEXIT, P_STOPEXIT,
114 0
115 };
116
117 static const u_int sysctl_slflagmap[] = {
118 PSL_TRACED, P_TRACED,
119 PSL_FSTRACE, P_FSTRACE,
120 PSL_CHTRACED, P_CHTRACED,
121 PSL_SYSCALL, P_SYSCALL,
122 0
123 };
124
125 static const u_int sysctl_lflagmap[] = {
126 PL_CONTROLT, P_CONTROLT,
127 0
128 };
129
130 static const u_int sysctl_stflagmap[] = {
131 PST_PROFIL, P_PROFIL,
132 0
133
134 };
135
136 static const u_int sysctl_lwpflagmap[] = {
137 LW_INMEM, P_INMEM,
138 LW_SINTR, P_SINTR,
139 LW_SYSTEM, P_SYSTEM,
140 0
141 };
142
143 static const u_int sysctl_lwpprflagmap[] = {
144 LPR_DETACHED, L_DETACHED,
145 0
146 };
147
148
149 /*
150 * try over estimating by 5 procs/lwps
151 */
152 #define KERN_PROCSLOP (5 * sizeof(struct kinfo_proc))
153 #define KERN_LWPSLOP (5 * sizeof(struct kinfo_lwp))
154
155 #ifdef KTRACE
156 int dcopyout(struct lwp *, const void *, void *, size_t);
157
158 int
159 dcopyout(l, kaddr, uaddr, len)
160 struct lwp *l;
161 const void *kaddr;
162 void *uaddr;
163 size_t len;
164 {
165 int error;
166
167 error = copyout(kaddr, uaddr, len);
168 if (!error && KTRPOINT(l->l_proc, KTR_MIB)) {
169 struct iovec iov;
170
171 iov.iov_base = uaddr;
172 iov.iov_len = len;
173 ktrgenio(l, -1, UIO_READ, &iov, len, 0);
174 }
175 return error;
176 }
177 #else /* !KTRACE */
178 #define dcopyout(l, kaddr, uaddr, len) copyout(kaddr, uaddr, len)
179 #endif /* KTRACE */
180
181 #ifdef DIAGNOSTIC
182 static int sysctl_kern_trigger_panic(SYSCTLFN_PROTO);
183 #endif
184 static int sysctl_kern_maxvnodes(SYSCTLFN_PROTO);
185 static int sysctl_kern_rtc_offset(SYSCTLFN_PROTO);
186 static int sysctl_kern_maxproc(SYSCTLFN_PROTO);
187 static int sysctl_kern_hostid(SYSCTLFN_PROTO);
188 static int sysctl_setlen(SYSCTLFN_PROTO);
189 static int sysctl_kern_clockrate(SYSCTLFN_PROTO);
190 static int sysctl_kern_file(SYSCTLFN_PROTO);
191 static int sysctl_msgbuf(SYSCTLFN_PROTO);
192 static int sysctl_kern_defcorename(SYSCTLFN_PROTO);
193 static int sysctl_kern_cptime(SYSCTLFN_PROTO);
194 #if NPTY > 0
195 static int sysctl_kern_maxptys(SYSCTLFN_PROTO);
196 #endif /* NPTY > 0 */
197 static int sysctl_kern_sbmax(SYSCTLFN_PROTO);
198 static int sysctl_kern_urnd(SYSCTLFN_PROTO);
199 static int sysctl_kern_arnd(SYSCTLFN_PROTO);
200 static int sysctl_kern_lwp(SYSCTLFN_PROTO);
201 static int sysctl_kern_forkfsleep(SYSCTLFN_PROTO);
202 static int sysctl_kern_root_partition(SYSCTLFN_PROTO);
203 static int sysctl_kern_drivers(SYSCTLFN_PROTO);
204 static int sysctl_kern_file2(SYSCTLFN_PROTO);
205 static int sysctl_security_setidcore(SYSCTLFN_PROTO);
206 static int sysctl_security_setidcorename(SYSCTLFN_PROTO);
207 static int sysctl_kern_cpid(SYSCTLFN_PROTO);
208 static int sysctl_doeproc(SYSCTLFN_PROTO);
209 static int sysctl_kern_proc_args(SYSCTLFN_PROTO);
210 static int sysctl_hw_usermem(SYSCTLFN_PROTO);
211 static int sysctl_hw_cnmagic(SYSCTLFN_PROTO);
212 static int sysctl_hw_ncpu(SYSCTLFN_PROTO);
213
214 static u_int sysctl_map_flags(const u_int *, u_int);
215 static void fill_kproc2(struct proc *, struct kinfo_proc2 *);
216 static void fill_lwp(struct lwp *l, struct kinfo_lwp *kl);
217 static void fill_file(struct kinfo_file *, const struct file *, struct proc *,
218 int);
219
220 /*
221 * ********************************************************************
222 * section 1: setup routines
223 * ********************************************************************
224 * these functions are stuffed into a link set for sysctl setup
225 * functions. they're never called or referenced from anywhere else.
226 * ********************************************************************
227 */
228
229 /*
230 * sets up the base nodes...
231 */
232 SYSCTL_SETUP(sysctl_root_setup, "sysctl base setup")
233 {
234
235 sysctl_createv(clog, 0, NULL, NULL,
236 CTLFLAG_PERMANENT,
237 CTLTYPE_NODE, "kern",
238 SYSCTL_DESCR("High kernel"),
239 NULL, 0, NULL, 0,
240 CTL_KERN, CTL_EOL);
241 sysctl_createv(clog, 0, NULL, NULL,
242 CTLFLAG_PERMANENT,
243 CTLTYPE_NODE, "vm",
244 SYSCTL_DESCR("Virtual memory"),
245 NULL, 0, NULL, 0,
246 CTL_VM, CTL_EOL);
247 sysctl_createv(clog, 0, NULL, NULL,
248 CTLFLAG_PERMANENT,
249 CTLTYPE_NODE, "vfs",
250 SYSCTL_DESCR("Filesystem"),
251 NULL, 0, NULL, 0,
252 CTL_VFS, CTL_EOL);
253 sysctl_createv(clog, 0, NULL, NULL,
254 CTLFLAG_PERMANENT,
255 CTLTYPE_NODE, "net",
256 SYSCTL_DESCR("Networking"),
257 NULL, 0, NULL, 0,
258 CTL_NET, CTL_EOL);
259 sysctl_createv(clog, 0, NULL, NULL,
260 CTLFLAG_PERMANENT,
261 CTLTYPE_NODE, "debug",
262 SYSCTL_DESCR("Debugging"),
263 NULL, 0, NULL, 0,
264 CTL_DEBUG, CTL_EOL);
265 sysctl_createv(clog, 0, NULL, NULL,
266 CTLFLAG_PERMANENT,
267 CTLTYPE_NODE, "hw",
268 SYSCTL_DESCR("Generic CPU, I/O"),
269 NULL, 0, NULL, 0,
270 CTL_HW, CTL_EOL);
271 sysctl_createv(clog, 0, NULL, NULL,
272 CTLFLAG_PERMANENT,
273 CTLTYPE_NODE, "machdep",
274 SYSCTL_DESCR("Machine dependent"),
275 NULL, 0, NULL, 0,
276 CTL_MACHDEP, CTL_EOL);
277 /*
278 * this node is inserted so that the sysctl nodes in libc can
279 * operate.
280 */
281 sysctl_createv(clog, 0, NULL, NULL,
282 CTLFLAG_PERMANENT,
283 CTLTYPE_NODE, "user",
284 SYSCTL_DESCR("User-level"),
285 NULL, 0, NULL, 0,
286 CTL_USER, CTL_EOL);
287 sysctl_createv(clog, 0, NULL, NULL,
288 CTLFLAG_PERMANENT,
289 CTLTYPE_NODE, "ddb",
290 SYSCTL_DESCR("In-kernel debugger"),
291 NULL, 0, NULL, 0,
292 CTL_DDB, CTL_EOL);
293 sysctl_createv(clog, 0, NULL, NULL,
294 CTLFLAG_PERMANENT,
295 CTLTYPE_NODE, "proc",
296 SYSCTL_DESCR("Per-process"),
297 NULL, 0, NULL, 0,
298 CTL_PROC, CTL_EOL);
299 sysctl_createv(clog, 0, NULL, NULL,
300 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
301 CTLTYPE_NODE, "vendor",
302 SYSCTL_DESCR("Vendor specific"),
303 NULL, 0, NULL, 0,
304 CTL_VENDOR, CTL_EOL);
305 sysctl_createv(clog, 0, NULL, NULL,
306 CTLFLAG_PERMANENT,
307 CTLTYPE_NODE, "emul",
308 SYSCTL_DESCR("Emulation settings"),
309 NULL, 0, NULL, 0,
310 CTL_EMUL, CTL_EOL);
311 sysctl_createv(clog, 0, NULL, NULL,
312 CTLFLAG_PERMANENT,
313 CTLTYPE_NODE, "security",
314 SYSCTL_DESCR("Security"),
315 NULL, 0, NULL, 0,
316 CTL_SECURITY, CTL_EOL);
317 }
318
319 /*
320 * this setup routine is a replacement for kern_sysctl()
321 */
322 SYSCTL_SETUP(sysctl_kern_setup, "sysctl kern subtree setup")
323 {
324 extern int kern_logsigexit; /* defined in kern/kern_sig.c */
325 extern fixpt_t ccpu; /* defined in kern/kern_synch.c */
326 extern int dumponpanic; /* defined in kern/subr_prf.c */
327 const struct sysctlnode *rnode;
328
329 sysctl_createv(clog, 0, NULL, NULL,
330 CTLFLAG_PERMANENT,
331 CTLTYPE_NODE, "kern", NULL,
332 NULL, 0, NULL, 0,
333 CTL_KERN, CTL_EOL);
334
335 sysctl_createv(clog, 0, NULL, NULL,
336 CTLFLAG_PERMANENT,
337 CTLTYPE_STRING, "ostype",
338 SYSCTL_DESCR("Operating system type"),
339 NULL, 0, &ostype, 0,
340 CTL_KERN, KERN_OSTYPE, CTL_EOL);
341 sysctl_createv(clog, 0, NULL, NULL,
342 CTLFLAG_PERMANENT,
343 CTLTYPE_STRING, "osrelease",
344 SYSCTL_DESCR("Operating system release"),
345 NULL, 0, &osrelease, 0,
346 CTL_KERN, KERN_OSRELEASE, CTL_EOL);
347 sysctl_createv(clog, 0, NULL, NULL,
348 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
349 CTLTYPE_INT, "osrevision",
350 SYSCTL_DESCR("Operating system revision"),
351 NULL, __NetBSD_Version__, NULL, 0,
352 CTL_KERN, KERN_OSREV, CTL_EOL);
353 sysctl_createv(clog, 0, NULL, NULL,
354 CTLFLAG_PERMANENT,
355 CTLTYPE_STRING, "version",
356 SYSCTL_DESCR("Kernel version"),
357 NULL, 0, &version, 0,
358 CTL_KERN, KERN_VERSION, CTL_EOL);
359 sysctl_createv(clog, 0, NULL, NULL,
360 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
361 CTLTYPE_INT, "maxvnodes",
362 SYSCTL_DESCR("Maximum number of vnodes"),
363 sysctl_kern_maxvnodes, 0, NULL, 0,
364 CTL_KERN, KERN_MAXVNODES, CTL_EOL);
365 sysctl_createv(clog, 0, NULL, NULL,
366 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
367 CTLTYPE_INT, "maxproc",
368 SYSCTL_DESCR("Maximum number of simultaneous processes"),
369 sysctl_kern_maxproc, 0, NULL, 0,
370 CTL_KERN, KERN_MAXPROC, CTL_EOL);
371 sysctl_createv(clog, 0, NULL, NULL,
372 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
373 CTLTYPE_INT, "maxfiles",
374 SYSCTL_DESCR("Maximum number of open files"),
375 NULL, 0, &maxfiles, 0,
376 CTL_KERN, KERN_MAXFILES, CTL_EOL);
377 sysctl_createv(clog, 0, NULL, NULL,
378 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
379 CTLTYPE_INT, "argmax",
380 SYSCTL_DESCR("Maximum number of bytes of arguments to "
381 "execve(2)"),
382 NULL, ARG_MAX, NULL, 0,
383 CTL_KERN, KERN_ARGMAX, CTL_EOL);
384 sysctl_createv(clog, 0, NULL, NULL,
385 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
386 CTLTYPE_STRING, "hostname",
387 SYSCTL_DESCR("System hostname"),
388 sysctl_setlen, 0, &hostname, MAXHOSTNAMELEN,
389 CTL_KERN, KERN_HOSTNAME, CTL_EOL);
390 sysctl_createv(clog, 0, NULL, NULL,
391 CTLFLAG_PERMANENT|CTLFLAG_READWRITE|CTLFLAG_HEX,
392 CTLTYPE_INT, "hostid",
393 SYSCTL_DESCR("System host ID number"),
394 sysctl_kern_hostid, 0, NULL, 0,
395 CTL_KERN, KERN_HOSTID, CTL_EOL);
396 sysctl_createv(clog, 0, NULL, NULL,
397 CTLFLAG_PERMANENT,
398 CTLTYPE_STRUCT, "clockrate",
399 SYSCTL_DESCR("Kernel clock rates"),
400 sysctl_kern_clockrate, 0, NULL,
401 sizeof(struct clockinfo),
402 CTL_KERN, KERN_CLOCKRATE, CTL_EOL);
403 sysctl_createv(clog, 0, NULL, NULL,
404 CTLFLAG_PERMANENT,
405 CTLTYPE_INT, "hardclock_ticks",
406 SYSCTL_DESCR("Number of hardclock ticks"),
407 NULL, 0, &hardclock_ticks, sizeof(hardclock_ticks),
408 CTL_KERN, KERN_HARDCLOCK_TICKS, CTL_EOL);
409 sysctl_createv(clog, 0, NULL, NULL,
410 CTLFLAG_PERMANENT,
411 CTLTYPE_STRUCT, "vnode",
412 SYSCTL_DESCR("System vnode table"),
413 sysctl_kern_vnode, 0, NULL, 0,
414 CTL_KERN, KERN_VNODE, CTL_EOL);
415 sysctl_createv(clog, 0, NULL, NULL,
416 CTLFLAG_PERMANENT,
417 CTLTYPE_STRUCT, "file",
418 SYSCTL_DESCR("System open file table"),
419 sysctl_kern_file, 0, NULL, 0,
420 CTL_KERN, KERN_FILE, CTL_EOL);
421 #ifndef GPROF
422 sysctl_createv(clog, 0, NULL, NULL,
423 CTLFLAG_PERMANENT,
424 CTLTYPE_NODE, "profiling",
425 SYSCTL_DESCR("Profiling information (not available)"),
426 sysctl_notavail, 0, NULL, 0,
427 CTL_KERN, KERN_PROF, CTL_EOL);
428 #endif
429 sysctl_createv(clog, 0, NULL, NULL,
430 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
431 CTLTYPE_INT, "posix1version",
432 SYSCTL_DESCR("Version of ISO/IEC 9945 (POSIX 1003.1) "
433 "with which the operating system attempts "
434 "to comply"),
435 NULL, _POSIX_VERSION, NULL, 0,
436 CTL_KERN, KERN_POSIX1, CTL_EOL);
437 sysctl_createv(clog, 0, NULL, NULL,
438 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
439 CTLTYPE_INT, "ngroups",
440 SYSCTL_DESCR("Maximum number of supplemental groups"),
441 NULL, NGROUPS_MAX, NULL, 0,
442 CTL_KERN, KERN_NGROUPS, CTL_EOL);
443 sysctl_createv(clog, 0, NULL, NULL,
444 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
445 CTLTYPE_INT, "job_control",
446 SYSCTL_DESCR("Whether job control is available"),
447 NULL, 1, NULL, 0,
448 CTL_KERN, KERN_JOB_CONTROL, CTL_EOL);
449 sysctl_createv(clog, 0, NULL, NULL,
450 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
451 CTLTYPE_INT, "saved_ids",
452 SYSCTL_DESCR("Whether POSIX saved set-group/user ID is "
453 "available"), NULL,
454 #ifdef _POSIX_SAVED_IDS
455 1,
456 #else /* _POSIX_SAVED_IDS */
457 0,
458 #endif /* _POSIX_SAVED_IDS */
459 NULL, 0, CTL_KERN, KERN_SAVED_IDS, CTL_EOL);
460 sysctl_createv(clog, 0, NULL, NULL,
461 CTLFLAG_PERMANENT,
462 CTLTYPE_STRUCT, "boottime",
463 SYSCTL_DESCR("System boot time"),
464 NULL, 0, &boottime, sizeof(boottime),
465 CTL_KERN, KERN_BOOTTIME, CTL_EOL);
466 sysctl_createv(clog, 0, NULL, NULL,
467 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
468 CTLTYPE_STRING, "domainname",
469 SYSCTL_DESCR("YP domain name"),
470 sysctl_setlen, 0, &domainname, MAXHOSTNAMELEN,
471 CTL_KERN, KERN_DOMAINNAME, CTL_EOL);
472 sysctl_createv(clog, 0, NULL, NULL,
473 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
474 CTLTYPE_INT, "maxpartitions",
475 SYSCTL_DESCR("Maximum number of partitions allowed per "
476 "disk"),
477 NULL, MAXPARTITIONS, NULL, 0,
478 CTL_KERN, KERN_MAXPARTITIONS, CTL_EOL);
479 sysctl_createv(clog, 0, NULL, NULL,
480 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
481 CTLTYPE_INT, "rawpartition",
482 SYSCTL_DESCR("Raw partition of a disk"),
483 NULL, RAW_PART, NULL, 0,
484 CTL_KERN, KERN_RAWPARTITION, CTL_EOL);
485 sysctl_createv(clog, 0, NULL, NULL,
486 CTLFLAG_PERMANENT,
487 CTLTYPE_STRUCT, "timex", NULL,
488 sysctl_notavail, 0, NULL, 0,
489 CTL_KERN, KERN_TIMEX, CTL_EOL);
490 sysctl_createv(clog, 0, NULL, NULL,
491 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
492 CTLTYPE_INT, "rtc_offset",
493 SYSCTL_DESCR("Offset of real time clock from UTC in "
494 "minutes"),
495 sysctl_kern_rtc_offset, 0, &rtc_offset, 0,
496 CTL_KERN, KERN_RTC_OFFSET, CTL_EOL);
497 sysctl_createv(clog, 0, NULL, NULL,
498 CTLFLAG_PERMANENT,
499 CTLTYPE_STRING, "root_device",
500 SYSCTL_DESCR("Name of the root device"),
501 sysctl_root_device, 0, NULL, 0,
502 CTL_KERN, KERN_ROOT_DEVICE, CTL_EOL);
503 sysctl_createv(clog, 0, NULL, NULL,
504 CTLFLAG_PERMANENT,
505 CTLTYPE_INT, "msgbufsize",
506 SYSCTL_DESCR("Size of the kernel message buffer"),
507 sysctl_msgbuf, 0, NULL, 0,
508 CTL_KERN, KERN_MSGBUFSIZE, CTL_EOL);
509 sysctl_createv(clog, 0, NULL, NULL,
510 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
511 CTLTYPE_INT, "fsync",
512 SYSCTL_DESCR("Whether the POSIX 1003.1b File "
513 "Synchronization Option is available on "
514 "this system"),
515 NULL, 1, NULL, 0,
516 CTL_KERN, KERN_FSYNC, CTL_EOL);
517 sysctl_createv(clog, 0, NULL, NULL,
518 CTLFLAG_PERMANENT,
519 CTLTYPE_NODE, "ipc",
520 SYSCTL_DESCR("SysV IPC options"),
521 NULL, 0, NULL, 0,
522 CTL_KERN, KERN_SYSVIPC, CTL_EOL);
523 sysctl_createv(clog, 0, NULL, NULL,
524 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
525 CTLTYPE_INT, "sysvmsg",
526 SYSCTL_DESCR("System V style message support available"),
527 NULL,
528 #ifdef SYSVMSG
529 1,
530 #else /* SYSVMSG */
531 0,
532 #endif /* SYSVMSG */
533 NULL, 0, CTL_KERN, KERN_SYSVIPC, KERN_SYSVIPC_MSG, CTL_EOL);
534 sysctl_createv(clog, 0, NULL, NULL,
535 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
536 CTLTYPE_INT, "sysvsem",
537 SYSCTL_DESCR("System V style semaphore support "
538 "available"), NULL,
539 #ifdef SYSVSEM
540 1,
541 #else /* SYSVSEM */
542 0,
543 #endif /* SYSVSEM */
544 NULL, 0, CTL_KERN, KERN_SYSVIPC, KERN_SYSVIPC_SEM, CTL_EOL);
545 sysctl_createv(clog, 0, NULL, NULL,
546 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
547 CTLTYPE_INT, "sysvshm",
548 SYSCTL_DESCR("System V style shared memory support "
549 "available"), NULL,
550 #ifdef SYSVSHM
551 1,
552 #else /* SYSVSHM */
553 0,
554 #endif /* SYSVSHM */
555 NULL, 0, CTL_KERN, KERN_SYSVIPC, KERN_SYSVIPC_SHM, CTL_EOL);
556 sysctl_createv(clog, 0, NULL, NULL,
557 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
558 CTLTYPE_INT, "synchronized_io",
559 SYSCTL_DESCR("Whether the POSIX 1003.1b Synchronized "
560 "I/O Option is available on this system"),
561 NULL, 1, NULL, 0,
562 CTL_KERN, KERN_SYNCHRONIZED_IO, CTL_EOL);
563 sysctl_createv(clog, 0, NULL, NULL,
564 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
565 CTLTYPE_INT, "iov_max",
566 SYSCTL_DESCR("Maximum number of iovec structures per "
567 "process"),
568 NULL, IOV_MAX, NULL, 0,
569 CTL_KERN, KERN_IOV_MAX, CTL_EOL);
570 sysctl_createv(clog, 0, NULL, NULL,
571 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
572 CTLTYPE_INT, "mapped_files",
573 SYSCTL_DESCR("Whether the POSIX 1003.1b Memory Mapped "
574 "Files Option is available on this system"),
575 NULL, 1, NULL, 0,
576 CTL_KERN, KERN_MAPPED_FILES, CTL_EOL);
577 sysctl_createv(clog, 0, NULL, NULL,
578 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
579 CTLTYPE_INT, "memlock",
580 SYSCTL_DESCR("Whether the POSIX 1003.1b Process Memory "
581 "Locking Option is available on this "
582 "system"),
583 NULL, 1, NULL, 0,
584 CTL_KERN, KERN_MEMLOCK, CTL_EOL);
585 sysctl_createv(clog, 0, NULL, NULL,
586 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
587 CTLTYPE_INT, "memlock_range",
588 SYSCTL_DESCR("Whether the POSIX 1003.1b Range Memory "
589 "Locking Option is available on this "
590 "system"),
591 NULL, 1, NULL, 0,
592 CTL_KERN, KERN_MEMLOCK_RANGE, CTL_EOL);
593 sysctl_createv(clog, 0, NULL, NULL,
594 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
595 CTLTYPE_INT, "memory_protection",
596 SYSCTL_DESCR("Whether the POSIX 1003.1b Memory "
597 "Protection Option is available on this "
598 "system"),
599 NULL, 1, NULL, 0,
600 CTL_KERN, KERN_MEMORY_PROTECTION, CTL_EOL);
601 sysctl_createv(clog, 0, NULL, NULL,
602 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
603 CTLTYPE_INT, "login_name_max",
604 SYSCTL_DESCR("Maximum login name length"),
605 NULL, LOGIN_NAME_MAX, NULL, 0,
606 CTL_KERN, KERN_LOGIN_NAME_MAX, CTL_EOL);
607 sysctl_createv(clog, 0, NULL, NULL,
608 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
609 CTLTYPE_STRING, "defcorename",
610 SYSCTL_DESCR("Default core file name"),
611 sysctl_kern_defcorename, 0, defcorename, MAXPATHLEN,
612 CTL_KERN, KERN_DEFCORENAME, CTL_EOL);
613 sysctl_createv(clog, 0, NULL, NULL,
614 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
615 CTLTYPE_INT, "logsigexit",
616 SYSCTL_DESCR("Log process exit when caused by signals"),
617 NULL, 0, &kern_logsigexit, 0,
618 CTL_KERN, KERN_LOGSIGEXIT, CTL_EOL);
619 sysctl_createv(clog, 0, NULL, NULL,
620 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
621 CTLTYPE_INT, "fscale",
622 SYSCTL_DESCR("Kernel fixed-point scale factor"),
623 NULL, FSCALE, NULL, 0,
624 CTL_KERN, KERN_FSCALE, CTL_EOL);
625 sysctl_createv(clog, 0, NULL, NULL,
626 CTLFLAG_PERMANENT,
627 CTLTYPE_INT, "ccpu",
628 SYSCTL_DESCR("Scheduler exponential decay value"),
629 NULL, 0, &ccpu, 0,
630 CTL_KERN, KERN_CCPU, CTL_EOL);
631 sysctl_createv(clog, 0, NULL, NULL,
632 CTLFLAG_PERMANENT,
633 CTLTYPE_STRUCT, "cp_time",
634 SYSCTL_DESCR("Clock ticks spent in different CPU states"),
635 sysctl_kern_cptime, 0, NULL, 0,
636 CTL_KERN, KERN_CP_TIME, CTL_EOL);
637 sysctl_createv(clog, 0, NULL, NULL,
638 CTLFLAG_PERMANENT,
639 CTLTYPE_INT, "msgbuf",
640 SYSCTL_DESCR("Kernel message buffer"),
641 sysctl_msgbuf, 0, NULL, 0,
642 CTL_KERN, KERN_MSGBUF, CTL_EOL);
643 sysctl_createv(clog, 0, NULL, NULL,
644 CTLFLAG_PERMANENT,
645 CTLTYPE_STRUCT, "consdev",
646 SYSCTL_DESCR("Console device"),
647 sysctl_consdev, 0, NULL, sizeof(dev_t),
648 CTL_KERN, KERN_CONSDEV, CTL_EOL);
649 #if NPTY > 0
650 sysctl_createv(clog, 0, NULL, NULL,
651 CTLFLAG_PERMANENT,
652 CTLTYPE_INT, "maxptys",
653 SYSCTL_DESCR("Maximum number of pseudo-ttys"),
654 sysctl_kern_maxptys, 0, NULL, 0,
655 CTL_KERN, KERN_MAXPTYS, CTL_EOL);
656 #endif /* NPTY > 0 */
657 sysctl_createv(clog, 0, NULL, NULL,
658 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
659 CTLTYPE_INT, "maxphys",
660 SYSCTL_DESCR("Maximum raw I/O transfer size"),
661 NULL, MAXPHYS, NULL, 0,
662 CTL_KERN, KERN_MAXPHYS, CTL_EOL);
663 sysctl_createv(clog, 0, NULL, NULL,
664 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
665 CTLTYPE_INT, "sbmax",
666 SYSCTL_DESCR("Maximum socket buffer size"),
667 sysctl_kern_sbmax, 0, NULL, 0,
668 CTL_KERN, KERN_SBMAX, CTL_EOL);
669 sysctl_createv(clog, 0, NULL, NULL,
670 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
671 CTLTYPE_INT, "monotonic_clock",
672 SYSCTL_DESCR("Implementation version of the POSIX "
673 "1003.1b Monotonic Clock Option"),
674 /* XXX _POSIX_VERSION */
675 NULL, _POSIX_MONOTONIC_CLOCK, NULL, 0,
676 CTL_KERN, KERN_MONOTONIC_CLOCK, CTL_EOL);
677 sysctl_createv(clog, 0, NULL, NULL,
678 CTLFLAG_PERMANENT,
679 CTLTYPE_INT, "urandom",
680 SYSCTL_DESCR("Random integer value"),
681 sysctl_kern_urnd, 0, NULL, 0,
682 CTL_KERN, KERN_URND, CTL_EOL);
683 sysctl_createv(clog, 0, NULL, NULL,
684 CTLFLAG_PERMANENT,
685 CTLTYPE_INT, "arandom",
686 SYSCTL_DESCR("n bytes of random data"),
687 sysctl_kern_arnd, 0, NULL, 0,
688 CTL_KERN, KERN_ARND, CTL_EOL);
689 sysctl_createv(clog, 0, NULL, NULL,
690 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
691 CTLTYPE_INT, "labelsector",
692 SYSCTL_DESCR("Sector number containing the disklabel"),
693 NULL, LABELSECTOR, NULL, 0,
694 CTL_KERN, KERN_LABELSECTOR, CTL_EOL);
695 sysctl_createv(clog, 0, NULL, NULL,
696 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
697 CTLTYPE_INT, "labeloffset",
698 SYSCTL_DESCR("Offset of the disklabel within the "
699 "sector"),
700 NULL, LABELOFFSET, NULL, 0,
701 CTL_KERN, KERN_LABELOFFSET, CTL_EOL);
702 sysctl_createv(clog, 0, NULL, NULL,
703 CTLFLAG_PERMANENT,
704 CTLTYPE_NODE, "lwp",
705 SYSCTL_DESCR("System-wide LWP information"),
706 sysctl_kern_lwp, 0, NULL, 0,
707 CTL_KERN, KERN_LWP, CTL_EOL);
708 sysctl_createv(clog, 0, NULL, NULL,
709 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
710 CTLTYPE_INT, "forkfsleep",
711 SYSCTL_DESCR("Milliseconds to sleep on fork failure due "
712 "to process limits"),
713 sysctl_kern_forkfsleep, 0, NULL, 0,
714 CTL_KERN, KERN_FORKFSLEEP, CTL_EOL);
715 sysctl_createv(clog, 0, NULL, NULL,
716 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
717 CTLTYPE_INT, "posix_threads",
718 SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
719 "Threads option to which the system "
720 "attempts to conform"),
721 /* XXX _POSIX_VERSION */
722 NULL, _POSIX_THREADS, NULL, 0,
723 CTL_KERN, KERN_POSIX_THREADS, CTL_EOL);
724 sysctl_createv(clog, 0, NULL, NULL,
725 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
726 CTLTYPE_INT, "posix_semaphores",
727 SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
728 "Semaphores option to which the system "
729 "attempts to conform"), NULL,
730 #ifdef P1003_1B_SEMAPHORE
731 200112,
732 #else /* P1003_1B_SEMAPHORE */
733 0,
734 #endif /* P1003_1B_SEMAPHORE */
735 NULL, 0, CTL_KERN, KERN_POSIX_SEMAPHORES, CTL_EOL);
736 sysctl_createv(clog, 0, NULL, NULL,
737 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
738 CTLTYPE_INT, "posix_barriers",
739 SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
740 "Barriers option to which the system "
741 "attempts to conform"),
742 /* XXX _POSIX_VERSION */
743 NULL, _POSIX_BARRIERS, NULL, 0,
744 CTL_KERN, KERN_POSIX_BARRIERS, CTL_EOL);
745 sysctl_createv(clog, 0, NULL, NULL,
746 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
747 CTLTYPE_INT, "posix_timers",
748 SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
749 "Timers option to which the system "
750 "attempts to conform"),
751 /* XXX _POSIX_VERSION */
752 NULL, _POSIX_TIMERS, NULL, 0,
753 CTL_KERN, KERN_POSIX_TIMERS, CTL_EOL);
754 sysctl_createv(clog, 0, NULL, NULL,
755 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
756 CTLTYPE_INT, "posix_spin_locks",
757 SYSCTL_DESCR("Version of IEEE Std 1003.1 and its Spin "
758 "Locks option to which the system attempts "
759 "to conform"),
760 /* XXX _POSIX_VERSION */
761 NULL, _POSIX_SPIN_LOCKS, NULL, 0,
762 CTL_KERN, KERN_POSIX_SPIN_LOCKS, CTL_EOL);
763 sysctl_createv(clog, 0, NULL, NULL,
764 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
765 CTLTYPE_INT, "posix_reader_writer_locks",
766 SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
767 "Read-Write Locks option to which the "
768 "system attempts to conform"),
769 /* XXX _POSIX_VERSION */
770 NULL, _POSIX_READER_WRITER_LOCKS, NULL, 0,
771 CTL_KERN, KERN_POSIX_READER_WRITER_LOCKS, CTL_EOL);
772 sysctl_createv(clog, 0, NULL, NULL,
773 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
774 CTLTYPE_INT, "dump_on_panic",
775 SYSCTL_DESCR("Perform a crash dump on system panic"),
776 NULL, 0, &dumponpanic, 0,
777 CTL_KERN, KERN_DUMP_ON_PANIC, CTL_EOL);
778 #ifdef DIAGNOSTIC
779 sysctl_createv(clog, 0, NULL, NULL,
780 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
781 CTLTYPE_INT, "panic_now",
782 SYSCTL_DESCR("Trigger a panic"),
783 sysctl_kern_trigger_panic, 0, NULL, 0,
784 CTL_KERN, CTL_CREATE, CTL_EOL);
785 #endif
786 sysctl_createv(clog, 0, NULL, NULL,
787 CTLFLAG_PERMANENT,
788 CTLTYPE_INT, "root_partition",
789 SYSCTL_DESCR("Root partition on the root device"),
790 sysctl_kern_root_partition, 0, NULL, 0,
791 CTL_KERN, KERN_ROOT_PARTITION, CTL_EOL);
792 sysctl_createv(clog, 0, NULL, NULL,
793 CTLFLAG_PERMANENT,
794 CTLTYPE_STRUCT, "drivers",
795 SYSCTL_DESCR("List of all drivers with block and "
796 "character device numbers"),
797 sysctl_kern_drivers, 0, NULL, 0,
798 CTL_KERN, KERN_DRIVERS, CTL_EOL);
799 sysctl_createv(clog, 0, NULL, NULL,
800 CTLFLAG_PERMANENT,
801 CTLTYPE_STRUCT, "file2",
802 SYSCTL_DESCR("System open file table"),
803 sysctl_kern_file2, 0, NULL, 0,
804 CTL_KERN, KERN_FILE2, CTL_EOL);
805 sysctl_createv(clog, 0, NULL, NULL,
806 CTLFLAG_PERMANENT,
807 CTLTYPE_STRUCT, "cp_id",
808 SYSCTL_DESCR("Mapping of CPU number to CPU id"),
809 sysctl_kern_cpid, 0, NULL, 0,
810 CTL_KERN, KERN_CP_ID, CTL_EOL);
811 sysctl_createv(clog, 0, NULL, &rnode,
812 CTLFLAG_PERMANENT,
813 CTLTYPE_NODE, "coredump",
814 SYSCTL_DESCR("Coredump settings."),
815 NULL, 0, NULL, 0,
816 CTL_KERN, CTL_CREATE, CTL_EOL);
817 sysctl_createv(clog, 0, &rnode, &rnode,
818 CTLFLAG_PERMANENT,
819 CTLTYPE_NODE, "setid",
820 SYSCTL_DESCR("Set-id processes' coredump settings."),
821 NULL, 0, NULL, 0,
822 CTL_CREATE, CTL_EOL);
823 sysctl_createv(clog, 0, &rnode, NULL,
824 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
825 CTLTYPE_INT, "dump",
826 SYSCTL_DESCR("Allow set-id processes to dump core."),
827 sysctl_security_setidcore, 0, &security_setidcore_dump,
828 sizeof(security_setidcore_dump),
829 CTL_CREATE, CTL_EOL);
830 sysctl_createv(clog, 0, &rnode, NULL,
831 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
832 CTLTYPE_STRING, "path",
833 SYSCTL_DESCR("Path pattern for set-id coredumps."),
834 sysctl_security_setidcorename, 0,
835 &security_setidcore_path,
836 sizeof(security_setidcore_path),
837 CTL_CREATE, CTL_EOL);
838 sysctl_createv(clog, 0, &rnode, NULL,
839 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
840 CTLTYPE_INT, "owner",
841 SYSCTL_DESCR("Owner id for set-id processes' cores."),
842 sysctl_security_setidcore, 0, &security_setidcore_owner,
843 0,
844 CTL_CREATE, CTL_EOL);
845 sysctl_createv(clog, 0, &rnode, NULL,
846 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
847 CTLTYPE_INT, "group",
848 SYSCTL_DESCR("Group id for set-id processes' cores."),
849 sysctl_security_setidcore, 0, &security_setidcore_group,
850 0,
851 CTL_CREATE, CTL_EOL);
852 sysctl_createv(clog, 0, &rnode, NULL,
853 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
854 CTLTYPE_INT, "mode",
855 SYSCTL_DESCR("Mode for set-id processes' cores."),
856 sysctl_security_setidcore, 0, &security_setidcore_mode,
857 0,
858 CTL_CREATE, CTL_EOL);
859 }
860
861 SYSCTL_SETUP(sysctl_kern_proc_setup,
862 "sysctl kern.proc/proc2/proc_args subtree setup")
863 {
864
865 sysctl_createv(clog, 0, NULL, NULL,
866 CTLFLAG_PERMANENT,
867 CTLTYPE_NODE, "kern", NULL,
868 NULL, 0, NULL, 0,
869 CTL_KERN, CTL_EOL);
870
871 sysctl_createv(clog, 0, NULL, NULL,
872 CTLFLAG_PERMANENT,
873 CTLTYPE_NODE, "proc",
874 SYSCTL_DESCR("System-wide process information"),
875 sysctl_doeproc, 0, NULL, 0,
876 CTL_KERN, KERN_PROC, CTL_EOL);
877 sysctl_createv(clog, 0, NULL, NULL,
878 CTLFLAG_PERMANENT,
879 CTLTYPE_NODE, "proc2",
880 SYSCTL_DESCR("Machine-independent process information"),
881 sysctl_doeproc, 0, NULL, 0,
882 CTL_KERN, KERN_PROC2, CTL_EOL);
883 sysctl_createv(clog, 0, NULL, NULL,
884 CTLFLAG_PERMANENT,
885 CTLTYPE_NODE, "proc_args",
886 SYSCTL_DESCR("Process argument information"),
887 sysctl_kern_proc_args, 0, NULL, 0,
888 CTL_KERN, KERN_PROC_ARGS, CTL_EOL);
889
890 /*
891 "nodes" under these:
892
893 KERN_PROC_ALL
894 KERN_PROC_PID pid
895 KERN_PROC_PGRP pgrp
896 KERN_PROC_SESSION sess
897 KERN_PROC_TTY tty
898 KERN_PROC_UID uid
899 KERN_PROC_RUID uid
900 KERN_PROC_GID gid
901 KERN_PROC_RGID gid
902
903 all in all, probably not worth the effort...
904 */
905 }
906
907 SYSCTL_SETUP(sysctl_hw_setup, "sysctl hw subtree setup")
908 {
909 u_int u;
910 u_quad_t q;
911
912 sysctl_createv(clog, 0, NULL, NULL,
913 CTLFLAG_PERMANENT,
914 CTLTYPE_NODE, "hw", NULL,
915 NULL, 0, NULL, 0,
916 CTL_HW, CTL_EOL);
917
918 sysctl_createv(clog, 0, NULL, NULL,
919 CTLFLAG_PERMANENT,
920 CTLTYPE_STRING, "machine",
921 SYSCTL_DESCR("Machine class"),
922 NULL, 0, machine, 0,
923 CTL_HW, HW_MACHINE, CTL_EOL);
924 sysctl_createv(clog, 0, NULL, NULL,
925 CTLFLAG_PERMANENT,
926 CTLTYPE_STRING, "model",
927 SYSCTL_DESCR("Machine model"),
928 NULL, 0, cpu_model, 0,
929 CTL_HW, HW_MODEL, CTL_EOL);
930 sysctl_createv(clog, 0, NULL, NULL,
931 CTLFLAG_PERMANENT,
932 CTLTYPE_INT, "ncpu",
933 SYSCTL_DESCR("Number of active CPUs"),
934 sysctl_hw_ncpu, 0, NULL, 0,
935 CTL_HW, HW_NCPU, CTL_EOL);
936 sysctl_createv(clog, 0, NULL, NULL,
937 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
938 CTLTYPE_INT, "byteorder",
939 SYSCTL_DESCR("System byte order"),
940 NULL, BYTE_ORDER, NULL, 0,
941 CTL_HW, HW_BYTEORDER, CTL_EOL);
942 u = ((u_int)physmem > (UINT_MAX / PAGE_SIZE)) ?
943 UINT_MAX : physmem * PAGE_SIZE;
944 sysctl_createv(clog, 0, NULL, NULL,
945 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
946 CTLTYPE_INT, "physmem",
947 SYSCTL_DESCR("Bytes of physical memory"),
948 NULL, u, NULL, 0,
949 CTL_HW, HW_PHYSMEM, CTL_EOL);
950 sysctl_createv(clog, 0, NULL, NULL,
951 CTLFLAG_PERMANENT,
952 CTLTYPE_INT, "usermem",
953 SYSCTL_DESCR("Bytes of non-kernel memory"),
954 sysctl_hw_usermem, 0, NULL, 0,
955 CTL_HW, HW_USERMEM, CTL_EOL);
956 sysctl_createv(clog, 0, NULL, NULL,
957 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
958 CTLTYPE_INT, "pagesize",
959 SYSCTL_DESCR("Software page size"),
960 NULL, PAGE_SIZE, NULL, 0,
961 CTL_HW, HW_PAGESIZE, CTL_EOL);
962 sysctl_createv(clog, 0, NULL, NULL,
963 CTLFLAG_PERMANENT,
964 CTLTYPE_STRING, "machine_arch",
965 SYSCTL_DESCR("Machine CPU class"),
966 NULL, 0, machine_arch, 0,
967 CTL_HW, HW_MACHINE_ARCH, CTL_EOL);
968 sysctl_createv(clog, 0, NULL, NULL,
969 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
970 CTLTYPE_INT, "alignbytes",
971 SYSCTL_DESCR("Alignment constraint for all possible "
972 "data types"),
973 NULL, ALIGNBYTES, NULL, 0,
974 CTL_HW, HW_ALIGNBYTES, CTL_EOL);
975 sysctl_createv(clog, 0, NULL, NULL,
976 CTLFLAG_PERMANENT|CTLFLAG_READWRITE|CTLFLAG_HEX,
977 CTLTYPE_STRING, "cnmagic",
978 SYSCTL_DESCR("Console magic key sequence"),
979 sysctl_hw_cnmagic, 0, NULL, CNS_LEN,
980 CTL_HW, HW_CNMAGIC, CTL_EOL);
981 q = (u_quad_t)physmem * PAGE_SIZE;
982 sysctl_createv(clog, 0, NULL, NULL,
983 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
984 CTLTYPE_QUAD, "physmem64",
985 SYSCTL_DESCR("Bytes of physical memory"),
986 NULL, q, NULL, 0,
987 CTL_HW, HW_PHYSMEM64, CTL_EOL);
988 sysctl_createv(clog, 0, NULL, NULL,
989 CTLFLAG_PERMANENT,
990 CTLTYPE_QUAD, "usermem64",
991 SYSCTL_DESCR("Bytes of non-kernel memory"),
992 sysctl_hw_usermem, 0, NULL, 0,
993 CTL_HW, HW_USERMEM64, CTL_EOL);
994 }
995
996 #ifdef DEBUG
997 /*
998 * Debugging related system variables.
999 */
1000 struct ctldebug /* debug0, */ /* debug1, */ debug2, debug3, debug4;
1001 struct ctldebug debug5, debug6, debug7, debug8, debug9;
1002 struct ctldebug debug10, debug11, debug12, debug13, debug14;
1003 struct ctldebug debug15, debug16, debug17, debug18, debug19;
1004 static struct ctldebug *debugvars[CTL_DEBUG_MAXID] = {
1005 &debug0, &debug1, &debug2, &debug3, &debug4,
1006 &debug5, &debug6, &debug7, &debug8, &debug9,
1007 &debug10, &debug11, &debug12, &debug13, &debug14,
1008 &debug15, &debug16, &debug17, &debug18, &debug19,
1009 };
1010
1011 /*
1012 * this setup routine is a replacement for debug_sysctl()
1013 *
1014 * note that it creates several nodes per defined debug variable
1015 */
1016 SYSCTL_SETUP(sysctl_debug_setup, "sysctl debug subtree setup")
1017 {
1018 struct ctldebug *cdp;
1019 char nodename[20];
1020 int i;
1021
1022 /*
1023 * two ways here:
1024 *
1025 * the "old" way (debug.name -> value) which was emulated by
1026 * the sysctl(8) binary
1027 *
1028 * the new way, which the sysctl(8) binary was actually using
1029
1030 node debug
1031 node debug.0
1032 string debug.0.name
1033 int debug.0.value
1034 int debug.name
1035
1036 */
1037
1038 sysctl_createv(clog, 0, NULL, NULL,
1039 CTLFLAG_PERMANENT,
1040 CTLTYPE_NODE, "debug", NULL,
1041 NULL, 0, NULL, 0,
1042 CTL_DEBUG, CTL_EOL);
1043
1044 for (i = 0; i < CTL_DEBUG_MAXID; i++) {
1045 cdp = debugvars[i];
1046 if (cdp->debugname == NULL || cdp->debugvar == NULL)
1047 continue;
1048
1049 snprintf(nodename, sizeof(nodename), "debug%d", i);
1050 sysctl_createv(clog, 0, NULL, NULL,
1051 CTLFLAG_PERMANENT|CTLFLAG_HIDDEN,
1052 CTLTYPE_NODE, nodename, NULL,
1053 NULL, 0, NULL, 0,
1054 CTL_DEBUG, i, CTL_EOL);
1055 sysctl_createv(clog, 0, NULL, NULL,
1056 CTLFLAG_PERMANENT|CTLFLAG_HIDDEN,
1057 CTLTYPE_STRING, "name", NULL,
1058 /*XXXUNCONST*/
1059 NULL, 0, __UNCONST(cdp->debugname), 0,
1060 CTL_DEBUG, i, CTL_DEBUG_NAME, CTL_EOL);
1061 sysctl_createv(clog, 0, NULL, NULL,
1062 CTLFLAG_PERMANENT|CTLFLAG_HIDDEN,
1063 CTLTYPE_INT, "value", NULL,
1064 NULL, 0, cdp->debugvar, 0,
1065 CTL_DEBUG, i, CTL_DEBUG_VALUE, CTL_EOL);
1066 sysctl_createv(clog, 0, NULL, NULL,
1067 CTLFLAG_PERMANENT,
1068 CTLTYPE_INT, cdp->debugname, NULL,
1069 NULL, 0, cdp->debugvar, 0,
1070 CTL_DEBUG, CTL_CREATE, CTL_EOL);
1071 }
1072 }
1073 #endif /* DEBUG */
1074
1075 /*
1076 * ********************************************************************
1077 * section 2: private node-specific helper routines.
1078 * ********************************************************************
1079 */
1080
1081 #ifdef DIAGNOSTIC
1082 static int
1083 sysctl_kern_trigger_panic(SYSCTLFN_ARGS)
1084 {
1085 int newtrig, error;
1086 struct sysctlnode node;
1087
1088 newtrig = 0;
1089 node = *rnode;
1090 node.sysctl_data = &newtrig;
1091 error = sysctl_lookup(SYSCTLFN_CALL(&node));
1092 if (error || newp == NULL)
1093 return (error);
1094
1095 if (newtrig != 0)
1096 panic("Panic triggered");
1097
1098 return (error);
1099 }
1100 #endif
1101
1102 /*
1103 * sysctl helper routine for kern.maxvnodes. drain vnodes if
1104 * new value is lower than desiredvnodes and then calls reinit
1105 * routines that needs to adjust to the new value.
1106 */
1107 static int
1108 sysctl_kern_maxvnodes(SYSCTLFN_ARGS)
1109 {
1110 int error, new_vnodes, old_vnodes;
1111 struct sysctlnode node;
1112
1113 new_vnodes = desiredvnodes;
1114 node = *rnode;
1115 node.sysctl_data = &new_vnodes;
1116 error = sysctl_lookup(SYSCTLFN_CALL(&node));
1117 if (error || newp == NULL)
1118 return (error);
1119
1120 old_vnodes = desiredvnodes;
1121 desiredvnodes = new_vnodes;
1122 if (new_vnodes < old_vnodes) {
1123 error = vfs_drainvnodes(new_vnodes, l);
1124 if (error) {
1125 desiredvnodes = old_vnodes;
1126 return (error);
1127 }
1128 }
1129 vfs_reinit();
1130 nchreinit();
1131
1132 return (0);
1133 }
1134
1135 /*
1136 * sysctl helper routine for rtc_offset - set time after changes
1137 */
1138 static int
1139 sysctl_kern_rtc_offset(SYSCTLFN_ARGS)
1140 {
1141 struct timespec ts, delta;
1142 int error, new_rtc_offset;
1143 struct sysctlnode node;
1144
1145 new_rtc_offset = rtc_offset;
1146 node = *rnode;
1147 node.sysctl_data = &new_rtc_offset;
1148 error = sysctl_lookup(SYSCTLFN_CALL(&node));
1149 if (error || newp == NULL)
1150 return (error);
1151
1152 if (kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_TIME,
1153 KAUTH_REQ_SYSTEM_TIME_RTCOFFSET,
1154 (void *)(u_long)new_rtc_offset, NULL, NULL))
1155 return (EPERM);
1156 if (rtc_offset == new_rtc_offset)
1157 return (0);
1158
1159 /* if we change the offset, adjust the time */
1160 nanotime(&ts);
1161 delta.tv_sec = 60 * (new_rtc_offset - rtc_offset);
1162 delta.tv_nsec = 0;
1163 timespecadd(&ts, &delta, &ts);
1164 rtc_offset = new_rtc_offset;
1165 settime(l->l_proc, &ts);
1166
1167 return (0);
1168 }
1169
1170 /*
1171 * sysctl helper routine for kern.maxproc. ensures that the new
1172 * values are not too low or too high.
1173 */
1174 static int
1175 sysctl_kern_maxproc(SYSCTLFN_ARGS)
1176 {
1177 int error, nmaxproc;
1178 struct sysctlnode node;
1179
1180 nmaxproc = maxproc;
1181 node = *rnode;
1182 node.sysctl_data = &nmaxproc;
1183 error = sysctl_lookup(SYSCTLFN_CALL(&node));
1184 if (error || newp == NULL)
1185 return (error);
1186
1187 if (nmaxproc < 0 || nmaxproc >= PID_MAX)
1188 return (EINVAL);
1189 #ifdef __HAVE_CPU_MAXPROC
1190 if (nmaxproc > cpu_maxproc())
1191 return (EINVAL);
1192 #endif
1193 maxproc = nmaxproc;
1194
1195 return (0);
1196 }
1197
1198 /*
1199 * sysctl helper function for kern.hostid. the hostid is a long, but
1200 * we export it as an int, so we need to give it a little help.
1201 */
1202 static int
1203 sysctl_kern_hostid(SYSCTLFN_ARGS)
1204 {
1205 int error, inthostid;
1206 struct sysctlnode node;
1207
1208 inthostid = hostid; /* XXX assumes sizeof int <= sizeof long */
1209 node = *rnode;
1210 node.sysctl_data = &inthostid;
1211 error = sysctl_lookup(SYSCTLFN_CALL(&node));
1212 if (error || newp == NULL)
1213 return (error);
1214
1215 hostid = (unsigned)inthostid;
1216
1217 return (0);
1218 }
1219
1220 /*
1221 * sysctl helper function for kern.hostname and kern.domainnname.
1222 * resets the relevant recorded length when the underlying name is
1223 * changed.
1224 */
1225 static int
1226 sysctl_setlen(SYSCTLFN_ARGS)
1227 {
1228 int error;
1229
1230 error = sysctl_lookup(SYSCTLFN_CALL(rnode));
1231 if (error || newp == NULL)
1232 return (error);
1233
1234 switch (rnode->sysctl_num) {
1235 case KERN_HOSTNAME:
1236 hostnamelen = strlen((const char*)rnode->sysctl_data);
1237 break;
1238 case KERN_DOMAINNAME:
1239 domainnamelen = strlen((const char*)rnode->sysctl_data);
1240 break;
1241 }
1242
1243 return (0);
1244 }
1245
1246 /*
1247 * sysctl helper routine for kern.clockrate. assembles a struct on
1248 * the fly to be returned to the caller.
1249 */
1250 static int
1251 sysctl_kern_clockrate(SYSCTLFN_ARGS)
1252 {
1253 struct clockinfo clkinfo;
1254 struct sysctlnode node;
1255
1256 clkinfo.tick = tick;
1257 clkinfo.tickadj = tickadj;
1258 clkinfo.hz = hz;
1259 clkinfo.profhz = profhz;
1260 clkinfo.stathz = stathz ? stathz : hz;
1261
1262 node = *rnode;
1263 node.sysctl_data = &clkinfo;
1264 return (sysctl_lookup(SYSCTLFN_CALL(&node)));
1265 }
1266
1267
1268 /*
1269 * sysctl helper routine for kern.file pseudo-subtree.
1270 */
1271 static int
1272 sysctl_kern_file(SYSCTLFN_ARGS)
1273 {
1274 int error;
1275 size_t buflen;
1276 struct file *fp;
1277 char *start, *where;
1278
1279 start = where = oldp;
1280 buflen = *oldlenp;
1281 if (where == NULL) {
1282 /*
1283 * overestimate by 10 files
1284 */
1285 *oldlenp = sizeof(filehead) + (nfiles + 10) * sizeof(struct file);
1286 return (0);
1287 }
1288
1289 /*
1290 * first dcopyout filehead
1291 */
1292 if (buflen < sizeof(filehead)) {
1293 *oldlenp = 0;
1294 return (0);
1295 }
1296 error = dcopyout(l, &filehead, where, sizeof(filehead));
1297 if (error)
1298 return (error);
1299 buflen -= sizeof(filehead);
1300 where += sizeof(filehead);
1301
1302 /*
1303 * followed by an array of file structures
1304 */
1305 LIST_FOREACH(fp, &filehead, f_list) {
1306 if (kauth_authorize_generic(l->l_cred,
1307 KAUTH_GENERIC_CANSEE, fp->f_cred) != 0)
1308 continue;
1309 if (buflen < sizeof(struct file)) {
1310 *oldlenp = where - start;
1311 return (ENOMEM);
1312 }
1313 error = dcopyout(l, fp, where, sizeof(struct file));
1314 if (error)
1315 return (error);
1316 buflen -= sizeof(struct file);
1317 where += sizeof(struct file);
1318 }
1319 *oldlenp = where - start;
1320 return (0);
1321 }
1322
1323 /*
1324 * sysctl helper routine for kern.msgbufsize and kern.msgbuf. for the
1325 * former it merely checks the message buffer is set up. for the latter,
1326 * it also copies out the data if necessary.
1327 */
1328 static int
1329 sysctl_msgbuf(SYSCTLFN_ARGS)
1330 {
1331 char *where = oldp;
1332 size_t len, maxlen;
1333 long beg, end;
1334 int error;
1335
1336 if (!msgbufenabled || msgbufp->msg_magic != MSG_MAGIC) {
1337 msgbufenabled = 0;
1338 return (ENXIO);
1339 }
1340
1341 switch (rnode->sysctl_num) {
1342 case KERN_MSGBUFSIZE: {
1343 struct sysctlnode node = *rnode;
1344 int msg_bufs = (int)msgbufp->msg_bufs;
1345 node.sysctl_data = &msg_bufs;
1346 return (sysctl_lookup(SYSCTLFN_CALL(&node)));
1347 }
1348 case KERN_MSGBUF:
1349 break;
1350 default:
1351 return (EOPNOTSUPP);
1352 }
1353
1354 if (newp != NULL)
1355 return (EPERM);
1356
1357 if (oldp == NULL) {
1358 /* always return full buffer size */
1359 *oldlenp = msgbufp->msg_bufs;
1360 return (0);
1361 }
1362
1363 error = 0;
1364 maxlen = MIN(msgbufp->msg_bufs, *oldlenp);
1365
1366 /*
1367 * First, copy from the write pointer to the end of
1368 * message buffer.
1369 */
1370 beg = msgbufp->msg_bufx;
1371 end = msgbufp->msg_bufs;
1372 while (maxlen > 0) {
1373 len = MIN(end - beg, maxlen);
1374 if (len == 0)
1375 break;
1376 error = dcopyout(l, &msgbufp->msg_bufc[beg], where, len);
1377 if (error)
1378 break;
1379 where += len;
1380 maxlen -= len;
1381
1382 /*
1383 * ... then, copy from the beginning of message buffer to
1384 * the write pointer.
1385 */
1386 beg = 0;
1387 end = msgbufp->msg_bufx;
1388 }
1389
1390 return (error);
1391 }
1392
1393 /*
1394 * sysctl helper routine for kern.defcorename. in the case of a new
1395 * string being assigned, check that it's not a zero-length string.
1396 * (XXX the check in -current doesn't work, but do we really care?)
1397 */
1398 static int
1399 sysctl_kern_defcorename(SYSCTLFN_ARGS)
1400 {
1401 int error;
1402 char *newcorename;
1403 struct sysctlnode node;
1404
1405 newcorename = PNBUF_GET();
1406 node = *rnode;
1407 node.sysctl_data = &newcorename[0];
1408 memcpy(node.sysctl_data, rnode->sysctl_data, MAXPATHLEN);
1409 error = sysctl_lookup(SYSCTLFN_CALL(&node));
1410 if (error || newp == NULL) {
1411 goto done;
1412 }
1413
1414 /*
1415 * when sysctl_lookup() deals with a string, it's guaranteed
1416 * to come back nul terminated. so there. :)
1417 */
1418 if (strlen(newcorename) == 0) {
1419 error = EINVAL;
1420 } else {
1421 memcpy(rnode->sysctl_data, node.sysctl_data, MAXPATHLEN);
1422 error = 0;
1423 }
1424 done:
1425 PNBUF_PUT(newcorename);
1426 return error;
1427 }
1428
1429 /*
1430 * sysctl helper routine for kern.cp_time node. adds up cpu time
1431 * across all cpus.
1432 */
1433 static int
1434 sysctl_kern_cptime(SYSCTLFN_ARGS)
1435 {
1436 struct sysctlnode node = *rnode;
1437
1438 #ifndef MULTIPROCESSOR
1439
1440 if (namelen == 1) {
1441 if (name[0] != 0)
1442 return (ENOENT);
1443 /*
1444 * you're allowed to ask for the zero'th processor
1445 */
1446 name++;
1447 namelen--;
1448 }
1449 node.sysctl_data = curcpu()->ci_schedstate.spc_cp_time;
1450 node.sysctl_size = sizeof(curcpu()->ci_schedstate.spc_cp_time);
1451 return (sysctl_lookup(SYSCTLFN_CALL(&node)));
1452
1453 #else /* MULTIPROCESSOR */
1454
1455 uint64_t *cp_time = NULL;
1456 int error, n = ncpu, i;
1457 struct cpu_info *ci;
1458 CPU_INFO_ITERATOR cii;
1459
1460 /*
1461 * if you specifically pass a buffer that is the size of the
1462 * sum, or if you are probing for the size, you get the "sum"
1463 * of cp_time (and the size thereof) across all processors.
1464 *
1465 * alternately, you can pass an additional mib number and get
1466 * cp_time for that particular processor.
1467 */
1468 switch (namelen) {
1469 case 0:
1470 if (*oldlenp == sizeof(uint64_t) * CPUSTATES || oldp == NULL) {
1471 node.sysctl_size = sizeof(uint64_t) * CPUSTATES;
1472 n = -1; /* SUM */
1473 }
1474 else {
1475 node.sysctl_size = n * sizeof(uint64_t) * CPUSTATES;
1476 n = -2; /* ALL */
1477 }
1478 break;
1479 case 1:
1480 if (name[0] < 0 || name[0] >= n)
1481 return (ENOENT); /* ENOSUCHPROCESSOR */
1482 node.sysctl_size = sizeof(uint64_t) * CPUSTATES;
1483 n = name[0];
1484 /*
1485 * adjust these so that sysctl_lookup() will be happy
1486 */
1487 name++;
1488 namelen--;
1489 break;
1490 default:
1491 return (EINVAL);
1492 }
1493
1494 cp_time = malloc(node.sysctl_size, M_TEMP, M_WAITOK|M_CANFAIL);
1495 if (cp_time == NULL)
1496 return (ENOMEM);
1497 node.sysctl_data = cp_time;
1498 memset(cp_time, 0, node.sysctl_size);
1499
1500 for (CPU_INFO_FOREACH(cii, ci)) {
1501 if (n <= 0)
1502 for (i = 0; i < CPUSTATES; i++)
1503 cp_time[i] += ci->ci_schedstate.spc_cp_time[i];
1504 /*
1505 * if a specific processor was requested and we just
1506 * did it, we're done here
1507 */
1508 if (n == 0)
1509 break;
1510 /*
1511 * if doing "all", skip to next cp_time set for next processor
1512 */
1513 if (n == -2)
1514 cp_time += CPUSTATES;
1515 /*
1516 * if we're doing a specific processor, we're one
1517 * processor closer
1518 */
1519 if (n > 0)
1520 n--;
1521 }
1522
1523 error = sysctl_lookup(SYSCTLFN_CALL(&node));
1524 free(node.sysctl_data, M_TEMP);
1525 return (error);
1526
1527 #endif /* MULTIPROCESSOR */
1528 }
1529
1530 #if NPTY > 0
1531 /*
1532 * sysctl helper routine for kern.maxptys. ensures that any new value
1533 * is acceptable to the pty subsystem.
1534 */
1535 static int
1536 sysctl_kern_maxptys(SYSCTLFN_ARGS)
1537 {
1538 int pty_maxptys(int, int); /* defined in kern/tty_pty.c */
1539 int error, xmax;
1540 struct sysctlnode node;
1541
1542 /* get current value of maxptys */
1543 xmax = pty_maxptys(0, 0);
1544
1545 node = *rnode;
1546 node.sysctl_data = &xmax;
1547 error = sysctl_lookup(SYSCTLFN_CALL(&node));
1548 if (error || newp == NULL)
1549 return (error);
1550
1551 if (xmax != pty_maxptys(xmax, 1))
1552 return (EINVAL);
1553
1554 return (0);
1555 }
1556 #endif /* NPTY > 0 */
1557
1558 /*
1559 * sysctl helper routine for kern.sbmax. basically just ensures that
1560 * any new value is not too small.
1561 */
1562 static int
1563 sysctl_kern_sbmax(SYSCTLFN_ARGS)
1564 {
1565 int error, new_sbmax;
1566 struct sysctlnode node;
1567
1568 new_sbmax = sb_max;
1569 node = *rnode;
1570 node.sysctl_data = &new_sbmax;
1571 error = sysctl_lookup(SYSCTLFN_CALL(&node));
1572 if (error || newp == NULL)
1573 return (error);
1574
1575 error = sb_max_set(new_sbmax);
1576
1577 return (error);
1578 }
1579
1580 /*
1581 * sysctl helper routine for kern.urandom node. picks a random number
1582 * for you.
1583 */
1584 static int
1585 sysctl_kern_urnd(SYSCTLFN_ARGS)
1586 {
1587 #if NRND > 0
1588 int v;
1589
1590 if (rnd_extract_data(&v, sizeof(v), RND_EXTRACT_ANY) == sizeof(v)) {
1591 struct sysctlnode node = *rnode;
1592 node.sysctl_data = &v;
1593 return (sysctl_lookup(SYSCTLFN_CALL(&node)));
1594 }
1595 else
1596 return (EIO); /*XXX*/
1597 #else
1598 return (EOPNOTSUPP);
1599 #endif
1600 }
1601
1602 /*
1603 * sysctl helper routine for kern.arandom node. picks a random number
1604 * for you.
1605 */
1606 static int
1607 sysctl_kern_arnd(SYSCTLFN_ARGS)
1608 {
1609 #if NRND > 0
1610 int error;
1611 void *v;
1612 struct sysctlnode node = *rnode;
1613
1614 if (*oldlenp == 0)
1615 return 0;
1616 if (*oldlenp > 8192)
1617 return E2BIG;
1618
1619 v = malloc(*oldlenp, M_TEMP, M_WAITOK);
1620
1621 arc4randbytes(v, *oldlenp);
1622 node.sysctl_data = v;
1623 node.sysctl_size = *oldlenp;
1624 error = sysctl_lookup(SYSCTLFN_CALL(&node));
1625 free(v, M_TEMP);
1626 return error;
1627 #else
1628 return (EOPNOTSUPP);
1629 #endif
1630 }
1631 /*
1632 * sysctl helper routine to do kern.lwp.* work.
1633 */
1634 static int
1635 sysctl_kern_lwp(SYSCTLFN_ARGS)
1636 {
1637 struct kinfo_lwp klwp;
1638 struct proc *p;
1639 struct lwp *l2;
1640 char *where, *dp;
1641 int pid, elem_size, elem_count;
1642 int buflen, needed, error;
1643
1644 if (namelen == 1 && name[0] == CTL_QUERY)
1645 return (sysctl_query(SYSCTLFN_CALL(rnode)));
1646
1647 dp = where = oldp;
1648 buflen = where != NULL ? *oldlenp : 0;
1649 error = needed = 0;
1650
1651 if (newp != NULL || namelen != 3)
1652 return (EINVAL);
1653 pid = name[0];
1654 elem_size = name[1];
1655 elem_count = name[2];
1656
1657 mutex_enter(&proclist_lock);
1658 if (pid == -1) {
1659 LIST_FOREACH(l2, &alllwp, l_list) {
1660 if (buflen >= elem_size && elem_count > 0) {
1661 lwp_lock(l2);
1662 fill_lwp(l2, &klwp);
1663 lwp_unlock(l2);
1664
1665 /*
1666 * Copy out elem_size, but not larger than
1667 * the size of a struct kinfo_proc2.
1668 *
1669 * XXX We should not be holding p_smutex, but
1670 * for now, the buffer is wired. Fix later.
1671 */
1672 error = dcopyout(l, &klwp, dp,
1673 min(sizeof(klwp), elem_size));
1674 if (error)
1675 goto cleanup;
1676 dp += elem_size;
1677 buflen -= elem_size;
1678 elem_count--;
1679 }
1680 needed += elem_size;
1681 }
1682 } else {
1683 p = p_find(pid, PFIND_LOCKED);
1684 if (p == NULL) {
1685 mutex_exit(&proclist_lock);
1686 return (ESRCH);
1687 }
1688 mutex_enter(&p->p_smutex);
1689 LIST_FOREACH(l2, &p->p_lwps, l_sibling) {
1690 if (buflen >= elem_size && elem_count > 0) {
1691 lwp_lock(l2);
1692 fill_lwp(l2, &klwp);
1693 lwp_unlock(l2);
1694
1695 /*
1696 * Copy out elem_size, but not larger than
1697 * the size of a struct kinfo_proc2.
1698 *
1699 * XXX We should not be holding p_smutex, but
1700 * for now, the buffer is wired. Fix later.
1701 */
1702 error = dcopyout(l, &klwp, dp,
1703 min(sizeof(klwp), elem_size));
1704 if (error)
1705 goto cleanup;
1706 dp += elem_size;
1707 buflen -= elem_size;
1708 elem_count--;
1709 }
1710 needed += elem_size;
1711 }
1712 mutex_exit(&p->p_smutex);
1713 }
1714 mutex_exit(&proclist_lock);
1715
1716 if (where != NULL) {
1717 *oldlenp = dp - where;
1718 if (needed > *oldlenp)
1719 return (ENOMEM);
1720 } else {
1721 needed += KERN_LWPSLOP;
1722 *oldlenp = needed;
1723 }
1724 return (0);
1725 cleanup:
1726 return (error);
1727 }
1728
1729 /*
1730 * sysctl helper routine for kern.forkfsleep node. ensures that the
1731 * given value is not too large or two small, and is at least one
1732 * timer tick if not zero.
1733 */
1734 static int
1735 sysctl_kern_forkfsleep(SYSCTLFN_ARGS)
1736 {
1737 /* userland sees value in ms, internally is in ticks */
1738 extern int forkfsleep; /* defined in kern/kern_fork.c */
1739 int error, timo, lsleep;
1740 struct sysctlnode node;
1741
1742 lsleep = forkfsleep * 1000 / hz;
1743 node = *rnode;
1744 node.sysctl_data = &lsleep;
1745 error = sysctl_lookup(SYSCTLFN_CALL(&node));
1746 if (error || newp == NULL)
1747 return (error);
1748
1749 /* refuse negative values, and overly 'long time' */
1750 if (lsleep < 0 || lsleep > MAXSLP * 1000)
1751 return (EINVAL);
1752
1753 timo = mstohz(lsleep);
1754
1755 /* if the interval is >0 ms && <1 tick, use 1 tick */
1756 if (lsleep != 0 && timo == 0)
1757 forkfsleep = 1;
1758 else
1759 forkfsleep = timo;
1760
1761 return (0);
1762 }
1763
1764 /*
1765 * sysctl helper routine for kern.root_partition
1766 */
1767 static int
1768 sysctl_kern_root_partition(SYSCTLFN_ARGS)
1769 {
1770 int rootpart = DISKPART(rootdev);
1771 struct sysctlnode node = *rnode;
1772
1773 node.sysctl_data = &rootpart;
1774 return (sysctl_lookup(SYSCTLFN_CALL(&node)));
1775 }
1776
1777 /*
1778 * sysctl helper function for kern.drivers
1779 */
1780 static int
1781 sysctl_kern_drivers(SYSCTLFN_ARGS)
1782 {
1783 int error;
1784 size_t buflen;
1785 struct kinfo_drivers kd;
1786 char *start, *where;
1787 const char *dname;
1788 int i;
1789 extern struct devsw_conv *devsw_conv;
1790 extern int max_devsw_convs;
1791
1792 if (newp != NULL || namelen != 0)
1793 return (EINVAL);
1794
1795 start = where = oldp;
1796 buflen = *oldlenp;
1797 if (where == NULL) {
1798 *oldlenp = max_devsw_convs * sizeof kd;
1799 return 0;
1800 }
1801
1802 /*
1803 * An array of kinfo_drivers structures
1804 */
1805 error = 0;
1806 for (i = 0; i < max_devsw_convs; i++) {
1807 dname = devsw_conv[i].d_name;
1808 if (dname == NULL)
1809 continue;
1810 if (buflen < sizeof kd) {
1811 error = ENOMEM;
1812 break;
1813 }
1814 memset(&kd, 0, sizeof(kd));
1815 kd.d_bmajor = devsw_conv[i].d_bmajor;
1816 kd.d_cmajor = devsw_conv[i].d_cmajor;
1817 strlcpy(kd.d_name, dname, sizeof kd.d_name);
1818 error = dcopyout(l, &kd, where, sizeof kd);
1819 if (error != 0)
1820 break;
1821 buflen -= sizeof kd;
1822 where += sizeof kd;
1823 }
1824 *oldlenp = where - start;
1825 return error;
1826 }
1827
1828 /*
1829 * sysctl helper function for kern.file2
1830 */
1831 static int
1832 sysctl_kern_file2(SYSCTLFN_ARGS)
1833 {
1834 struct proc *p;
1835 struct file *fp;
1836 struct filedesc *fd;
1837 struct kinfo_file kf;
1838 char *dp;
1839 u_int i, op;
1840 size_t len, needed, elem_size, out_size;
1841 int error, arg, elem_count;
1842
1843 if (namelen == 1 && name[0] == CTL_QUERY)
1844 return (sysctl_query(SYSCTLFN_CALL(rnode)));
1845
1846 if (namelen != 4)
1847 return (EINVAL);
1848
1849 error = 0;
1850 dp = oldp;
1851 len = (oldp != NULL) ? *oldlenp : 0;
1852 op = name[0];
1853 arg = name[1];
1854 elem_size = name[2];
1855 elem_count = name[3];
1856 out_size = MIN(sizeof(kf), elem_size);
1857 needed = 0;
1858
1859 if (elem_size < 1 || elem_count < 0)
1860 return (EINVAL);
1861
1862 switch (op) {
1863 case KERN_FILE_BYFILE:
1864 /*
1865 * doesn't use arg so it must be zero
1866 */
1867 if (arg != 0)
1868 return (EINVAL);
1869 LIST_FOREACH(fp, &filehead, f_list) {
1870 if (kauth_authorize_generic(l->l_cred,
1871 KAUTH_GENERIC_CANSEE, fp->f_cred) != 0)
1872 continue;
1873 if (len >= elem_size && elem_count > 0) {
1874 fill_file(&kf, fp, NULL, 0);
1875 error = dcopyout(l, &kf, dp, out_size);
1876 if (error)
1877 break;
1878 dp += elem_size;
1879 len -= elem_size;
1880 }
1881 if (elem_count > 0) {
1882 needed += elem_size;
1883 if (elem_count != INT_MAX)
1884 elem_count--;
1885 }
1886 }
1887 break;
1888 case KERN_FILE_BYPID:
1889 if (arg < -1)
1890 /* -1 means all processes */
1891 return (EINVAL);
1892 mutex_enter(&proclist_lock);
1893 PROCLIST_FOREACH(p, &allproc) {
1894 if (p->p_stat == SIDL)
1895 /* skip embryonic processes */
1896 continue;
1897 if (kauth_authorize_process(l->l_cred,
1898 KAUTH_PROCESS_CANSEE, p, NULL, NULL, NULL) != 0)
1899 continue;
1900 if (arg > 0 && p->p_pid != arg)
1901 /* pick only the one we want */
1902 /* XXX want 0 to mean "kernel files" */
1903 continue;
1904 fd = p->p_fd;
1905 for (i = 0; i < fd->fd_nfiles; i++) {
1906 fp = fd->fd_ofiles[i];
1907 if (fp == NULL || !FILE_IS_USABLE(fp))
1908 continue;
1909 if (len >= elem_size && elem_count > 0) {
1910 fill_file(&kf, fd->fd_ofiles[i],
1911 p, i);
1912 error = dcopyout(l, &kf, dp, out_size);
1913 if (error)
1914 break;
1915 dp += elem_size;
1916 len -= elem_size;
1917 }
1918 if (elem_count > 0) {
1919 needed += elem_size;
1920 if (elem_count != INT_MAX)
1921 elem_count--;
1922 }
1923 }
1924 }
1925 mutex_exit(&proclist_lock);
1926 break;
1927 default:
1928 return (EINVAL);
1929 }
1930
1931 if (oldp == NULL)
1932 needed += KERN_FILESLOP * elem_size;
1933 *oldlenp = needed;
1934
1935 return (error);
1936 }
1937
1938 static void
1939 fill_file(struct kinfo_file *kp, const struct file *fp, struct proc *p, int i)
1940 {
1941
1942 memset(kp, 0, sizeof(*kp));
1943
1944 kp->ki_fileaddr = PTRTOUINT64(fp);
1945 kp->ki_flag = fp->f_flag;
1946 kp->ki_iflags = fp->f_iflags;
1947 kp->ki_ftype = fp->f_type;
1948 kp->ki_count = fp->f_count;
1949 kp->ki_msgcount = fp->f_msgcount;
1950 kp->ki_usecount = fp->f_usecount;
1951 kp->ki_fucred = PTRTOUINT64(fp->f_cred);
1952 kp->ki_fuid = kauth_cred_geteuid(fp->f_cred);
1953 kp->ki_fgid = kauth_cred_getegid(fp->f_cred);
1954 kp->ki_fops = PTRTOUINT64(fp->f_ops);
1955 kp->ki_foffset = fp->f_offset;
1956 kp->ki_fdata = PTRTOUINT64(fp->f_data);
1957
1958 /* vnode information to glue this file to something */
1959 if (fp->f_type == DTYPE_VNODE) {
1960 struct vnode *vp = (struct vnode *)fp->f_data;
1961
1962 kp->ki_vun = PTRTOUINT64(vp->v_un.vu_socket);
1963 kp->ki_vsize = vp->v_size;
1964 kp->ki_vtype = vp->v_type;
1965 kp->ki_vtag = vp->v_tag;
1966 kp->ki_vdata = PTRTOUINT64(vp->v_data);
1967 }
1968
1969 /* process information when retrieved via KERN_FILE_BYPID */
1970 if (p) {
1971 kp->ki_pid = p->p_pid;
1972 kp->ki_fd = i;
1973 kp->ki_ofileflags = p->p_fd->fd_ofileflags[i];
1974 }
1975 }
1976
1977 static int
1978 sysctl_doeproc(SYSCTLFN_ARGS)
1979 {
1980 struct eproc *eproc;
1981 struct kinfo_proc2 *kproc2;
1982 struct kinfo_proc *dp;
1983 struct proc *p;
1984 const struct proclist_desc *pd;
1985 char *where, *dp2;
1986 int type, op, arg;
1987 u_int elem_size, elem_count;
1988 size_t buflen, needed;
1989 int error;
1990
1991 if (namelen == 1 && name[0] == CTL_QUERY)
1992 return (sysctl_query(SYSCTLFN_CALL(rnode)));
1993
1994 dp = oldp;
1995 dp2 = where = oldp;
1996 buflen = where != NULL ? *oldlenp : 0;
1997 error = 0;
1998 needed = 0;
1999 type = rnode->sysctl_num;
2000
2001 if (type == KERN_PROC) {
2002 if (namelen != 2 && !(namelen == 1 && name[0] == KERN_PROC_ALL))
2003 return (EINVAL);
2004 op = name[0];
2005 if (op != KERN_PROC_ALL)
2006 arg = name[1];
2007 else
2008 arg = 0; /* Quell compiler warning */
2009 elem_size = elem_count = 0; /* Ditto */
2010 } else {
2011 if (namelen != 4)
2012 return (EINVAL);
2013 op = name[0];
2014 arg = name[1];
2015 elem_size = name[2];
2016 elem_count = name[3];
2017 }
2018
2019 if (type == KERN_PROC) {
2020 eproc = malloc(sizeof(*eproc), M_TEMP, M_WAITOK);
2021 kproc2 = NULL;
2022 } else {
2023 eproc = NULL;
2024 kproc2 = malloc(sizeof(*kproc2), M_TEMP, M_WAITOK);
2025 }
2026 mutex_enter(&proclist_lock);
2027
2028 pd = proclists;
2029 again:
2030 PROCLIST_FOREACH(p, pd->pd_list) {
2031 /*
2032 * Skip embryonic processes.
2033 */
2034 if (p->p_stat == SIDL)
2035 continue;
2036
2037 if (kauth_authorize_process(l->l_cred,
2038 KAUTH_PROCESS_CANSEE, p, NULL, NULL, NULL) != 0)
2039 continue;
2040
2041 /*
2042 * TODO - make more efficient (see notes below).
2043 * do by session.
2044 */
2045 switch (op) {
2046
2047 case KERN_PROC_PID:
2048 /* could do this with just a lookup */
2049 if (p->p_pid != (pid_t)arg)
2050 continue;
2051 break;
2052
2053 case KERN_PROC_PGRP:
2054 /* could do this by traversing pgrp */
2055 if (p->p_pgrp->pg_id != (pid_t)arg)
2056 continue;
2057 break;
2058
2059 case KERN_PROC_SESSION:
2060 if (p->p_session->s_sid != (pid_t)arg)
2061 continue;
2062 break;
2063
2064 case KERN_PROC_TTY:
2065 if (arg == (int) KERN_PROC_TTY_REVOKE) {
2066 if ((p->p_lflag & PL_CONTROLT) == 0 ||
2067 p->p_session->s_ttyp == NULL ||
2068 p->p_session->s_ttyvp != NULL)
2069 continue;
2070 } else if ((p->p_lflag & PL_CONTROLT) == 0 ||
2071 p->p_session->s_ttyp == NULL) {
2072 if ((dev_t)arg != KERN_PROC_TTY_NODEV)
2073 continue;
2074 } else if (p->p_session->s_ttyp->t_dev != (dev_t)arg)
2075 continue;
2076 break;
2077
2078 case KERN_PROC_UID:
2079 if (kauth_cred_geteuid(p->p_cred) != (uid_t)arg)
2080 continue;
2081 break;
2082
2083 case KERN_PROC_RUID:
2084 if (kauth_cred_getuid(p->p_cred) != (uid_t)arg)
2085 continue;
2086 break;
2087
2088 case KERN_PROC_GID:
2089 if (kauth_cred_getegid(p->p_cred) != (uid_t)arg)
2090 continue;
2091 break;
2092
2093 case KERN_PROC_RGID:
2094 if (kauth_cred_getgid(p->p_cred) != (uid_t)arg)
2095 continue;
2096 break;
2097
2098 case KERN_PROC_ALL:
2099 /* allow everything */
2100 break;
2101
2102 default:
2103 error = EINVAL;
2104 goto cleanup;
2105 }
2106 if (type == KERN_PROC) {
2107 if (buflen >= sizeof(struct kinfo_proc)) {
2108 fill_eproc(p, eproc);
2109 error = dcopyout(l, p, &dp->kp_proc,
2110 sizeof(struct proc));
2111 if (error)
2112 goto cleanup;
2113 error = dcopyout(l, eproc, &dp->kp_eproc,
2114 sizeof(*eproc));
2115 if (error)
2116 goto cleanup;
2117 dp++;
2118 buflen -= sizeof(struct kinfo_proc);
2119 }
2120 needed += sizeof(struct kinfo_proc);
2121 } else { /* KERN_PROC2 */
2122 if (buflen >= elem_size && elem_count > 0) {
2123 fill_kproc2(p, kproc2);
2124 /*
2125 * Copy out elem_size, but not larger than
2126 * the size of a struct kinfo_proc2.
2127 */
2128 error = dcopyout(l, kproc2, dp2,
2129 min(sizeof(*kproc2), elem_size));
2130 if (error)
2131 goto cleanup;
2132 dp2 += elem_size;
2133 buflen -= elem_size;
2134 elem_count--;
2135 }
2136 needed += elem_size;
2137 }
2138 }
2139 pd++;
2140 if (pd->pd_list != NULL)
2141 goto again;
2142 mutex_exit(&proclist_lock);
2143
2144 if (where != NULL) {
2145 if (type == KERN_PROC)
2146 *oldlenp = (char *)dp - where;
2147 else
2148 *oldlenp = dp2 - where;
2149 if (needed > *oldlenp) {
2150 error = ENOMEM;
2151 goto out;
2152 }
2153 } else {
2154 needed += KERN_PROCSLOP;
2155 *oldlenp = needed;
2156 }
2157 if (kproc2)
2158 free(kproc2, M_TEMP);
2159 if (eproc)
2160 free(eproc, M_TEMP);
2161 return 0;
2162 cleanup:
2163 mutex_exit(&proclist_lock);
2164 out:
2165 if (kproc2)
2166 free(kproc2, M_TEMP);
2167 if (eproc)
2168 free(eproc, M_TEMP);
2169 return error;
2170 }
2171
2172 /*
2173 * sysctl helper routine for kern.proc_args pseudo-subtree.
2174 */
2175 static int
2176 sysctl_kern_proc_args(SYSCTLFN_ARGS)
2177 {
2178 struct ps_strings pss;
2179 struct proc *p;
2180 size_t len, i;
2181 struct uio auio;
2182 struct iovec aiov;
2183 pid_t pid;
2184 int nargv, type, error;
2185 char *arg;
2186 char **argv = NULL;
2187 char *tmp;
2188 struct vmspace *vmspace;
2189 vaddr_t psstr_addr;
2190 vaddr_t offsetn;
2191 vaddr_t offsetv;
2192
2193 if (namelen == 1 && name[0] == CTL_QUERY)
2194 return (sysctl_query(SYSCTLFN_CALL(rnode)));
2195
2196 if (newp != NULL || namelen != 2)
2197 return (EINVAL);
2198 pid = name[0];
2199 type = name[1];
2200
2201 switch (type) {
2202 case KERN_PROC_ARGV:
2203 case KERN_PROC_NARGV:
2204 case KERN_PROC_ENV:
2205 case KERN_PROC_NENV:
2206 /* ok */
2207 break;
2208 default:
2209 return (EINVAL);
2210 }
2211
2212 mutex_enter(&proclist_lock);
2213
2214 /* check pid */
2215 if ((p = p_find(pid, PFIND_LOCKED)) == NULL) {
2216 error = EINVAL;
2217 goto out_locked;
2218 }
2219
2220 error = kauth_authorize_process(l->l_cred,
2221 KAUTH_PROCESS_CANSEE, p, NULL, NULL, NULL);
2222 if (error) {
2223 goto out_locked;
2224 }
2225
2226 /* only root or same user change look at the environment */
2227 if (type == KERN_PROC_ENV || type == KERN_PROC_NENV) {
2228 if (kauth_authorize_generic(l->l_cred, KAUTH_GENERIC_ISSUSER,
2229 NULL) != 0) {
2230 if (kauth_cred_getuid(l->l_cred) !=
2231 kauth_cred_getuid(p->p_cred) ||
2232 kauth_cred_getuid(l->l_cred) !=
2233 kauth_cred_getsvuid(p->p_cred)) {
2234 error = EPERM;
2235 goto out_locked;
2236 }
2237 }
2238 }
2239
2240 if (oldp == NULL) {
2241 if (type == KERN_PROC_NARGV || type == KERN_PROC_NENV)
2242 *oldlenp = sizeof (int);
2243 else
2244 *oldlenp = ARG_MAX; /* XXX XXX XXX */
2245 error = 0;
2246 goto out_locked;
2247 }
2248
2249 /*
2250 * Zombies don't have a stack, so we can't read their psstrings.
2251 * System processes also don't have a user stack.
2252 */
2253 if (P_ZOMBIE(p) || (p->p_flag & PK_SYSTEM) != 0) {
2254 error = EINVAL;
2255 goto out_locked;
2256 }
2257
2258 /*
2259 * Lock the process down in memory.
2260 */
2261 /* XXXCDC: how should locking work here? */
2262 if ((l->l_flag & LW_WEXIT) || (p->p_vmspace->vm_refcnt < 1)) {
2263 error = EFAULT;
2264 goto out_locked;
2265 }
2266
2267 psstr_addr = (vaddr_t)p->p_psstr;
2268 if (type == KERN_PROC_ARGV || type == KERN_PROC_NARGV) {
2269 offsetn = p->p_psnargv;
2270 offsetv = p->p_psargv;
2271 } else {
2272 offsetn = p->p_psnenv;
2273 offsetv = p->p_psenv;
2274 }
2275 vmspace = p->p_vmspace;
2276 vmspace->vm_refcnt++; /* XXX */
2277
2278 mutex_exit(&proclist_lock);
2279
2280 /*
2281 * Allocate a temporary buffer to hold the arguments.
2282 */
2283 arg = malloc(PAGE_SIZE, M_TEMP, M_WAITOK);
2284
2285 /*
2286 * Read in the ps_strings structure.
2287 */
2288 aiov.iov_base = &pss;
2289 aiov.iov_len = sizeof(pss);
2290 auio.uio_iov = &aiov;
2291 auio.uio_iovcnt = 1;
2292 auio.uio_offset = psstr_addr;
2293 auio.uio_resid = sizeof(pss);
2294 auio.uio_rw = UIO_READ;
2295 UIO_SETUP_SYSSPACE(&auio);
2296 error = uvm_io(&vmspace->vm_map, &auio);
2297 if (error)
2298 goto done;
2299
2300 memcpy(&nargv, (char *)&pss + offsetn, sizeof(nargv));
2301 if (type == KERN_PROC_NARGV || type == KERN_PROC_NENV) {
2302 error = dcopyout(l, &nargv, oldp, sizeof(nargv));
2303 *oldlenp = sizeof(nargv);
2304 goto done;
2305 }
2306 /*
2307 * Now read the address of the argument vector.
2308 */
2309 switch (type) {
2310 case KERN_PROC_ARGV:
2311 /* FALLTHROUGH */
2312 case KERN_PROC_ENV:
2313 memcpy(&tmp, (char *)&pss + offsetv, sizeof(tmp));
2314 break;
2315 default:
2316 return (EINVAL);
2317 }
2318
2319 #ifdef COMPAT_NETBSD32
2320 if (p->p_flag & PK_32)
2321 len = sizeof(netbsd32_charp) * nargv;
2322 else
2323 #endif
2324 len = sizeof(char *) * nargv;
2325
2326 argv = malloc(len, M_TEMP, M_WAITOK);
2327
2328 aiov.iov_base = argv;
2329 aiov.iov_len = len;
2330 auio.uio_iov = &aiov;
2331 auio.uio_iovcnt = 1;
2332 auio.uio_offset = (off_t)(unsigned long)tmp;
2333 auio.uio_resid = len;
2334 auio.uio_rw = UIO_READ;
2335 UIO_SETUP_SYSSPACE(&auio);
2336 error = uvm_io(&vmspace->vm_map, &auio);
2337 if (error)
2338 goto done;
2339
2340 /*
2341 * Now copy each string.
2342 */
2343 len = 0; /* bytes written to user buffer */
2344 for (i = 0; i < nargv; i++) {
2345 int finished = 0;
2346 vaddr_t base;
2347 size_t xlen;
2348 int j;
2349
2350 #ifdef COMPAT_NETBSD32
2351 if (p->p_flag & PK_32) {
2352 netbsd32_charp *argv32;
2353
2354 argv32 = (netbsd32_charp *)argv;
2355
2356 base = (vaddr_t)NETBSD32PTR64(argv32[i]);
2357 } else
2358 #endif
2359 base = (vaddr_t)argv[i];
2360
2361 while (!finished) {
2362 xlen = PAGE_SIZE - (base & PAGE_MASK);
2363
2364 aiov.iov_base = arg;
2365 aiov.iov_len = PAGE_SIZE;
2366 auio.uio_iov = &aiov;
2367 auio.uio_iovcnt = 1;
2368 auio.uio_offset = base;
2369 auio.uio_resid = xlen;
2370 auio.uio_rw = UIO_READ;
2371 UIO_SETUP_SYSSPACE(&auio);
2372 error = uvm_io(&vmspace->vm_map, &auio);
2373 if (error)
2374 goto done;
2375
2376 /* Look for the end of the string */
2377 for (j = 0; j < xlen; j++) {
2378 if (arg[j] == '\0') {
2379 xlen = j + 1;
2380 finished = 1;
2381 break;
2382 }
2383 }
2384
2385 /* Check for user buffer overflow */
2386 if (len + xlen > *oldlenp) {
2387 finished = 1;
2388 if (len > *oldlenp)
2389 xlen = 0;
2390 else
2391 xlen = *oldlenp - len;
2392 }
2393
2394 /* Copyout the page */
2395 error = dcopyout(l, arg, (char *)oldp + len, xlen);
2396 if (error)
2397 goto done;
2398
2399 len += xlen;
2400 base += xlen;
2401 }
2402 }
2403 *oldlenp = len;
2404
2405 done:
2406 if (argv != NULL)
2407 free(argv, M_TEMP);
2408
2409 uvmspace_free(vmspace);
2410
2411 free(arg, M_TEMP);
2412 return error;
2413
2414 out_locked:
2415 mutex_exit(&proclist_lock);
2416 return error;
2417 }
2418
2419 static int
2420 sysctl_security_setidcore(SYSCTLFN_ARGS)
2421 {
2422 int newsize, error;
2423 struct sysctlnode node;
2424
2425 node = *rnode;
2426 node.sysctl_data = &newsize;
2427 newsize = *(int *)rnode->sysctl_data;
2428 error = sysctl_lookup(SYSCTLFN_CALL(&node));
2429 if (error || newp == NULL)
2430 return error;
2431
2432 if (kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_SETIDCORE,
2433 0, NULL, NULL, NULL))
2434 return (EPERM);
2435
2436 *(int *)rnode->sysctl_data = newsize;
2437
2438 return 0;
2439 }
2440
2441 static int
2442 sysctl_security_setidcorename(SYSCTLFN_ARGS)
2443 {
2444 int error;
2445 char *newsetidcorename;
2446 struct sysctlnode node;
2447
2448 newsetidcorename = PNBUF_GET();
2449 node = *rnode;
2450 node.sysctl_data = newsetidcorename;
2451 memcpy(node.sysctl_data, rnode->sysctl_data, MAXPATHLEN);
2452 error = sysctl_lookup(SYSCTLFN_CALL(&node));
2453 if (error || newp == NULL) {
2454 goto out;
2455 }
2456 if (kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_SETIDCORE,
2457 0, NULL, NULL, NULL)) {
2458 error = EPERM;
2459 goto out;
2460 }
2461 if (strlen(newsetidcorename) == 0) {
2462 error = EINVAL;
2463 goto out;
2464 }
2465 memcpy(rnode->sysctl_data, node.sysctl_data, MAXPATHLEN);
2466 out:
2467 PNBUF_PUT(newsetidcorename);
2468 return error;
2469 }
2470
2471 /*
2472 * sysctl helper routine for kern.cp_id node. maps cpus to their
2473 * cpuids.
2474 */
2475 static int
2476 sysctl_kern_cpid(SYSCTLFN_ARGS)
2477 {
2478 struct sysctlnode node = *rnode;
2479
2480 #ifndef MULTIPROCESSOR
2481 uint64_t id;
2482
2483 if (namelen == 1) {
2484 if (name[0] != 0)
2485 return (ENOENT);
2486 /*
2487 * you're allowed to ask for the zero'th processor
2488 */
2489 name++;
2490 namelen--;
2491 }
2492 node.sysctl_data = &id;
2493 node.sysctl_size = sizeof(id);
2494 id = cpu_number();
2495 return (sysctl_lookup(SYSCTLFN_CALL(&node)));
2496
2497 #else /* MULTIPROCESSOR */
2498 uint64_t *cp_id = NULL;
2499 int error, n = ncpu;
2500 struct cpu_info *ci;
2501 CPU_INFO_ITERATOR cii;
2502
2503 /*
2504 * here you may either retrieve a single cpu id or the whole
2505 * set. the size you get back when probing depends on what
2506 * you ask for.
2507 */
2508 switch (namelen) {
2509 case 0:
2510 node.sysctl_size = n * sizeof(uint64_t);
2511 n = -2; /* ALL */
2512 break;
2513 case 1:
2514 if (name[0] < 0 || name[0] >= n)
2515 return (ENOENT); /* ENOSUCHPROCESSOR */
2516 node.sysctl_size = sizeof(uint64_t);
2517 n = name[0];
2518 /*
2519 * adjust these so that sysctl_lookup() will be happy
2520 */
2521 name++;
2522 namelen--;
2523 break;
2524 default:
2525 return (EINVAL);
2526 }
2527
2528 cp_id = malloc(node.sysctl_size, M_TEMP, M_WAITOK|M_CANFAIL);
2529 if (cp_id == NULL)
2530 return (ENOMEM);
2531 node.sysctl_data = cp_id;
2532 memset(cp_id, 0, node.sysctl_size);
2533
2534 for (CPU_INFO_FOREACH(cii, ci)) {
2535 if (n <= 0)
2536 cp_id[0] = ci->ci_cpuid;
2537 /*
2538 * if a specific processor was requested and we just
2539 * did it, we're done here
2540 */
2541 if (n == 0)
2542 break;
2543 /*
2544 * if doing "all", skip to next cp_id slot for next processor
2545 */
2546 if (n == -2)
2547 cp_id++;
2548 /*
2549 * if we're doing a specific processor, we're one
2550 * processor closer
2551 */
2552 if (n > 0)
2553 n--;
2554 }
2555
2556 error = sysctl_lookup(SYSCTLFN_CALL(&node));
2557 free(node.sysctl_data, M_TEMP);
2558 return (error);
2559
2560 #endif /* MULTIPROCESSOR */
2561 }
2562
2563 /*
2564 * sysctl helper routine for hw.usermem and hw.usermem64. values are
2565 * calculate on the fly taking into account integer overflow and the
2566 * current wired count.
2567 */
2568 static int
2569 sysctl_hw_usermem(SYSCTLFN_ARGS)
2570 {
2571 u_int ui;
2572 u_quad_t uq;
2573 struct sysctlnode node;
2574
2575 node = *rnode;
2576 switch (rnode->sysctl_num) {
2577 case HW_USERMEM:
2578 if ((ui = physmem - uvmexp.wired) > (UINT_MAX / PAGE_SIZE))
2579 ui = UINT_MAX;
2580 else
2581 ui *= PAGE_SIZE;
2582 node.sysctl_data = &ui;
2583 break;
2584 case HW_USERMEM64:
2585 uq = (u_quad_t)(physmem - uvmexp.wired) * PAGE_SIZE;
2586 node.sysctl_data = &uq;
2587 break;
2588 default:
2589 return (EINVAL);
2590 }
2591
2592 return (sysctl_lookup(SYSCTLFN_CALL(&node)));
2593 }
2594
2595 /*
2596 * sysctl helper routine for kern.cnmagic node. pulls the old value
2597 * out, encoded, and stuffs the new value in for decoding.
2598 */
2599 static int
2600 sysctl_hw_cnmagic(SYSCTLFN_ARGS)
2601 {
2602 char magic[CNS_LEN];
2603 int error;
2604 struct sysctlnode node;
2605
2606 if (oldp)
2607 cn_get_magic(magic, CNS_LEN);
2608 node = *rnode;
2609 node.sysctl_data = &magic[0];
2610 error = sysctl_lookup(SYSCTLFN_CALL(&node));
2611 if (error || newp == NULL)
2612 return (error);
2613
2614 return (cn_set_magic(magic));
2615 }
2616
2617 static int
2618 sysctl_hw_ncpu(SYSCTLFN_ARGS)
2619 {
2620 struct sysctlnode node;
2621
2622 node = *rnode;
2623 node.sysctl_data = &ncpu;
2624
2625 return (sysctl_lookup(SYSCTLFN_CALL(&node)));
2626 }
2627
2628
2629 /*
2630 * ********************************************************************
2631 * section 3: public helper routines that are used for more than one
2632 * node
2633 * ********************************************************************
2634 */
2635
2636 /*
2637 * sysctl helper routine for the kern.root_device node and some ports'
2638 * machdep.root_device nodes.
2639 */
2640 int
2641 sysctl_root_device(SYSCTLFN_ARGS)
2642 {
2643 struct sysctlnode node;
2644
2645 node = *rnode;
2646 node.sysctl_data = root_device->dv_xname;
2647 node.sysctl_size = strlen(root_device->dv_xname) + 1;
2648 return (sysctl_lookup(SYSCTLFN_CALL(&node)));
2649 }
2650
2651 /*
2652 * sysctl helper routine for kern.consdev, dependent on the current
2653 * state of the console. also used for machdep.console_device on some
2654 * ports.
2655 */
2656 int
2657 sysctl_consdev(SYSCTLFN_ARGS)
2658 {
2659 dev_t consdev;
2660 struct sysctlnode node;
2661
2662 if (cn_tab != NULL)
2663 consdev = cn_tab->cn_dev;
2664 else
2665 consdev = NODEV;
2666 node = *rnode;
2667 node.sysctl_data = &consdev;
2668 node.sysctl_size = sizeof(consdev);
2669 return (sysctl_lookup(SYSCTLFN_CALL(&node)));
2670 }
2671
2672 /*
2673 * ********************************************************************
2674 * section 4: support for some helpers
2675 * ********************************************************************
2676 */
2677
2678 /*
2679 * Fill in a kinfo_proc2 structure for the specified process.
2680 */
2681 static void
2682 fill_kproc2(struct proc *p, struct kinfo_proc2 *ki)
2683 {
2684 struct tty *tp;
2685 struct lwp *l, *l2;
2686 struct timeval ut, st, rt;
2687 sigset_t ss1, ss2;
2688
2689 memset(ki, 0, sizeof(*ki));
2690
2691 ki->p_paddr = PTRTOUINT64(p);
2692 ki->p_fd = PTRTOUINT64(p->p_fd);
2693 ki->p_cwdi = PTRTOUINT64(p->p_cwdi);
2694 ki->p_stats = PTRTOUINT64(p->p_stats);
2695 ki->p_limit = PTRTOUINT64(p->p_limit);
2696 ki->p_vmspace = PTRTOUINT64(p->p_vmspace);
2697 ki->p_sigacts = PTRTOUINT64(p->p_sigacts);
2698 ki->p_sess = PTRTOUINT64(p->p_session);
2699 ki->p_tsess = 0; /* may be changed if controlling tty below */
2700 ki->p_ru = PTRTOUINT64(&p->p_stats->p_ru);
2701
2702 ki->p_eflag = 0;
2703 ki->p_exitsig = p->p_exitsig;
2704
2705 ki->p_flag = sysctl_map_flags(sysctl_flagmap, p->p_flag);
2706 ki->p_flag |= sysctl_map_flags(sysctl_sflagmap, p->p_sflag);
2707 ki->p_flag |= sysctl_map_flags(sysctl_slflagmap, p->p_slflag);
2708 ki->p_flag |= sysctl_map_flags(sysctl_lflagmap, p->p_lflag);
2709 ki->p_flag |= sysctl_map_flags(sysctl_stflagmap, p->p_stflag);
2710
2711 ki->p_pid = p->p_pid;
2712 if (p->p_pptr)
2713 ki->p_ppid = p->p_pptr->p_pid;
2714 else
2715 ki->p_ppid = 0;
2716 ki->p_sid = p->p_session->s_sid;
2717 ki->p__pgid = p->p_pgrp->pg_id;
2718
2719 ki->p_tpgid = NO_PGID; /* may be changed if controlling tty below */
2720
2721 ki->p_uid = kauth_cred_geteuid(p->p_cred);
2722 ki->p_ruid = kauth_cred_getuid(p->p_cred);
2723 ki->p_gid = kauth_cred_getegid(p->p_cred);
2724 ki->p_rgid = kauth_cred_getgid(p->p_cred);
2725 ki->p_svuid = kauth_cred_getsvuid(p->p_cred);
2726 ki->p_svgid = kauth_cred_getsvgid(p->p_cred);
2727
2728 ki->p_ngroups = kauth_cred_ngroups(p->p_cred);
2729 kauth_cred_getgroups(p->p_cred, ki->p_groups,
2730 min(ki->p_ngroups, sizeof(ki->p_groups) / sizeof(ki->p_groups[0])),
2731 UIO_SYSSPACE);
2732
2733 ki->p_jobc = p->p_pgrp->pg_jobc;
2734 if ((p->p_lflag & PL_CONTROLT) && (tp = p->p_session->s_ttyp)) {
2735 ki->p_tdev = tp->t_dev;
2736 ki->p_tpgid = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PGID;
2737 ki->p_tsess = PTRTOUINT64(tp->t_session);
2738 } else {
2739 ki->p_tdev = NODEV;
2740 }
2741
2742 ki->p_estcpu = p->p_estcpu;
2743
2744 mutex_enter(&p->p_smutex);
2745
2746 ki->p_uticks = p->p_uticks;
2747 ki->p_sticks = p->p_sticks;
2748 ki->p_iticks = p->p_iticks;
2749
2750 ki->p_tracep = PTRTOUINT64(p->p_tracep);
2751 ki->p_traceflag = p->p_traceflag;
2752
2753 memcpy(&ki->p_sigignore, &p->p_sigctx.ps_sigignore,sizeof(ki_sigset_t));
2754 memcpy(&ki->p_sigcatch, &p->p_sigctx.ps_sigcatch, sizeof(ki_sigset_t));
2755
2756 ki->p_cpticks = 0;
2757 ki->p_pctcpu = p->p_pctcpu;
2758 ss1 = p->p_sigpend.sp_set;
2759 LIST_FOREACH(l, &p->p_lwps, l_sibling) {
2760 /* This is hardly correct, but... */
2761 sigplusset(&l->l_sigpend.sp_set, &ss1);
2762 sigplusset(&l->l_sigmask, &ss2);
2763 ki->p_cpticks += l->l_cpticks;
2764 ki->p_pctcpu += l->l_pctcpu;
2765 }
2766 memcpy(&ki->p_siglist, &ss1, sizeof(ki_sigset_t));
2767 memcpy(&ki->p_sigmask, &ss2, sizeof(ki_sigset_t));
2768
2769 ki->p_stat = p->p_stat; /* Will likely be overridden by LWP status */
2770 ki->p_realstat = p->p_stat;
2771 ki->p_nice = p->p_nice;
2772
2773 ki->p_xstat = p->p_xstat;
2774 ki->p_acflag = p->p_acflag;
2775
2776 strncpy(ki->p_comm, p->p_comm,
2777 min(sizeof(ki->p_comm), sizeof(p->p_comm)));
2778
2779 strncpy(ki->p_login, p->p_session->s_login,
2780 min(sizeof ki->p_login - 1, sizeof p->p_session->s_login));
2781
2782 ki->p_nlwps = p->p_nlwps;
2783 ki->p_realflag = ki->p_flag;
2784
2785 if (p->p_stat == SIDL || P_ZOMBIE(p)) {
2786 ki->p_vm_rssize = 0;
2787 ki->p_vm_tsize = 0;
2788 ki->p_vm_dsize = 0;
2789 ki->p_vm_ssize = 0;
2790 ki->p_nrlwps = 0;
2791 l = NULL;
2792 } else {
2793 struct vmspace *vm = p->p_vmspace;
2794 int tmp;
2795
2796 ki->p_vm_rssize = vm_resident_count(vm);
2797 ki->p_vm_tsize = vm->vm_tsize;
2798 ki->p_vm_dsize = vm->vm_dsize;
2799 ki->p_vm_ssize = vm->vm_ssize;
2800
2801 /* Pick a "representative" LWP */
2802 l = proc_representative_lwp(p, &tmp, 1);
2803 lwp_lock(l);
2804 ki->p_nrlwps = tmp;
2805 ki->p_forw = 0;
2806 ki->p_back = 0;
2807 ki->p_addr = PTRTOUINT64(l->l_addr);
2808 ki->p_stat = l->l_stat;
2809 ki->p_flag |= sysctl_map_flags(sysctl_lwpflagmap, l->l_flag);
2810 ki->p_swtime = l->l_swtime;
2811 ki->p_slptime = l->l_slptime;
2812 if (l->l_stat == LSONPROC)
2813 ki->p_schedflags = l->l_cpu->ci_schedstate.spc_flags;
2814 else
2815 ki->p_schedflags = 0;
2816 ki->p_holdcnt = l->l_holdcnt;
2817 ki->p_priority = l->l_priority;
2818 ki->p_usrpri = l->l_usrpri;
2819 if (l->l_wmesg)
2820 strncpy(ki->p_wmesg, l->l_wmesg, sizeof(ki->p_wmesg));
2821 ki->p_wchan = PTRTOUINT64(l->l_wchan);
2822 lwp_unlock(l);
2823 }
2824 if (p->p_session->s_ttyvp)
2825 ki->p_eflag |= EPROC_CTTY;
2826 if (SESS_LEADER(p))
2827 ki->p_eflag |= EPROC_SLEADER;
2828
2829 /* XXX Is this double check necessary? */
2830 if (P_ZOMBIE(p)) {
2831 ki->p_uvalid = 0;
2832 ki->p_rtime_sec = 0;
2833 ki->p_rtime_usec = 0;
2834 } else {
2835 ki->p_uvalid = 1;
2836
2837 ki->p_ustart_sec = p->p_stats->p_start.tv_sec;
2838 ki->p_ustart_usec = p->p_stats->p_start.tv_usec;
2839
2840 calcru(p, &ut, &st, NULL, &rt);
2841 ki->p_rtime_sec = rt.tv_sec;
2842 ki->p_rtime_usec = rt.tv_usec;
2843 ki->p_uutime_sec = ut.tv_sec;
2844 ki->p_uutime_usec = ut.tv_usec;
2845 ki->p_ustime_sec = st.tv_sec;
2846 ki->p_ustime_usec = st.tv_usec;
2847
2848 ki->p_uru_maxrss = p->p_stats->p_ru.ru_maxrss;
2849 ki->p_uru_ixrss = p->p_stats->p_ru.ru_ixrss;
2850 ki->p_uru_idrss = p->p_stats->p_ru.ru_idrss;
2851 ki->p_uru_isrss = p->p_stats->p_ru.ru_isrss;
2852 ki->p_uru_minflt = p->p_stats->p_ru.ru_minflt;
2853 ki->p_uru_majflt = p->p_stats->p_ru.ru_majflt;
2854 ki->p_uru_nswap = p->p_stats->p_ru.ru_nswap;
2855 ki->p_uru_inblock = p->p_stats->p_ru.ru_inblock;
2856 ki->p_uru_oublock = p->p_stats->p_ru.ru_oublock;
2857 ki->p_uru_msgsnd = p->p_stats->p_ru.ru_msgsnd;
2858 ki->p_uru_msgrcv = p->p_stats->p_ru.ru_msgrcv;
2859 ki->p_uru_nsignals = p->p_stats->p_ru.ru_nsignals;
2860
2861 ki->p_uru_nvcsw = 0;
2862 ki->p_uru_nivcsw = 0;
2863 LIST_FOREACH(l2, &p->p_lwps, l_sibling) {
2864 ki->p_uru_nvcsw += (l->l_ncsw - l->l_nivcsw);
2865 ki->p_uru_nivcsw += l->l_nivcsw;
2866 }
2867
2868 timeradd(&p->p_stats->p_cru.ru_utime,
2869 &p->p_stats->p_cru.ru_stime, &ut);
2870 ki->p_uctime_sec = ut.tv_sec;
2871 ki->p_uctime_usec = ut.tv_usec;
2872 }
2873 #ifdef MULTIPROCESSOR
2874 if (l != NULL)
2875 ki->p_cpuid = l->l_cpu->ci_cpuid;
2876 else
2877 #endif
2878 ki->p_cpuid = KI_NOCPU;
2879
2880 mutex_exit(&p->p_smutex);
2881 }
2882
2883 /*
2884 * Fill in a kinfo_lwp structure for the specified lwp.
2885 */
2886 static void
2887 fill_lwp(struct lwp *l, struct kinfo_lwp *kl)
2888 {
2889 struct proc *p = l->l_proc;
2890
2891 kl->l_forw = 0;
2892 kl->l_back = 0;
2893 kl->l_laddr = PTRTOUINT64(l);
2894 kl->l_addr = PTRTOUINT64(l->l_addr);
2895 kl->l_stat = l->l_stat;
2896 kl->l_lid = l->l_lid;
2897 kl->l_flag = sysctl_map_flags(sysctl_lwpprflagmap, l->l_prflag);
2898
2899 kl->l_swtime = l->l_swtime;
2900 kl->l_slptime = l->l_slptime;
2901 if (l->l_stat == LSONPROC)
2902 kl->l_schedflags = l->l_cpu->ci_schedstate.spc_flags;
2903 else
2904 kl->l_schedflags = 0;
2905 kl->l_holdcnt = l->l_holdcnt;
2906 kl->l_priority = l->l_priority;
2907 kl->l_usrpri = l->l_usrpri;
2908 if (l->l_wmesg)
2909 strncpy(kl->l_wmesg, l->l_wmesg, sizeof(kl->l_wmesg));
2910 kl->l_wchan = PTRTOUINT64(l->l_wchan);
2911 #ifdef MULTIPROCESSOR
2912 kl->l_cpuid = l->l_cpu->ci_cpuid;
2913 #else
2914 kl->l_cpuid = KI_NOCPU;
2915 #endif
2916 kl->l_rtime_sec = l->l_rtime.tv_sec;
2917 kl->l_rtime_usec = l->l_rtime.tv_usec;
2918 kl->l_cpticks = l->l_cpticks;
2919 kl->l_pctcpu = l->l_pctcpu;
2920 kl->l_pid = p->p_pid;
2921 if (l->l_name == NULL)
2922 kl->l_name[0] = '\0';
2923 else
2924 strlcpy(kl->l_name, l->l_name, sizeof(kl->l_name));
2925 }
2926
2927 /*
2928 * Fill in an eproc structure for the specified process.
2929 */
2930 void
2931 fill_eproc(struct proc *p, struct eproc *ep)
2932 {
2933 struct tty *tp;
2934 struct lwp *l;
2935
2936 ep->e_paddr = p;
2937 ep->e_sess = p->p_session;
2938 kauth_cred_topcred(p->p_cred, &ep->e_pcred);
2939 kauth_cred_toucred(p->p_cred, &ep->e_ucred);
2940 if (p->p_stat == SIDL || P_ZOMBIE(p)) {
2941 ep->e_vm.vm_rssize = 0;
2942 ep->e_vm.vm_tsize = 0;
2943 ep->e_vm.vm_dsize = 0;
2944 ep->e_vm.vm_ssize = 0;
2945 /* ep->e_vm.vm_pmap = XXX; */
2946 } else {
2947 struct vmspace *vm = p->p_vmspace;
2948
2949 ep->e_vm.vm_rssize = vm_resident_count(vm);
2950 ep->e_vm.vm_tsize = vm->vm_tsize;
2951 ep->e_vm.vm_dsize = vm->vm_dsize;
2952 ep->e_vm.vm_ssize = vm->vm_ssize;
2953
2954 /* Pick a "representative" LWP */
2955 mutex_enter(&p->p_smutex);
2956 l = proc_representative_lwp(p, NULL, 1);
2957 lwp_lock(l);
2958 if (l->l_wmesg)
2959 strncpy(ep->e_wmesg, l->l_wmesg, WMESGLEN);
2960 lwp_unlock(l);
2961 mutex_exit(&p->p_smutex);
2962 }
2963 if (p->p_pptr)
2964 ep->e_ppid = p->p_pptr->p_pid;
2965 else
2966 ep->e_ppid = 0;
2967 ep->e_pgid = p->p_pgrp->pg_id;
2968 ep->e_sid = ep->e_sess->s_sid;
2969 ep->e_jobc = p->p_pgrp->pg_jobc;
2970 if ((p->p_lflag & PL_CONTROLT) &&
2971 (tp = ep->e_sess->s_ttyp)) {
2972 ep->e_tdev = tp->t_dev;
2973 ep->e_tpgid = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PGID;
2974 ep->e_tsess = tp->t_session;
2975 } else
2976 ep->e_tdev = NODEV;
2977
2978 ep->e_xsize = ep->e_xrssize = 0;
2979 ep->e_xccount = ep->e_xswrss = 0;
2980 ep->e_flag = ep->e_sess->s_ttyvp ? EPROC_CTTY : 0;
2981 if (SESS_LEADER(p))
2982 ep->e_flag |= EPROC_SLEADER;
2983 strncpy(ep->e_login, ep->e_sess->s_login, MAXLOGNAME);
2984 }
2985
2986 u_int
2987 sysctl_map_flags(const u_int *map, u_int word)
2988 {
2989 u_int rv;
2990
2991 for (rv = 0; *map != 0; map += 2)
2992 if ((word & map[0]) != 0)
2993 rv |= map[1];
2994
2995 return rv;
2996 }
2997