| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | .\" $NetBSD: sysctl.9,v 1.17 2010/05/16 05:18:35 jruoho Exp $ | | 1 | .\" $NetBSD: sysctl.9,v 1.18 2011/12/04 18:34:20 jym Exp $ |
2 | .\" | | 2 | .\" |
3 | .\" Copyright (c) 2004 The NetBSD Foundation, Inc. | | 3 | .\" Copyright (c) 2004 The NetBSD Foundation, Inc. |
4 | .\" All rights reserved. | | 4 | .\" All rights reserved. |
5 | .\" | | 5 | .\" |
6 | .\" This code is derived from software contributed to The NetBSD Foundation | | 6 | .\" This code is derived from software contributed to The NetBSD Foundation |
7 | .\" by Andrew Brown. | | 7 | .\" by Andrew Brown. |
8 | .\" | | 8 | .\" |
9 | .\" Redistribution and use in source and binary forms, with or without | | 9 | .\" Redistribution and use in source and binary forms, with or without |
10 | .\" modification, are permitted provided that the following conditions | | 10 | .\" modification, are permitted provided that the following conditions |
11 | .\" are met: | | 11 | .\" are met: |
12 | .\" 1. Redistributions of source code must retain the above copyright | | 12 | .\" 1. Redistributions of source code must retain the above copyright |
13 | .\" notice, this list of conditions and the following disclaimer. | | 13 | .\" notice, this list of conditions and the following disclaimer. |
14 | .\" 2. Redistributions in binary form must reproduce the above copyright | | 14 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| @@ -17,27 +17,27 @@ | | | @@ -17,27 +17,27 @@ |
17 | .\" | | 17 | .\" |
18 | .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | | 18 | .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
19 | .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 19 | .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
20 | .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 20 | .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
21 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 21 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
22 | .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 22 | .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
23 | .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 23 | .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
24 | .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 24 | .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
25 | .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 25 | .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
26 | .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 26 | .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
27 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 27 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
28 | .\" POSSIBILITY OF SUCH DAMAGE. | | 28 | .\" POSSIBILITY OF SUCH DAMAGE. |
29 | .\" | | 29 | .\" |
30 | .Dd May 16, 2010 | | 30 | .Dd December 4, 2011 |
31 | .Dt SYSCTL 9 | | 31 | .Dt SYSCTL 9 |
32 | .Os | | 32 | .Os |
33 | .Sh NAME | | 33 | .Sh NAME |
34 | .Nm sysctl | | 34 | .Nm sysctl |
35 | .Nd system variable control interfaces | | 35 | .Nd system variable control interfaces |
36 | .Sh SYNOPSIS | | 36 | .Sh SYNOPSIS |
37 | .In sys/param.h | | 37 | .In sys/param.h |
38 | .In sys/sysctl.h | | 38 | .In sys/sysctl.h |
39 | .Pp | | 39 | .Pp |
40 | Primary external interfaces: | | 40 | Primary external interfaces: |
41 | .Ft void | | 41 | .Ft void |
42 | .Fn sysctl_init void | | 42 | .Fn sysctl_init void |
43 | .Ft int | | 43 | .Ft int |
| @@ -411,26 +411,27 @@ flag. | | | @@ -411,26 +411,27 @@ flag. |
411 | .El | | 411 | .El |
412 | .Pp | | 412 | .Pp |
413 | The | | 413 | The |
414 | .Fa func | | 414 | .Fa func |
415 | argument is the name of a | | 415 | argument is the name of a |
416 | .Dq helper | | 416 | .Dq helper |
417 | function (see | | 417 | function (see |
418 | .Sx HELPER FUNCTIONS AND MACROS ) . | | 418 | .Sx HELPER FUNCTIONS AND MACROS ) . |
419 | If the | | 419 | If the |
420 | .Dv CTLFLAG_IMMEDIATE | | 420 | .Dv CTLFLAG_IMMEDIATE |
421 | flag is set, the | | 421 | flag is set, the |
422 | .Fa qv | | 422 | .Fa qv |
423 | argument will be interpreted as the initial value for the new | | 423 | argument will be interpreted as the initial value for the new |
| | | 424 | .Dq bool , |
424 | .Dq int | | 425 | .Dq int |
425 | or | | 426 | or |
426 | .Dq quad | | 427 | .Dq quad |
427 | node. | | 428 | node. |
428 | This flag does not apply to any other type of node. | | 429 | This flag does not apply to any other type of node. |
429 | The | | 430 | The |
430 | .Fa newp | | 431 | .Fa newp |
431 | and | | 432 | and |
432 | .Fa newlen | | 433 | .Fa newlen |
433 | arguments describe the data external to SYSCTL that is to be | | 434 | arguments describe the data external to SYSCTL that is to be |
434 | instrumented. | | 435 | instrumented. |
435 | One of | | 436 | One of |
436 | .Fa func , | | 437 | .Fa func , |
| @@ -494,36 +495,38 @@ The | | | @@ -494,36 +495,38 @@ The |
494 | prototype and function that needs to ensure that a newly assigned | | 495 | prototype and function that needs to ensure that a newly assigned |
495 | value is within a certain range (presuming external data) would look | | 496 | value is within a certain range (presuming external data) would look |
496 | like the following: | | 497 | like the following: |
497 | .Pp | | 498 | .Pp |
498 | .Bd -literal -offset indent -compact | | 499 | .Bd -literal -offset indent -compact |
499 | static int sysctl_helper(SYSCTLFN_PROTO); | | 500 | static int sysctl_helper(SYSCTLFN_PROTO); |
500 | | | 501 | |
501 | static int | | 502 | static int |
502 | sysctl_helper(SYSCTLFN_ARGS) | | 503 | sysctl_helper(SYSCTLFN_ARGS) |
503 | { | | 504 | { |
504 | struct sysctlnode node; | | 505 | struct sysctlnode node; |
505 | int t, error; | | 506 | int t, error; |
506 | | | 507 | |
| | | 508 | t = *(int *)rnode-\*[Gt]sysctl_data; |
| | | 509 | |
507 | node = *rnode; | | 510 | node = *rnode; |
508 | node.sysctl_data = \*[Am]t; | | 511 | node.sysctl_data = \*[Am]t; |
509 | error = sysctl_lookup(SYSCTLFN_CALL(\*[Am]node)); | | 512 | error = sysctl_lookup(SYSCTLFN_CALL(\*[Am]node)); |
510 | if (error || newp == NULL) | | 513 | if (error || newp == NULL) |
511 | return (error); | | 514 | return (error); |
512 | | | 515 | |
513 | if (t \*[Lt] 0 || t \*[Gt] 20) | | 516 | if (t \*[Lt] 0 || t \*[Gt] 20) |
514 | return (EINVAL); | | 517 | return (EINVAL); |
515 | | | 518 | |
516 | *(int*)rnode-\*[Gt]sysctl_data = t; | | 519 | *(int *)rnode-\*[Gt]sysctl_data = t; |
517 | return (0); | | 520 | return (0); |
518 | } | | 521 | } |
519 | .Ed | | 522 | .Ed |
520 | .Pp | | 523 | .Pp |
521 | The use of the | | 524 | The use of the |
522 | .Dv SYSCTLFN_PROTO , | | 525 | .Dv SYSCTLFN_PROTO , |
523 | .Dv SYSCTLFN_ARGS, and | | 526 | .Dv SYSCTLFN_ARGS, and |
524 | .Dv SYSCTLFN_CALL | | 527 | .Dv SYSCTLFN_CALL |
525 | macros ensure that all arguments are passed properly. | | 528 | macros ensure that all arguments are passed properly. |
526 | The single argument to the | | 529 | The single argument to the |
527 | .Dv SYSCTLFN_CALL | | 530 | .Dv SYSCTLFN_CALL |
528 | macro is the pointer to the node being examined. | | 531 | macro is the pointer to the node being examined. |
529 | .Pp | | 532 | .Pp |