1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
|
/* $NetBSD: init_sysctl.c,v 1.19 2003/12/28 22:36:37 atatat Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Andrew Brown.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.19 2003/12/28 22:36:37 atatat Exp $");
#include "opt_sysv.h"
#include "opt_multiprocessor.h"
#include "opt_posix.h"
#include "pty.h"
#include "rnd.h"
#include <sys/types.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/errno.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/unistd.h>
#include <sys/disklabel.h>
#include <sys/rnd.h>
#include <sys/vnode.h>
#include <sys/mount.h>
#include <sys/namei.h>
#include <sys/msgbuf.h>
#include <dev/cons.h>
#include <sys/socketvar.h>
#include <sys/file.h>
#include <sys/tty.h>
#include <sys/malloc.h>
#include <sys/resource.h>
#include <sys/resourcevar.h>
#include <sys/exec.h>
#include <sys/conf.h>
#include <sys/device.h>
#if defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM)
#include <sys/ipc.h>
#endif
#ifdef SYSVMSG
#include <sys/msg.h>
#endif
#ifdef SYSVSEM
#include <sys/sem.h>
#endif
#ifdef SYSVSHM
#include <sys/shm.h>
#endif
#include <machine/cpu.h>
/*
* try over estimating by 5 procs/lwps
*/
#define KERN_PROCSLOP (5 * sizeof(struct kinfo_proc))
#define KERN_LWPSLOP (5 * sizeof(struct kinfo_lwp))
/*
* convert pointer to 64 int for struct kinfo_proc2
*/
#define PTRTOINT64(foo) ((u_int64_t)(uintptr_t)(foo))
#ifndef MULTIPROCESSOR
#define sysctl_ncpus() (1)
#else /* MULTIPROCESSOR */
#ifndef CPU_INFO_FOREACH
#define CPU_INFO_ITERATOR int
#define CPU_INFO_FOREACH(cii, ci) cii = 0, ci = curcpu(); ci != NULL; ci = NULL
#endif
static int
sysctl_ncpus(void)
{
struct cpu_info *ci;
CPU_INFO_ITERATOR cii;
int ncpus = 0;
for (CPU_INFO_FOREACH(cii, ci))
ncpus++;
return (ncpus);
}
#endif /* MULTIPROCESSOR */
static int sysctl_kern_maxvnodes(SYSCTLFN_PROTO);
static int sysctl_kern_rtc_offset(SYSCTLFN_PROTO);
static int sysctl_kern_maxproc(SYSCTLFN_PROTO);
static int sysctl_kern_securelevel(SYSCTLFN_PROTO);
static int sysctl_kern_hostid(SYSCTLFN_PROTO);
static int sysctl_setlen(SYSCTLFN_PROTO);
static int sysctl_kern_clockrate(SYSCTLFN_PROTO);
static int sysctl_kern_file(SYSCTLFN_PROTO);
static int sysctl_kern_autonice(SYSCTLFN_PROTO);
static int sysctl_msgbuf(SYSCTLFN_PROTO);
static int sysctl_kern_defcorename(SYSCTLFN_PROTO);
static int sysctl_kern_cptime(SYSCTLFN_PROTO);
#if defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM)
static int sysctl_kern_sysvipc(SYSCTLFN_PROTO);
#endif /* defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM) */
#if NPTY > 0
static int sysctl_kern_maxptys(SYSCTLFN_PROTO);
#endif /* NPTY > 0 */
static int sysctl_kern_sbmax(SYSCTLFN_PROTO);
static int sysctl_kern_urnd(SYSCTLFN_PROTO);
static int sysctl_kern_lwp(SYSCTLFN_PROTO);
static int sysctl_kern_forkfsleep(SYSCTLFN_PROTO);
static int sysctl_kern_somaxkva(SYSCTLFN_PROTO);
static int sysctl_kern_root_partition(SYSCTLFN_PROTO);
static int sysctl_kern_drivers(SYSCTLFN_PROTO);
static int sysctl_doeproc(SYSCTLFN_PROTO);
static int sysctl_kern_proc_args(SYSCTLFN_PROTO);
static int sysctl_hw_usermem(SYSCTLFN_PROTO);
static int sysctl_hw_cnmagic(SYSCTLFN_PROTO);
static int sysctl_hw_ncpu(SYSCTLFN_PROTO);
static void fill_kproc2(struct proc *, struct kinfo_proc2 *);
static void fill_lwp(struct lwp *l, struct kinfo_lwp *kl);
/*
* ********************************************************************
* section 1: setup routines
* ********************************************************************
* these functions are stuffed into a link set for sysctl setup
* functions. they're never called or referenced from anywhere else.
* ********************************************************************
*/
/*
* sets up the base nodes...
*/
SYSCTL_SETUP(sysctl_root_setup, "sysctl base setup")
{
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_NODE, "kern", NULL,
NULL, 0, NULL, 0,
CTL_KERN, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_NODE, "vm", NULL,
NULL, 0, NULL, 0,
CTL_VM, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_NODE, "vfs", NULL,
NULL, 0, NULL, 0,
CTL_VFS, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_NODE, "net", NULL,
NULL, 0, NULL, 0,
CTL_NET, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_NODE, "debug", NULL,
NULL, 0, NULL, 0,
CTL_DEBUG, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_NODE, "hw", NULL,
NULL, 0, NULL, 0,
CTL_HW, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_NODE, "machdep", NULL,
NULL, 0, NULL, 0,
CTL_MACHDEP, CTL_EOL);
/*
* this node is inserted so that the sysctl nodes in libc can
* operate.
*/
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_NODE, "user", NULL,
NULL, 0, NULL, 0,
CTL_USER, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_NODE, "ddb", NULL,
NULL, 0, NULL, 0,
CTL_DDB, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_NODE, "proc", NULL,
NULL, 0, NULL, 0,
CTL_PROC, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
CTLTYPE_NODE, "vendor", NULL,
NULL, 0, NULL, 0,
CTL_VENDOR, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_NODE, "emul", NULL,
NULL, 0, NULL, 0,
CTL_EMUL, CTL_EOL);
}
/*
* this setup routine is a replacement for kern_sysctl()
*/
SYSCTL_SETUP(sysctl_kern_setup, "sysctl kern subtree setup")
{
extern int kern_logsigexit; /* defined in kern/kern_sig.c */
extern fixpt_t ccpu; /* defined in kern/kern_synch.c */
extern int dumponpanic; /* defined in kern/subr_prf.c */
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_NODE, "kern", NULL,
NULL, 0, NULL, 0,
CTL_KERN, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_STRING, "ostype", NULL,
NULL, 0, &ostype, 0,
CTL_KERN, KERN_OSTYPE, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_STRING, "osrelease", NULL,
NULL, 0, &osrelease, 0,
CTL_KERN, KERN_OSRELEASE, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "osrevision", NULL,
NULL, __NetBSD_Version__, NULL, 0,
CTL_KERN, KERN_OSREV, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_STRING, "version", NULL,
NULL, 0, &version, 0,
CTL_KERN, KERN_VERSION, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
CTLTYPE_INT, "maxvnodes", NULL,
sysctl_kern_maxvnodes, 0, NULL, 0,
CTL_KERN, KERN_MAXVNODES, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
CTLTYPE_INT, "maxproc", NULL,
sysctl_kern_maxproc, 0, NULL, 0,
CTL_KERN, KERN_MAXPROC, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
CTLTYPE_INT, "maxfiles", NULL,
NULL, 0, &maxfiles, 0,
CTL_KERN, KERN_MAXFILES, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "argmax", NULL,
NULL, ARG_MAX, NULL, 0,
CTL_KERN, KERN_ARGMAX, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
CTLTYPE_INT, "securelevel", NULL,
sysctl_kern_securelevel, 0, &securelevel, 0,
CTL_KERN, KERN_SECURELVL, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
CTLTYPE_STRING, "hostname", NULL,
sysctl_setlen, 0, &hostname, MAXHOSTNAMELEN,
CTL_KERN, KERN_HOSTNAME, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
CTLTYPE_INT, "hostid", NULL,
sysctl_kern_hostid, 0, NULL, 0,
CTL_KERN, KERN_HOSTID, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_STRUCT, "clockrate", NULL,
sysctl_kern_clockrate, 0, NULL,
sizeof(struct clockinfo),
CTL_KERN, KERN_CLOCKRATE, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_STRUCT, "vnode", NULL,
sysctl_kern_vnode, 0, NULL, 0,
CTL_KERN, KERN_VNODE, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_STRUCT, "file", NULL,
sysctl_kern_file, 0, NULL, 0,
CTL_KERN, KERN_FILE, CTL_EOL);
#ifndef GPROF
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_NODE, "profiling", NULL,
sysctl_notavail, 0, NULL, 0,
CTL_KERN, KERN_PROF, CTL_EOL);
#endif
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "posix1version", NULL,
NULL, _POSIX_VERSION, NULL, 0,
CTL_KERN, KERN_POSIX1, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "ngroups", NULL,
NULL, NGROUPS_MAX, NULL, 0,
CTL_KERN, KERN_NGROUPS, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "job_control", NULL,
NULL, 1, NULL, 0,
CTL_KERN, KERN_JOB_CONTROL, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "saved_ids", NULL, NULL,
#ifdef _POSIX_SAVED_IDS
1,
#else /* _POSIX_SAVED_IDS */
0,
#endif /* _POSIX_SAVED_IDS */
NULL, 0, CTL_KERN, KERN_SAVED_IDS, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_STRUCT, "boottime", NULL,
NULL, 0, &boottime, sizeof(boottime),
CTL_KERN, KERN_BOOTTIME, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
CTLTYPE_STRING, "domainname", NULL,
sysctl_setlen, 0, &domainname, MAXHOSTNAMELEN,
CTL_KERN, KERN_DOMAINNAME, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "maxpartitions", NULL,
NULL, MAXPARTITIONS, NULL, 0,
CTL_KERN, KERN_MAXPARTITIONS, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "rawpartition", NULL,
NULL, RAW_PART, NULL, 0,
CTL_KERN, KERN_RAWPARTITION, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_STRUCT, "timex", NULL,
sysctl_notavail, 0, NULL, 0,
CTL_KERN, KERN_TIMEX, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
CTLTYPE_INT, "autonicetime", NULL,
sysctl_kern_autonice, 0, &autonicetime, 0,
CTL_KERN, KERN_AUTONICETIME, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
CTLTYPE_INT, "autoniceval", NULL,
sysctl_kern_autonice, 0, &autoniceval, 0,
CTL_KERN, KERN_AUTONICEVAL, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
CTLTYPE_INT, "rtc_offset", NULL,
sysctl_kern_rtc_offset, 0, &rtc_offset, 0,
CTL_KERN, KERN_RTC_OFFSET, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_STRING, "root_device", NULL,
sysctl_root_device, 0, NULL, 0,
CTL_KERN, KERN_ROOT_DEVICE, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_INT, "msgbufsize", NULL,
sysctl_msgbuf, 0, &msgbufp->msg_bufs, 0,
CTL_KERN, KERN_MSGBUFSIZE, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "fsync", NULL,
NULL, 1, NULL, 0,
CTL_KERN, KERN_FSYNC, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "sysvmsg", NULL, NULL,
#ifdef SYSVMSG
1,
#else /* SYSVMSG */
0,
#endif /* SYSVMSG */
NULL, 0, CTL_KERN, KERN_SYSVMSG, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "sysvsem", NULL, NULL,
#ifdef SYSVSEM
1,
#else /* SYSVSEM */
0,
#endif /* SYSVSEM */
NULL, 0, CTL_KERN, KERN_SYSVSEM, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "sysvshm", NULL, NULL,
#ifdef SYSVSHM
1,
#else /* SYSVSHM */
0,
#endif /* SYSVSHM */
NULL, 0, CTL_KERN, KERN_SYSVSHM, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "synchronized_io", NULL,
NULL, 1, NULL, 0,
CTL_KERN, KERN_SYNCHRONIZED_IO, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "iov_max", NULL,
NULL, IOV_MAX, NULL, 0,
CTL_KERN, KERN_IOV_MAX, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "mapped_files", NULL,
NULL, 1, NULL, 0,
CTL_KERN, KERN_MAPPED_FILES, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "memlock", NULL,
NULL, 1, NULL, 0,
CTL_KERN, KERN_MEMLOCK, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "memlock_range", NULL,
NULL, 1, NULL, 0,
CTL_KERN, KERN_MEMLOCK_RANGE, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "memory_protection", NULL,
NULL, 1, NULL, 0,
CTL_KERN, KERN_MEMORY_PROTECTION, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "login_name_max", NULL,
NULL, LOGIN_NAME_MAX, NULL, 0,
CTL_KERN, KERN_LOGIN_NAME_MAX, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
CTLTYPE_STRING, "defcorename", NULL,
sysctl_kern_defcorename, 0, defcorename, MAXPATHLEN,
CTL_KERN, KERN_DEFCORENAME, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
CTLTYPE_INT, "logsigexit", NULL,
NULL, 0, &kern_logsigexit, 0,
CTL_KERN, KERN_LOGSIGEXIT, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "fscale", NULL,
NULL, FSCALE, NULL, 0,
CTL_KERN, KERN_FSCALE, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_INT, "ccpu", NULL,
NULL, 0, &ccpu, 0,
CTL_KERN, KERN_CCPU, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_STRUCT, "cp_time", NULL,
sysctl_kern_cptime, 0, NULL, 0,
CTL_KERN, KERN_CP_TIME, CTL_EOL);
#if defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM)
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_STRUCT, "sysvipc_info", NULL,
sysctl_kern_sysvipc, 0, NULL, 0,
CTL_KERN, KERN_SYSVIPC_INFO, CTL_EOL);
#endif /* SYSVMSG || SYSVSEM || SYSVSHM */
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_INT, "msgbuf", NULL,
sysctl_msgbuf, 0, NULL, 0,
CTL_KERN, KERN_MSGBUF, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_STRUCT, "consdev", NULL,
sysctl_consdev, 0, NULL, sizeof(dev_t),
CTL_KERN, KERN_CONSDEV, CTL_EOL);
#if NPTY > 0
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_INT, "maxptys", NULL,
sysctl_kern_maxptys, 0, NULL, 0,
CTL_KERN, KERN_MAXPTYS, CTL_EOL);
#endif /* NPTY > 0 */
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "maxphys", NULL,
NULL, MAXPHYS, NULL, 0,
CTL_KERN, KERN_MAXPHYS, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
CTLTYPE_INT, "sbmax", NULL,
sysctl_kern_sbmax, 0, NULL, 0,
CTL_KERN, KERN_SBMAX, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "monotonic_clock", NULL,
/* XXX _POSIX_VERSION */
NULL, _POSIX_MONOTONIC_CLOCK, NULL, 0,
CTL_KERN, KERN_MONOTONIC_CLOCK, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_INT, "urandom", NULL,
sysctl_kern_urnd, 0, NULL, 0,
CTL_KERN, KERN_URND, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "labelsector", NULL,
NULL, LABELSECTOR, NULL, 0,
CTL_KERN, KERN_LABELSECTOR, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "labeloffset", NULL,
NULL, LABELOFFSET, NULL, 0,
CTL_KERN, KERN_LABELOFFSET, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_NODE, "lwp", NULL,
sysctl_kern_lwp, 0, NULL, 0,
CTL_KERN, KERN_LWP, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
CTLTYPE_INT, "forkfsleep", NULL,
sysctl_kern_forkfsleep, 0, NULL, 0,
CTL_KERN, KERN_FORKFSLEEP, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "posix_threads", NULL,
/* XXX _POSIX_VERSION */
NULL, _POSIX_THREADS, NULL, 0,
CTL_KERN, KERN_POSIX_THREADS, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "posix_semaphores", NULL, NULL,
#ifdef P1003_1B_SEMAPHORE
200112,
#else /* P1003_1B_SEMAPHORE */
0,
#endif /* P1003_1B_SEMAPHORE */
NULL, 0, CTL_KERN, KERN_POSIX_SEMAPHORES, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "posix_barriers", NULL,
/* XXX _POSIX_VERSION */
NULL, _POSIX_BARRIERS, NULL, 0,
CTL_KERN, KERN_POSIX_BARRIERS, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "posix_timers", NULL,
/* XXX _POSIX_VERSION */
NULL, _POSIX_TIMERS, NULL, 0,
CTL_KERN, KERN_POSIX_TIMERS, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "posix_spin_locks", NULL,
/* XXX _POSIX_VERSION */
NULL, _POSIX_SPIN_LOCKS, NULL, 0,
CTL_KERN, KERN_POSIX_SPIN_LOCKS, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "posix_reader_writer_locks", NULL,
/* XXX _POSIX_VERSION */
NULL, _POSIX_READER_WRITER_LOCKS, NULL, 0,
CTL_KERN, KERN_POSIX_READER_WRITER_LOCKS, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
CTLTYPE_INT, "dump_on_panic", NULL,
NULL, 0, &dumponpanic, 0,
CTL_KERN, KERN_DUMP_ON_PANIC, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
CTLTYPE_INT, "somaxkva", NULL,
sysctl_kern_somaxkva, 0, NULL, 0,
CTL_KERN, KERN_SOMAXKVA, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_INT, "root_partition", NULL,
sysctl_kern_root_partition, 0, NULL, 0,
CTL_KERN, KERN_ROOT_PARTITION, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_STRUCT, "drivers", NULL,
sysctl_kern_drivers, 0, NULL, 0,
CTL_KERN, KERN_DRIVERS, CTL_EOL);
}
SYSCTL_SETUP(sysctl_kern_proc_setup,
"sysctl kern.proc/proc2/proc_args subtree setup")
{
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_NODE, "kern", NULL,
NULL, 0, NULL, 0,
CTL_KERN, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_NODE, "proc", NULL,
sysctl_doeproc, 0, NULL, 0,
CTL_KERN, KERN_PROC, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_NODE, "proc2", NULL,
sysctl_doeproc, 0, NULL, 0,
CTL_KERN, KERN_PROC2, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_NODE, "proc_args", NULL,
sysctl_kern_proc_args, 0, NULL, 0,
CTL_KERN, KERN_PROC_ARGS, CTL_EOL);
/*
"nodes" under these:
KERN_PROC_ALL
KERN_PROC_PID pid
KERN_PROC_PGRP pgrp
KERN_PROC_SESSION sess
KERN_PROC_TTY tty
KERN_PROC_UID uid
KERN_PROC_RUID uid
KERN_PROC_GID gid
KERN_PROC_RGID gid
all in all, probably not worth the effort...
*/
}
SYSCTL_SETUP(sysctl_hw_setup, "sysctl hw subtree setup")
{
u_int u;
u_quad_t q;
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_NODE, "hw", NULL,
NULL, 0, NULL, 0,
CTL_HW, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_STRING, "machine", NULL,
NULL, 0, machine, 0,
CTL_HW, HW_MACHINE, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_STRING, "model", NULL,
NULL, 0, cpu_model, 0,
CTL_HW, HW_MODEL, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_INT, "ncpu", NULL,
sysctl_hw_ncpu, 0, NULL, 0,
CTL_HW, HW_NCPU, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "byteorder", NULL,
NULL, BYTE_ORDER, NULL, 0,
CTL_HW, HW_BYTEORDER, CTL_EOL);
u = ((u_int)physmem > (UINT_MAX / PAGE_SIZE)) ?
UINT_MAX : physmem * PAGE_SIZE;
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "physmem", NULL,
NULL, u, NULL, 0,
CTL_HW, HW_PHYSMEM, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_INT, "usermem", NULL,
sysctl_hw_usermem, 0, NULL, 0,
CTL_HW, HW_USERMEM, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "pagesize", NULL,
NULL, PAGE_SIZE, NULL, 0,
CTL_HW, HW_PAGESIZE, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_STRING, "disknames", NULL,
sysctl_hw_disknames, 0, NULL, 0,
CTL_HW, HW_DISKNAMES, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_STRUCT, "diskstats", NULL,
sysctl_hw_diskstats, 0, NULL, 0,
CTL_HW, HW_DISKSTATS, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_STRING, "machine_arch", NULL,
NULL, 0, machine_arch, 0,
CTL_HW, HW_MACHINE_ARCH, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_INT, "alignbytes", NULL,
NULL, ALIGNBYTES, NULL, 0,
CTL_HW, HW_ALIGNBYTES, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE|SYSCTL_HEX,
CTLTYPE_STRING, "cnmagic", NULL,
sysctl_hw_cnmagic, 0, NULL, CNS_LEN,
CTL_HW, HW_CNMAGIC, CTL_EOL);
q = (u_quad_t)physmem * PAGE_SIZE;
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_IMMEDIATE,
CTLTYPE_QUAD, "physmem64", NULL,
NULL, q, NULL, 0,
CTL_HW, HW_PHYSMEM64, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_QUAD, "usermem64", NULL,
sysctl_hw_usermem, 0, NULL, 0,
CTL_HW, HW_USERMEM64, CTL_EOL);
}
#ifdef DEBUG
/*
* Debugging related system variables.
*/
struct ctldebug /* debug0, */ /* debug1, */ debug2, debug3, debug4;
struct ctldebug debug5, debug6, debug7, debug8, debug9;
struct ctldebug debug10, debug11, debug12, debug13, debug14;
struct ctldebug debug15, debug16, debug17, debug18, debug19;
static struct ctldebug *debugvars[CTL_DEBUG_MAXID] = {
&debug0, &debug1, &debug2, &debug3, &debug4,
&debug5, &debug6, &debug7, &debug8, &debug9,
&debug10, &debug11, &debug12, &debug13, &debug14,
&debug15, &debug16, &debug17, &debug18, &debug19,
};
/*
* this setup routine is a replacement for debug_sysctl()
*
* note that it creates several nodes per defined debug variable
*/
SYSCTL_SETUP(sysctl_debug_setup, "sysctl debug subtree setup")
{
struct ctldebug *cdp;
char nodename[20];
int i;
/*
* two ways here:
*
* the "old" way (debug.name -> value) which was emulated by
* the sysctl(8) binary
*
* the new way, which the sysctl(8) binary was actually using
node debug
node debug.0
string debug.0.name
int debug.0.value
int debug.name
*/
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_NODE, "debug", NULL,
NULL, 0, NULL, 0,
CTL_DEBUG, CTL_EOL);
for (i = 0; i < CTL_DEBUG_MAXID; i++) {
cdp = debugvars[i];
if (cdp->debugname == NULL || cdp->debugvar == NULL)
continue;
snprintf(nodename, sizeof(nodename), "debug%d", i);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_HIDDEN,
CTLTYPE_NODE, nodename, NULL,
NULL, 0, NULL, 0,
CTL_DEBUG, i, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_HIDDEN,
CTLTYPE_STRING, "name", NULL,
NULL, 0, cdp->debugname, 0,
CTL_DEBUG, i, CTL_DEBUG_NAME, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_HIDDEN,
CTLTYPE_INT, "value", NULL,
NULL, 0, cdp->debugvar, 0,
CTL_DEBUG, i, CTL_DEBUG_VALUE, CTL_EOL);
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_INT, cdp->debugname, NULL,
NULL, 0, cdp->debugvar, 0,
CTL_DEBUG, CTL_CREATE, CTL_EOL);
}
}
#endif /* DEBUG */
/*
* ********************************************************************
* section 2: private node-specific helper routines.
* ********************************************************************
*/
/*
* sysctl helper routine for kern.maxvnodes. drain vnodes if
* new value is lower than desiredvnodes and then calls reinit
* routines that needs to adjust to the new value.
*/
static int
sysctl_kern_maxvnodes(SYSCTLFN_ARGS)
{
int error, new_vnodes, old_vnodes;
struct sysctlnode node;
new_vnodes = desiredvnodes;
node = *rnode;
node.sysctl_data = &new_vnodes;
error = sysctl_lookup(SYSCTLFN_CALL(&node));
if (error || newp == NULL)
return (error);
old_vnodes = desiredvnodes;
desiredvnodes = new_vnodes;
if (new_vnodes < old_vnodes) {
error = vfs_drainvnodes(new_vnodes, l->l_proc);
if (error) {
desiredvnodes = old_vnodes;
return (error);
}
}
vfs_reinit();
nchreinit();
return (0);
}
/*
* sysctl helper routine for rtc_offset - set time after changes
*/
static int
sysctl_kern_rtc_offset(SYSCTLFN_ARGS)
{
struct timeval tv, delta;
int s, error, new_rtc_offset;
struct sysctlnode node;
new_rtc_offset = rtc_offset;
node = *rnode;
node.sysctl_data = &new_rtc_offset;
error = sysctl_lookup(SYSCTLFN_CALL(&node));
if (error || newp == NULL)
return (error);
if (securelevel > 0)
return (EPERM);
if (rtc_offset == new_rtc_offset)
return (0);
/* if we change the offset, adjust the time */
s = splclock();
tv = time;
splx(s);
delta.tv_sec = 60*(new_rtc_offset - rtc_offset);
delta.tv_usec = 0;
timeradd(&tv, &delta, &tv);
rtc_offset = new_rtc_offset;
settime(&tv);
return (0);
}
/*
* sysctl helper routine for kern.maxvnodes. ensures that the new
* values are not too low or too high.
*/
static int
sysctl_kern_maxproc(SYSCTLFN_ARGS)
{
int error, nmaxproc;
struct sysctlnode node;
nmaxproc = maxproc;
node = *rnode;
node.sysctl_data = &nmaxproc;
error = sysctl_lookup(SYSCTLFN_CALL(&node));
if (error || newp == NULL)
return (error);
if (nmaxproc < 0 || nmaxproc >= PID_MAX)
return (EINVAL);
#ifdef __HAVE_CPU_MAXPROC
if (nmaxproc > cpu_maxproc())
return (EINVAL);
#endif
maxproc = nmaxproc;
return (0);
}
/*
* sysctl helper routine for kern.securelevel. ensures that the value
* only rises unless the caller has pid 1 (assumed to be init).
*/
static int
sysctl_kern_securelevel(SYSCTLFN_ARGS)
{
int newsecurelevel, error;
struct sysctlnode node;
newsecurelevel = securelevel;
node = *rnode;
node.sysctl_data = &newsecurelevel;
error = sysctl_lookup(SYSCTLFN_CALL(&node));
if (error || newp == NULL)
return (error);
if (newsecurelevel < securelevel && l->l_proc->p_pid != 1)
return (EPERM);
securelevel = newsecurelevel;
return (error);
}
/*
* sysctl helper function for kern.hostid. the hostid is a long, but
* we export it as an int, so we need to give it a little help.
*/
static int
sysctl_kern_hostid(SYSCTLFN_ARGS)
{
int error, inthostid;
struct sysctlnode node;
inthostid = hostid; /* XXX assumes sizeof int >= sizeof long */
node = *rnode;
node.sysctl_data = &inthostid;
error = sysctl_lookup(SYSCTLFN_CALL(&node));
if (error || newp == NULL)
return (error);
hostid = inthostid;
return (0);
}
/*
* sysctl helper function for kern.hostname and kern.domainnname.
* resets the relevant recorded length when the underlying name is
* changed.
*/
static int
sysctl_setlen(SYSCTLFN_ARGS)
{
int error;
error = sysctl_lookup(SYSCTLFN_CALL(rnode));
if (error || newp == NULL)
return (error);
switch (rnode->sysctl_num) {
case KERN_HOSTNAME:
hostnamelen = strlen((const char*)rnode->sysctl_data);
break;
case KERN_DOMAINNAME:
domainnamelen = strlen((const char*)rnode->sysctl_data);
break;
}
return (0);
}
/*
* sysctl helper routine for kern.clockrate. assembles a struct on
* the fly to be returned to the caller.
*/
static int
sysctl_kern_clockrate(SYSCTLFN_ARGS)
{
struct clockinfo clkinfo;
struct sysctlnode node;
clkinfo.tick = tick;
clkinfo.tickadj = tickadj;
clkinfo.hz = hz;
clkinfo.profhz = profhz;
clkinfo.stathz = stathz ? stathz : hz;
node = *rnode;
node.sysctl_data = &clkinfo;
return (sysctl_lookup(SYSCTLFN_CALL(&node)));
}
/*
* sysctl helper routine for kern.file pseudo-subtree.
*/
static int
sysctl_kern_file(SYSCTLFN_ARGS)
{
int error;
size_t buflen;
struct file *fp;
char *start, *where;
start = where = oldp;
buflen = *oldlenp;
if (where == NULL) {
/*
* overestimate by 10 files
*/
*oldlenp = sizeof(filehead) + (nfiles + 10) * sizeof(struct file);
return (0);
}
/*
* first copyout filehead
*/
if (buflen < sizeof(filehead)) {
*oldlenp = 0;
return (0);
}
error = copyout(&filehead, where, sizeof(filehead));
if (error)
return (error);
buflen -= sizeof(filehead);
where += sizeof(filehead);
/*
* followed by an array of file structures
*/
LIST_FOREACH(fp, &filehead, f_list) {
if (buflen < sizeof(struct file)) {
*oldlenp = where - start;
return (ENOMEM);
}
error = copyout(fp, where, sizeof(struct file));
if (error)
return (error);
buflen -= sizeof(struct file);
where += sizeof(struct file);
}
*oldlenp = where - start;
return (0);
}
/*
* sysctl helper routine for kern.autonicetime and kern.autoniceval.
* asserts that the assigned value is in the correct range.
*/
static int
sysctl_kern_autonice(SYSCTLFN_ARGS)
{
int error, t = 0;
struct sysctlnode node;
node = *rnode;
t = *(int*)node.sysctl_data;
node.sysctl_data = &t;
error = sysctl_lookup(SYSCTLFN_CALL(&node));
if (error || newp == NULL)
return (error);
switch (node.sysctl_num) {
case KERN_AUTONICETIME:
if (t >= 0)
autonicetime = t;
break;
case KERN_AUTONICEVAL:
if (t < PRIO_MIN)
t = PRIO_MIN;
else if (t > PRIO_MAX)
t = PRIO_MAX;
autoniceval = t;
break;
}
return (0);
}
/*
* sysctl helper routine for kern.msgbufsize and kern.msgbuf. for the
* former it merely checks the the message buffer is set up. for the
* latter, it also copies out the data if necessary.
*/
static int
sysctl_msgbuf(SYSCTLFN_ARGS)
{
char *where = oldp;
size_t len, maxlen;
long beg, end;
int error;
if (!msgbufenabled || msgbufp->msg_magic != MSG_MAGIC) {
msgbufenabled = 0;
return (ENXIO);
}
switch (rnode->sysctl_num) {
case KERN_MSGBUFSIZE:
return (sysctl_lookup(SYSCTLFN_CALL(rnode)));
case KERN_MSGBUF:
break;
default:
return (EOPNOTSUPP);
}
if (newp != NULL)
return (EPERM);
if (oldp == NULL) {
/* always return full buffer size */
*oldlenp = msgbufp->msg_bufs;
return (0);
}
error = 0;
maxlen = MIN(msgbufp->msg_bufs, *oldlenp);
/*
* First, copy from the write pointer to the end of
* message buffer.
*/
beg = msgbufp->msg_bufx;
end = msgbufp->msg_bufs;
while (maxlen > 0) {
len = MIN(end - beg, maxlen);
if (len == 0)
break;
error = copyout(&msgbufp->msg_bufc[beg], where, len);
if (error)
break;
where += len;
maxlen -= len;
/*
* ... then, copy from the beginning of message buffer to
* the write pointer.
*/
beg = 0;
end = msgbufp->msg_bufx;
}
return (error);
}
/*
* sysctl helper routine for kern.defcorename. in the case of a new
* string being assigned, check that it's not a zero-length string.
* (XXX the check in -current doesn't work, but do we really care?)
*/
static int
sysctl_kern_defcorename(SYSCTLFN_ARGS)
{
int error;
char newcorename[MAXPATHLEN];
struct sysctlnode node;
node = *rnode;
node.sysctl_data = &newcorename[0];
memcpy(node.sysctl_data, rnode->sysctl_data, MAXPATHLEN);
error = sysctl_lookup(SYSCTLFN_CALL(&node));
if (error || newp == NULL)
return (error);
/*
* when sysctl_lookup() deals with a string, it's guaranteed
* to come back nul terminated. so there. :)
*/
if (strlen(newcorename) == 0)
return (EINVAL);
memcpy(rnode->sysctl_data, node.sysctl_data, MAXPATHLEN);
return (0);
}
/*
* sysctl helper routine for kern.cp_time node. adds up cpu time
* across all cpus.
*/
static int
sysctl_kern_cptime(SYSCTLFN_ARGS)
{
struct sysctlnode node = *rnode;
#ifndef MULTIPROCESSOR
if (namelen == 1) {
if (name[0] != 0)
return (ENOENT);
/*
* you're allowed to ask for the zero'th processor
*/
name++;
namelen--;
}
node.sysctl_data = curcpu()->ci_schedstate.spc_cp_time;
node.sysctl_size = sizeof(curcpu()->ci_schedstate.spc_cp_time);
return (sysctl_lookup(SYSCTLFN_CALL(&node)));
#else /* MULTIPROCESSOR */
u_int64_t *cp_time = NULL;
int error, n = sysctl_ncpus(), i;
struct cpu_info *ci;
CPU_INFO_ITERATOR cii;
/*
* if you specifically pass a buffer that is the size of the
* sum, or if you are probing for the size, you get the "sum"
* of cp_time (and the size thereof) across all processors.
*
* alternately, you can pass an additional mib number and get
* cp_time for that particular processor.
*/
switch (namelen) {
case 0:
if (*oldlenp == sizeof(u_int64_t) * CPUSTATES || oldp == NULL) {
node.sysctl_size = sizeof(u_int64_t) * CPUSTATES;
n = -1; /* SUM */
}
else {
node.sysctl_size = n * sizeof(u_int64_t) * CPUSTATES;
n = -2; /* ALL */
}
break;
case 1:
if (name[0] < 0 || name[0] >= n)
return (ENOENT); /* ENOSUCHPROCESSOR */
node.sysctl_size = sizeof(u_int64_t) * CPUSTATES;
n = name[0];
/*
* adjust these so that sysctl_lookup() will be happy
*/
name++;
namelen--;
break;
default:
return (EINVAL);
}
cp_time = malloc(node.sysctl_size, M_TEMP, M_WAITOK|M_CANFAIL);
if (cp_time == NULL)
return (ENOMEM);
node.sysctl_data = cp_time;
memset(cp_time, 0, node.sysctl_size);
for (CPU_INFO_FOREACH(cii, ci)) {
if (n <= 0)
for (i = 0; i < CPUSTATES; i++)
cp_time[i] += ci->ci_schedstate.spc_cp_time[i];
/*
* if a specific processor was requested and we just
* did it, we're done here
*/
if (n == 0)
break;
/*
* if doing "all", skip to next cp_time set for next processor
*/
if (n == -2)
cp_time += CPUSTATES;
/*
* if we're doing a specific processor, we're one
* processor closer
*/
if (n > 0)
n--;
}
error = sysctl_lookup(SYSCTLFN_CALL(&node));
free(node.sysctl_data, M_TEMP);
return (error);
#endif /* MULTIPROCESSOR */
}
#if defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM)
/*
* sysctl helper routine for kern.sysvipc_info subtree.
*/
#define FILL_PERM(src, dst) do { \
(dst)._key = (src)._key; \
(dst).uid = (src).uid; \
(dst).gid = (src).gid; \
(dst).cuid = (src).cuid; \
(dst).cgid = (src).cgid; \
(dst).mode = (src).mode; \
(dst)._seq = (src)._seq; \
} while (/*CONSTCOND*/ 0);
#define FILL_MSG(src, dst) do { \
FILL_PERM((src).msg_perm, (dst).msg_perm); \
(dst).msg_qnum = (src).msg_qnum; \
(dst).msg_qbytes = (src).msg_qbytes; \
(dst)._msg_cbytes = (src)._msg_cbytes; \
(dst).msg_lspid = (src).msg_lspid; \
(dst).msg_lrpid = (src).msg_lrpid; \
(dst).msg_stime = (src).msg_stime; \
(dst).msg_rtime = (src).msg_rtime; \
(dst).msg_ctime = (src).msg_ctime; \
} while (/*CONSTCOND*/ 0)
#define FILL_SEM(src, dst) do { \
FILL_PERM((src).sem_perm, (dst).sem_perm); \
(dst).sem_nsems = (src).sem_nsems; \
(dst).sem_otime = (src).sem_otime; \
(dst).sem_ctime = (src).sem_ctime; \
} while (/*CONSTCOND*/ 0)
#define FILL_SHM(src, dst) do { \
FILL_PERM((src).shm_perm, (dst).shm_perm); \
(dst).shm_segsz = (src).shm_segsz; \
(dst).shm_lpid = (src).shm_lpid; \
(dst).shm_cpid = (src).shm_cpid; \
(dst).shm_atime = (src).shm_atime; \
(dst).shm_dtime = (src).shm_dtime; \
(dst).shm_ctime = (src).shm_ctime; \
(dst).shm_nattch = (src).shm_nattch; \
} while (/*CONSTCOND*/ 0)
static int
sysctl_kern_sysvipc(SYSCTLFN_ARGS)
{
void *where = oldp;
size_t *sizep = oldlenp;
#ifdef SYSVMSG
struct msg_sysctl_info *msgsi = NULL;
#endif
#ifdef SYSVSEM
struct sem_sysctl_info *semsi = NULL;
#endif
#ifdef SYSVSHM
struct shm_sysctl_info *shmsi = NULL;
#endif
size_t infosize, dssize, tsize, buflen;
void *buf = NULL;
char *start;
int32_t nds;
int i, error, ret;
if (namelen != 1)
return (EINVAL);
start = where;
buflen = *sizep;
switch (*name) {
case KERN_SYSVIPC_MSG_INFO:
#ifdef SYSVMSG
infosize = sizeof(msgsi->msginfo);
nds = msginfo.msgmni;
dssize = sizeof(msgsi->msgids[0]);
break;
#else
return (EINVAL);
#endif
case KERN_SYSVIPC_SEM_INFO:
#ifdef SYSVSEM
infosize = sizeof(semsi->seminfo);
nds = seminfo.semmni;
dssize = sizeof(semsi->semids[0]);
break;
#else
return (EINVAL);
#endif
case KERN_SYSVIPC_SHM_INFO:
#ifdef SYSVSHM
infosize = sizeof(shmsi->shminfo);
nds = shminfo.shmmni;
dssize = sizeof(shmsi->shmids[0]);
break;
#else
return (EINVAL);
#endif
default:
return (EINVAL);
}
/*
* Round infosize to 64 bit boundary if requesting more than just
* the info structure or getting the total data size.
*/
if (where == NULL || *sizep > infosize)
infosize = ((infosize + 7) / 8) * 8;
tsize = infosize + nds * dssize;
/* Return just the total size required. */
if (where == NULL) {
*sizep = tsize;
return (0);
}
/* Not enough room for even the info struct. */
if (buflen < infosize) {
*sizep = 0;
return (ENOMEM);
}
buf = malloc(min(tsize, buflen), M_TEMP, M_WAITOK);
memset(buf, 0, min(tsize, buflen));
switch (*name) {
#ifdef SYSVMSG
case KERN_SYSVIPC_MSG_INFO:
msgsi = (struct msg_sysctl_info *)buf;
msgsi->msginfo = msginfo;
break;
#endif
#ifdef SYSVSEM
case KERN_SYSVIPC_SEM_INFO:
semsi = (struct sem_sysctl_info *)buf;
semsi->seminfo = seminfo;
break;
#endif
#ifdef SYSVSHM
case KERN_SYSVIPC_SHM_INFO:
shmsi = (struct shm_sysctl_info *)buf;
shmsi->shminfo = shminfo;
break;
#endif
}
buflen -= infosize;
ret = 0;
if (buflen > 0) {
/* Fill in the IPC data structures. */
for (i = 0; i < nds; i++) {
if (buflen < dssize) {
ret = ENOMEM;
break;
}
switch (*name) {
#ifdef SYSVMSG
case KERN_SYSVIPC_MSG_INFO:
FILL_MSG(msqids[i], msgsi->msgids[i]);
break;
#endif
#ifdef SYSVSEM
case KERN_SYSVIPC_SEM_INFO:
FILL_SEM(sema[i], semsi->semids[i]);
break;
#endif
#ifdef SYSVSHM
case KERN_SYSVIPC_SHM_INFO:
FILL_SHM(shmsegs[i], shmsi->shmids[i]);
break;
#endif
}
buflen -= dssize;
}
}
*sizep -= buflen;
error = copyout(buf, start, *sizep);
/* If copyout succeeded, use return code set earlier. */
if (error == 0)
error = ret;
if (buf)
free(buf, M_TEMP);
return (error);
}
#undef FILL_PERM
#undef FILL_MSG
#undef FILL_SEM
#undef FILL_SHM
#endif /* defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM) */
#if NPTY > 0
/*
* sysctl helper routine for kern.maxptys. ensures that any new value
* is acceptable to the pty subsystem.
*/
static int
sysctl_kern_maxptys(SYSCTLFN_ARGS)
{
int pty_maxptys(int, int); /* defined in kern/tty_pty.c */
int error, max;
struct sysctlnode node;
/* get current value of maxptys */
max = pty_maxptys(0, 0);
node = *rnode;
node.sysctl_data = &max;
error = sysctl_lookup(SYSCTLFN_CALL(&node));
if (error || newp == NULL)
return (error);
if (max != pty_maxptys(max, 1))
return (EINVAL);
return (0);
}
#endif /* NPTY > 0 */
/*
* sysctl helper routine for kern.sbmax. basically just ensures that
* any new value is not too small.
*/
static int
sysctl_kern_sbmax(SYSCTLFN_ARGS)
{
int error, new_sbmax;
struct sysctlnode node;
new_sbmax = sb_max;
node = *rnode;
node.sysctl_data = &new_sbmax;
error = sysctl_lookup(SYSCTLFN_CALL(&node));
if (error || newp == NULL)
return (error);
error = sb_max_set(new_sbmax);
return (error);
}
/*
* sysctl helper routine for kern.urandom node. picks a random number
* for you.
*/
static int
sysctl_kern_urnd(SYSCTLFN_ARGS)
{
#if NRND > 0
int v;
if (rnd_extract_data(&v, sizeof(v), RND_EXTRACT_ANY) == sizeof(v)) {
struct sysctlnode node = *rnode;
node.sysctl_data = &v;
return (sysctl_lookup(SYSCTLFN_CALL(&node)));
}
else
return (EIO); /*XXX*/
#else
return (EOPNOTSUPP);
#endif
}
/*
* sysctl helper routine to do kern.lwp.* work.
*/
static int
sysctl_kern_lwp(SYSCTLFN_ARGS)
{
struct kinfo_lwp klwp;
struct proc *p;
struct lwp *l2;
char *where, *dp;
int pid, elem_size, elem_count;
int buflen, needed, error;
if (namelen == 1 && name[0] == CTL_QUERY)
return (sysctl_query(SYSCTLFN_CALL(rnode)));
dp = where = oldp;
buflen = where != NULL ? *oldlenp : 0;
error = needed = 0;
if (newp != NULL || namelen != 3)
return (EINVAL);
pid = name[0];
elem_size = name[1];
elem_count = name[2];
p = pfind(pid);
if (p == NULL)
return (ESRCH);
LIST_FOREACH(l2, &p->p_lwps, l_sibling) {
if (buflen >= elem_size && elem_count > 0) {
fill_lwp(l2, &klwp);
/*
* Copy out elem_size, but not larger than
* the size of a struct kinfo_proc2.
*/
error = copyout(&klwp, dp,
min(sizeof(klwp), elem_size));
if (error)
goto cleanup;
dp += elem_size;
buflen -= elem_size;
elem_count--;
}
needed += elem_size;
}
if (where != NULL) {
*oldlenp = dp - where;
if (needed > *oldlenp)
return (ENOMEM);
} else {
needed += KERN_PROCSLOP;
*oldlenp = needed;
}
return (0);
cleanup:
return (error);
}
/*
* sysctl helper routine for kern.forkfsleep node. ensures that the
* given value is not too large or two small, and is at least one
* timer tick if not zero.
*/
static int
sysctl_kern_forkfsleep(SYSCTLFN_ARGS)
{
/* userland sees value in ms, internally is in ticks */
extern int forkfsleep; /* defined in kern/kern_fork.c */
int error, timo, lsleep;
struct sysctlnode node;
lsleep = forkfsleep * 1000 / hz;
node = *rnode;
node.sysctl_data = &lsleep;
error = sysctl_lookup(SYSCTLFN_CALL(&node));
if (error || newp == NULL)
return (error);
/* refuse negative values, and overly 'long time' */
if (lsleep < 0 || lsleep > MAXSLP * 1000)
return (EINVAL);
timo = mstohz(lsleep);
/* if the interval is >0 ms && <1 tick, use 1 tick */
if (lsleep != 0 && timo == 0)
forkfsleep = 1;
else
forkfsleep = timo;
return (0);
}
/*
* sysctl helper routine for kern.somaxkva. ensures that the given
* value is not too small.
* (XXX should we maybe make sure it's not too large as well?)
*/
static int
sysctl_kern_somaxkva(SYSCTLFN_ARGS)
{
int error, new_somaxkva;
struct sysctlnode node;
new_somaxkva = somaxkva;
node = *rnode;
node.sysctl_data = &new_somaxkva;
error = sysctl_lookup(SYSCTLFN_CALL(&node));
if (error || newp == NULL)
return (error);
if (new_somaxkva < (16 * 1024 * 1024)) /* sanity */
return (EINVAL);
somaxkva = new_somaxkva;
return (error);
}
/*
* sysctl helper routine for kern.root_partition
*/
static int
sysctl_kern_root_partition(SYSCTLFN_ARGS)
{
int rootpart = DISKPART(rootdev);
struct sysctlnode node = *rnode;
node.sysctl_data = &rootpart;
return (sysctl_lookup(SYSCTLFN_CALL(&node)));
}
/*
* sysctl helper function for kern.drivers
*/
static int
sysctl_kern_drivers(SYSCTLFN_ARGS)
{
int error;
size_t buflen;
struct kinfo_drivers kd;
char *start, *where;
const char *dname;
int i;
extern struct devsw_conv *devsw_conv;
extern int max_devsw_convs;
if (newp != NULL || namelen != 0)
return (EINVAL);
start = where = oldp;
buflen = *oldlenp;
if (where == NULL) {
*oldlenp = max_devsw_convs * sizeof kd;
return 0;
}
/*
* An array of kinfo_drivers structures
*/
error = 0;
for (i = 0; i < max_devsw_convs; i++) {
dname = devsw_conv[i].d_name;
if (dname == NULL)
continue;
if (buflen < sizeof kd) {
error = ENOMEM;
break;
}
kd.d_bmajor = devsw_conv[i].d_bmajor;
kd.d_cmajor = devsw_conv[i].d_cmajor;
strlcpy(kd.d_name, dname, sizeof kd.d_name);
error = copyout(&kd, where, sizeof kd);
if (error != 0)
break;
buflen -= sizeof kd;
where += sizeof kd;
}
*oldlenp = where - start;
return error;
}
static int
sysctl_doeproc(SYSCTLFN_ARGS)
{
struct eproc eproc;
struct kinfo_proc2 kproc2;
struct kinfo_proc *dp;
struct proc *p;
const struct proclist_desc *pd;
char *where, *dp2;
int type, op, arg;
u_int elem_size, elem_count;
size_t buflen, needed;
int error;
if (namelen == 1 && name[0] == CTL_QUERY)
return (sysctl_query(SYSCTLFN_CALL(rnode)));
dp = oldp;
dp2 = where = oldp;
buflen = where != NULL ? *oldlenp : 0;
error = 0;
needed = 0;
type = rnode->sysctl_num;
if (type == KERN_PROC) {
if (namelen != 2 && !(namelen == 1 && name[0] == KERN_PROC_ALL))
return (EINVAL);
op = name[0];
if (op != KERN_PROC_ALL)
arg = name[1];
else
arg = 0; /* Quell compiler warning */
elem_size = elem_count = 0; /* Ditto */
} else {
if (namelen != 4)
return (EINVAL);
op = name[0];
arg = name[1];
elem_size = name[2];
elem_count = name[3];
}
proclist_lock_read();
pd = proclists;
again:
for (p = LIST_FIRST(pd->pd_list); p != NULL; p = LIST_NEXT(p, p_list)) {
/*
* Skip embryonic processes.
*/
if (p->p_stat == SIDL)
continue;
/*
* TODO - make more efficient (see notes below).
* do by session.
*/
switch (op) {
case KERN_PROC_PID:
/* could do this with just a lookup */
if (p->p_pid != (pid_t)arg)
continue;
break;
case KERN_PROC_PGRP:
/* could do this by traversing pgrp */
if (p->p_pgrp->pg_id != (pid_t)arg)
continue;
break;
case KERN_PROC_SESSION:
if (p->p_session->s_sid != (pid_t)arg)
continue;
break;
case KERN_PROC_TTY:
if (arg == (int) KERN_PROC_TTY_REVOKE) {
if ((p->p_flag & P_CONTROLT) == 0 ||
p->p_session->s_ttyp == NULL ||
p->p_session->s_ttyvp != NULL)
continue;
} else if ((p->p_flag & P_CONTROLT) == 0 ||
p->p_session->s_ttyp == NULL) {
if ((dev_t)arg != KERN_PROC_TTY_NODEV)
continue;
} else if (p->p_session->s_ttyp->t_dev != (dev_t)arg)
continue;
break;
case KERN_PROC_UID:
if (p->p_ucred->cr_uid != (uid_t)arg)
continue;
break;
case KERN_PROC_RUID:
if (p->p_cred->p_ruid != (uid_t)arg)
continue;
break;
case KERN_PROC_GID:
if (p->p_ucred->cr_gid != (uid_t)arg)
continue;
break;
case KERN_PROC_RGID:
if (p->p_cred->p_rgid != (uid_t)arg)
continue;
break;
case KERN_PROC_ALL:
/* allow everything */
break;
default:
error = EINVAL;
goto cleanup;
}
if (type == KERN_PROC) {
if (buflen >= sizeof(struct kinfo_proc)) {
fill_eproc(p, &eproc);
error = copyout(p, &dp->kp_proc,
sizeof(struct proc));
if (error)
goto cleanup;
error = copyout(&eproc, &dp->kp_eproc,
sizeof(eproc));
if (error)
goto cleanup;
dp++;
buflen -= sizeof(struct kinfo_proc);
}
needed += sizeof(struct kinfo_proc);
} else { /* KERN_PROC2 */
if (buflen >= elem_size && elem_count > 0) {
fill_kproc2(p, &kproc2);
/*
* Copy out elem_size, but not larger than
* the size of a struct kinfo_proc2.
*/
error = copyout(&kproc2, dp2,
min(sizeof(kproc2), elem_size));
if (error)
goto cleanup;
dp2 += elem_size;
buflen -= elem_size;
elem_count--;
}
needed += elem_size;
}
}
pd++;
if (pd->pd_list != NULL)
goto again;
proclist_unlock_read();
if (where != NULL) {
if (type == KERN_PROC)
*oldlenp = (char *)dp - where;
else
*oldlenp = dp2 - where;
if (needed > *oldlenp)
return (ENOMEM);
} else {
needed += KERN_LWPSLOP;
*oldlenp = needed;
}
return (0);
cleanup:
proclist_unlock_read();
return (error);
}
/*
* sysctl helper routine for kern.proc_args pseudo-subtree.
*/
static int
sysctl_kern_proc_args(SYSCTLFN_ARGS)
{
struct ps_strings pss;
struct proc *p, *up = l->l_proc;
size_t len, upper_bound, xlen, i;
struct uio auio;
struct iovec aiov;
vaddr_t argv;
pid_t pid;
int nargv, type, error;
char *arg;
char *tmp;
if (namelen == 1 && name[0] == CTL_QUERY)
return (sysctl_query(SYSCTLFN_CALL(rnode)));
if (newp != NULL || namelen != 2)
return (EINVAL);
pid = name[0];
type = name[1];
switch (type) {
case KERN_PROC_ARGV:
case KERN_PROC_NARGV:
case KERN_PROC_ENV:
case KERN_PROC_NENV:
/* ok */
break;
default:
return (EINVAL);
}
/* check pid */
if ((p = pfind(pid)) == NULL)
return (EINVAL);
/* only root or same user change look at the environment */
if (type == KERN_PROC_ENV || type == KERN_PROC_NENV) {
if (up->p_ucred->cr_uid != 0) {
if (up->p_cred->p_ruid != p->p_cred->p_ruid ||
up->p_cred->p_ruid != p->p_cred->p_svuid)
return (EPERM);
}
}
if (oldp == NULL) {
if (type == KERN_PROC_NARGV || type == KERN_PROC_NENV)
*oldlenp = sizeof (int);
else
*oldlenp = ARG_MAX; /* XXX XXX XXX */
return (0);
}
/*
* Zombies don't have a stack, so we can't read their psstrings.
* System processes also don't have a user stack.
*/
if (P_ZOMBIE(p) || (p->p_flag & P_SYSTEM) != 0)
return (EINVAL);
/*
* Lock the process down in memory.
*/
/* XXXCDC: how should locking work here? */
if ((p->p_flag & P_WEXIT) || (p->p_vmspace->vm_refcnt < 1))
return (EFAULT);
p->p_vmspace->vm_refcnt++; /* XXX */
/*
* Allocate a temporary buffer to hold the arguments.
*/
arg = malloc(PAGE_SIZE, M_TEMP, M_WAITOK);
/*
* Read in the ps_strings structure.
*/
aiov.iov_base = &pss;
aiov.iov_len = sizeof(pss);
auio.uio_iov = &aiov;
auio.uio_iovcnt = 1;
auio.uio_offset = (vaddr_t)p->p_psstr;
auio.uio_resid = sizeof(pss);
auio.uio_segflg = UIO_SYSSPACE;
auio.uio_rw = UIO_READ;
auio.uio_procp = NULL;
error = uvm_io(&p->p_vmspace->vm_map, &auio);
if (error)
goto done;
if (type == KERN_PROC_ARGV || type == KERN_PROC_NARGV)
memcpy(&nargv, (char *)&pss + p->p_psnargv, sizeof(nargv));
else
memcpy(&nargv, (char *)&pss + p->p_psnenv, sizeof(nargv));
if (type == KERN_PROC_NARGV || type == KERN_PROC_NENV) {
error = copyout(&nargv, oldp, sizeof(nargv));
*oldlenp = sizeof(nargv);
goto done;
}
/*
* Now read the address of the argument vector.
*/
switch (type) {
case KERN_PROC_ARGV:
/* XXX compat32 stuff here */
memcpy(&tmp, (char *)&pss + p->p_psargv, sizeof(tmp));
break;
case KERN_PROC_ENV:
memcpy(&tmp, (char *)&pss + p->p_psenv, sizeof(tmp));
break;
default:
return (EINVAL);
}
auio.uio_offset = (off_t)(long)tmp;
aiov.iov_base = &argv;
aiov.iov_len = sizeof(argv);
auio.uio_iov = &aiov;
auio.uio_iovcnt = 1;
auio.uio_resid = sizeof(argv);
auio.uio_segflg = UIO_SYSSPACE;
auio.uio_rw = UIO_READ;
auio.uio_procp = NULL;
error = uvm_io(&p->p_vmspace->vm_map, &auio);
if (error)
goto done;
/*
* Now copy in the actual argument vector, one page at a time,
* since we don't know how long the vector is (though, we do
* know how many NUL-terminated strings are in the vector).
*/
len = 0;
upper_bound = *oldlenp;
for (; nargv != 0 && len < upper_bound; len += xlen) {
aiov.iov_base = arg;
aiov.iov_len = PAGE_SIZE;
auio.uio_iov = &aiov;
auio.uio_iovcnt = 1;
auio.uio_offset = argv + len;
xlen = PAGE_SIZE - ((argv + len) & PAGE_MASK);
auio.uio_resid = xlen;
auio.uio_segflg = UIO_SYSSPACE;
auio.uio_rw = UIO_READ;
auio.uio_procp = NULL;
error = uvm_io(&p->p_vmspace->vm_map, &auio);
if (error)
goto done;
for (i = 0; i < xlen && nargv != 0; i++) {
if (arg[i] == '\0')
nargv--; /* one full string */
}
/*
* Make sure we don't copyout past the end of the user's
* buffer.
*/
if (len + i > upper_bound)
i = upper_bound - len;
error = copyout(arg, (char *)oldp + len, i);
if (error)
break;
if (nargv == 0) {
len += i;
break;
}
}
*oldlenp = len;
done:
uvmspace_free(p->p_vmspace);
free(arg, M_TEMP);
return (error);
}
/*
* sysctl helper routine for hw.usermem and hw.usermem64. values are
* calculate on the fly taking into account integer overflow and the
* current wired count.
*/
static int
sysctl_hw_usermem(SYSCTLFN_ARGS)
{
u_int ui;
u_quad_t uq;
struct sysctlnode node;
node = *rnode;
switch (rnode->sysctl_num) {
case HW_USERMEM:
if ((ui = physmem - uvmexp.wired) > (UINT_MAX / PAGE_SIZE))
ui = UINT_MAX;
else
ui *= PAGE_SIZE;
node.sysctl_data = &ui;
break;
case HW_USERMEM64:
uq = (u_quad_t)(physmem - uvmexp.wired) * PAGE_SIZE;
node.sysctl_data = &uq;
break;
default:
return (EINVAL);
}
return (sysctl_lookup(SYSCTLFN_CALL(&node)));
}
/*
* sysctl helper routine for kern.cnmagic node. pulls the old value
* out, encoded, and stuffs the new value in for decoding.
*/
static int
sysctl_hw_cnmagic(SYSCTLFN_ARGS)
{
char magic[CNS_LEN];
int error;
struct sysctlnode node;
if (oldp)
cn_get_magic(magic, CNS_LEN);
node = *rnode;
node.sysctl_data = &magic[0];
error = sysctl_lookup(SYSCTLFN_CALL(&node));
if (error || newp == NULL)
return (error);
return (cn_set_magic(magic));
}
static int
sysctl_hw_ncpu(SYSCTLFN_ARGS)
{
int ncpu;
struct sysctlnode node;
ncpu = sysctl_ncpus();
node = *rnode;
node.sysctl_data = &ncpu;
return (sysctl_lookup(SYSCTLFN_CALL(&node)));
}
/*
* ********************************************************************
* section 3: public helper routines that are used for more than one
* node
* ********************************************************************
*/
/*
* sysctl helper routine for the kern.root_device node and some ports'
* machdep.root_device nodes.
*/
int
sysctl_root_device(SYSCTLFN_ARGS)
{
struct sysctlnode node;
node = *rnode;
node.sysctl_data = root_device->dv_xname;
node.sysctl_size = strlen(root_device->dv_xname) + 1;
return (sysctl_lookup(SYSCTLFN_CALL(&node)));
}
/*
* sysctl helper routine for kern.consdev, dependent on the current
* state of the console. also used for machdep.console_device on some
* ports.
*/
int
sysctl_consdev(SYSCTLFN_ARGS)
{
dev_t consdev;
struct sysctlnode node;
if (cn_tab != NULL)
consdev = cn_tab->cn_dev;
else
consdev = NODEV;
node = *rnode;
node.sysctl_data = &consdev;
node.sysctl_size = sizeof(consdev);
return (sysctl_lookup(SYSCTLFN_CALL(&node)));
}
/*
* ********************************************************************
* section 4: support for some helpers
* ********************************************************************
*/
/*
* Fill in a kinfo_proc2 structure for the specified process.
*/
static void
fill_kproc2(struct proc *p, struct kinfo_proc2 *ki)
{
struct tty *tp;
struct lwp *l;
struct timeval ut, st;
memset(ki, 0, sizeof(*ki));
ki->p_paddr = PTRTOINT64(p);
ki->p_fd = PTRTOINT64(p->p_fd);
ki->p_cwdi = PTRTOINT64(p->p_cwdi);
ki->p_stats = PTRTOINT64(p->p_stats);
ki->p_limit = PTRTOINT64(p->p_limit);
ki->p_vmspace = PTRTOINT64(p->p_vmspace);
ki->p_sigacts = PTRTOINT64(p->p_sigacts);
ki->p_sess = PTRTOINT64(p->p_session);
ki->p_tsess = 0; /* may be changed if controlling tty below */
ki->p_ru = PTRTOINT64(p->p_ru);
ki->p_eflag = 0;
ki->p_exitsig = p->p_exitsig;
ki->p_flag = p->p_flag;
ki->p_pid = p->p_pid;
if (p->p_pptr)
ki->p_ppid = p->p_pptr->p_pid;
else
ki->p_ppid = 0;
ki->p_sid = p->p_session->s_sid;
ki->p__pgid = p->p_pgrp->pg_id;
ki->p_tpgid = NO_PGID; /* may be changed if controlling tty below */
ki->p_uid = p->p_ucred->cr_uid;
ki->p_ruid = p->p_cred->p_ruid;
ki->p_gid = p->p_ucred->cr_gid;
ki->p_rgid = p->p_cred->p_rgid;
ki->p_svuid = p->p_cred->p_svuid;
ki->p_svgid = p->p_cred->p_svgid;
memcpy(ki->p_groups, p->p_cred->pc_ucred->cr_groups,
min(sizeof(ki->p_groups), sizeof(p->p_cred->pc_ucred->cr_groups)));
ki->p_ngroups = p->p_cred->pc_ucred->cr_ngroups;
ki->p_jobc = p->p_pgrp->pg_jobc;
if ((p->p_flag & P_CONTROLT) && (tp = p->p_session->s_ttyp)) {
ki->p_tdev = tp->t_dev;
ki->p_tpgid = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PGID;
ki->p_tsess = PTRTOINT64(tp->t_session);
} else {
ki->p_tdev = NODEV;
}
ki->p_estcpu = p->p_estcpu;
ki->p_rtime_sec = p->p_rtime.tv_sec;
ki->p_rtime_usec = p->p_rtime.tv_usec;
ki->p_cpticks = p->p_cpticks;
ki->p_pctcpu = p->p_pctcpu;
ki->p_uticks = p->p_uticks;
ki->p_sticks = p->p_sticks;
ki->p_iticks = p->p_iticks;
ki->p_tracep = PTRTOINT64(p->p_tracep);
ki->p_traceflag = p->p_traceflag;
memcpy(&ki->p_siglist, &p->p_sigctx.ps_siglist, sizeof(ki_sigset_t));
memcpy(&ki->p_sigmask, &p->p_sigctx.ps_sigmask, sizeof(ki_sigset_t));
memcpy(&ki->p_sigignore, &p->p_sigctx.ps_sigignore,sizeof(ki_sigset_t));
memcpy(&ki->p_sigcatch, &p->p_sigctx.ps_sigcatch, sizeof(ki_sigset_t));
ki->p_stat = p->p_stat; /* Will likely be overridden by LWP status */
ki->p_realstat = p->p_stat;
ki->p_nice = p->p_nice;
ki->p_xstat = p->p_xstat;
ki->p_acflag = p->p_acflag;
strncpy(ki->p_comm, p->p_comm,
min(sizeof(ki->p_comm), sizeof(p->p_comm)));
strncpy(ki->p_login, p->p_session->s_login,
min(sizeof ki->p_login - 1, sizeof p->p_session->s_login));
ki->p_nlwps = p->p_nlwps;
ki->p_nrlwps = p->p_nrlwps;
ki->p_realflag = p->p_flag;
if (p->p_stat == SIDL || P_ZOMBIE(p)) {
ki->p_vm_rssize = 0;
ki->p_vm_tsize = 0;
ki->p_vm_dsize = 0;
ki->p_vm_ssize = 0;
l = NULL;
} else {
struct vmspace *vm = p->p_vmspace;
ki->p_vm_rssize = vm_resident_count(vm);
ki->p_vm_tsize = vm->vm_tsize;
ki->p_vm_dsize = vm->vm_dsize;
ki->p_vm_ssize = vm->vm_ssize;
/* Pick a "representative" LWP */
l = proc_representative_lwp(p);
ki->p_forw = PTRTOINT64(l->l_forw);
ki->p_back = PTRTOINT64(l->l_back);
ki->p_addr = PTRTOINT64(l->l_addr);
ki->p_stat = l->l_stat;
ki->p_flag |= l->l_flag;
ki->p_swtime = l->l_swtime;
ki->p_slptime = l->l_slptime;
if (l->l_stat == LSONPROC) {
KDASSERT(l->l_cpu != NULL);
ki->p_schedflags = l->l_cpu->ci_schedstate.spc_flags;
} else
ki->p_schedflags = 0;
ki->p_holdcnt = l->l_holdcnt;
ki->p_priority = l->l_priority;
ki->p_usrpri = l->l_usrpri;
if (l->l_wmesg)
strncpy(ki->p_wmesg, l->l_wmesg, sizeof(ki->p_wmesg));
ki->p_wchan = PTRTOINT64(l->l_wchan);
}
if (p->p_session->s_ttyvp)
ki->p_eflag |= EPROC_CTTY;
if (SESS_LEADER(p))
ki->p_eflag |= EPROC_SLEADER;
/* XXX Is this double check necessary? */
if (P_ZOMBIE(p)) {
ki->p_uvalid = 0;
} else {
ki->p_uvalid = 1;
ki->p_ustart_sec = p->p_stats->p_start.tv_sec;
ki->p_ustart_usec = p->p_stats->p_start.tv_usec;
calcru(p, &ut, &st, 0);
ki->p_uutime_sec = ut.tv_sec;
ki->p_uutime_usec = ut.tv_usec;
ki->p_ustime_sec = st.tv_sec;
ki->p_ustime_usec = st.tv_usec;
ki->p_uru_maxrss = p->p_stats->p_ru.ru_maxrss;
ki->p_uru_ixrss = p->p_stats->p_ru.ru_ixrss;
ki->p_uru_idrss = p->p_stats->p_ru.ru_idrss;
ki->p_uru_isrss = p->p_stats->p_ru.ru_isrss;
ki->p_uru_minflt = p->p_stats->p_ru.ru_minflt;
ki->p_uru_majflt = p->p_stats->p_ru.ru_majflt;
ki->p_uru_nswap = p->p_stats->p_ru.ru_nswap;
ki->p_uru_inblock = p->p_stats->p_ru.ru_inblock;
ki->p_uru_oublock = p->p_stats->p_ru.ru_oublock;
ki->p_uru_msgsnd = p->p_stats->p_ru.ru_msgsnd;
ki->p_uru_msgrcv = p->p_stats->p_ru.ru_msgrcv;
ki->p_uru_nsignals = p->p_stats->p_ru.ru_nsignals;
ki->p_uru_nvcsw = p->p_stats->p_ru.ru_nvcsw;
ki->p_uru_nivcsw = p->p_stats->p_ru.ru_nivcsw;
timeradd(&p->p_stats->p_cru.ru_utime,
&p->p_stats->p_cru.ru_stime, &ut);
ki->p_uctime_sec = ut.tv_sec;
ki->p_uctime_usec = ut.tv_usec;
}
#ifdef MULTIPROCESSOR
if (l && l->l_cpu != NULL)
ki->p_cpuid = l->l_cpu->ci_cpuid;
else
#endif
ki->p_cpuid = KI_NOCPU;
}
/*
* Fill in a kinfo_lwp structure for the specified lwp.
*/
static void
fill_lwp(struct lwp *l, struct kinfo_lwp *kl)
{
kl->l_forw = PTRTOINT64(l->l_forw);
kl->l_back = PTRTOINT64(l->l_back);
kl->l_laddr = PTRTOINT64(l);
kl->l_addr = PTRTOINT64(l->l_addr);
kl->l_stat = l->l_stat;
kl->l_lid = l->l_lid;
kl->l_flag = l->l_flag;
kl->l_swtime = l->l_swtime;
kl->l_slptime = l->l_slptime;
if (l->l_stat == LSONPROC) {
KDASSERT(l->l_cpu != NULL);
kl->l_schedflags = l->l_cpu->ci_schedstate.spc_flags;
} else
kl->l_schedflags = 0;
kl->l_holdcnt = l->l_holdcnt;
kl->l_priority = l->l_priority;
kl->l_usrpri = l->l_usrpri;
if (l->l_wmesg)
strncpy(kl->l_wmesg, l->l_wmesg, sizeof(kl->l_wmesg));
kl->l_wchan = PTRTOINT64(l->l_wchan);
#ifdef MULTIPROCESSOR
if (l->l_cpu != NULL)
kl->l_cpuid = l->l_cpu->ci_cpuid;
else
#endif
kl->l_cpuid = KI_NOCPU;
}
/*
* Fill in an eproc structure for the specified process.
*/
void
fill_eproc(struct proc *p, struct eproc *ep)
{
struct tty *tp;
struct lwp *l;
ep->e_paddr = p;
ep->e_sess = p->p_session;
ep->e_pcred = *p->p_cred;
ep->e_ucred = *p->p_ucred;
if (p->p_stat == SIDL || P_ZOMBIE(p)) {
ep->e_vm.vm_rssize = 0;
ep->e_vm.vm_tsize = 0;
ep->e_vm.vm_dsize = 0;
ep->e_vm.vm_ssize = 0;
/* ep->e_vm.vm_pmap = XXX; */
} else {
struct vmspace *vm = p->p_vmspace;
ep->e_vm.vm_rssize = vm_resident_count(vm);
ep->e_vm.vm_tsize = vm->vm_tsize;
ep->e_vm.vm_dsize = vm->vm_dsize;
ep->e_vm.vm_ssize = vm->vm_ssize;
/* Pick a "representative" LWP */
l = proc_representative_lwp(p);
if (l->l_wmesg)
strncpy(ep->e_wmesg, l->l_wmesg, WMESGLEN);
}
if (p->p_pptr)
ep->e_ppid = p->p_pptr->p_pid;
else
ep->e_ppid = 0;
ep->e_pgid = p->p_pgrp->pg_id;
ep->e_sid = ep->e_sess->s_sid;
ep->e_jobc = p->p_pgrp->pg_jobc;
if ((p->p_flag & P_CONTROLT) &&
(tp = ep->e_sess->s_ttyp)) {
ep->e_tdev = tp->t_dev;
ep->e_tpgid = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PGID;
ep->e_tsess = tp->t_session;
} else
ep->e_tdev = NODEV;
ep->e_xsize = ep->e_xrssize = 0;
ep->e_xccount = ep->e_xswrss = 0;
ep->e_flag = ep->e_sess->s_ttyvp ? EPROC_CTTY : 0;
if (SESS_LEADER(p))
ep->e_flag |= EPROC_SLEADER;
strncpy(ep->e_login, ep->e_sess->s_login, MAXLOGNAME);
}
|