Sun Dec 4 18:34:20 2011 UTC ()
- add the bool type for IMMEDIATE flag.
- minor tweak to the handler example: it leaks 't' (on stack)
  when passed to sysctl_lookup(9), as it copyout its content via
  sysctl_data. That would not be the case if CTLFLAG_IMMEDIATE flag
  was set for this node but the example does not preclude that.


(jym)
diff -r1.17 -r1.18 src/share/man/man9/sysctl.9

cvs diff -r1.17 -r1.18 src/share/man/man9/sysctl.9 (expand / switch to unified diff)

--- src/share/man/man9/sysctl.9 2010/05/16 05:18:35 1.17
+++ src/share/man/man9/sysctl.9 2011/12/04 18:34:20 1.18
@@ -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
40Primary external interfaces: 40Primary 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
413The 413The
414.Fa func 414.Fa func
415argument is the name of a 415argument is the name of a
416.Dq helper 416.Dq helper
417function (see 417function (see
418.Sx HELPER FUNCTIONS AND MACROS ) . 418.Sx HELPER FUNCTIONS AND MACROS ) .
419If the 419If the
420.Dv CTLFLAG_IMMEDIATE 420.Dv CTLFLAG_IMMEDIATE
421flag is set, the 421flag is set, the
422.Fa qv 422.Fa qv
423argument will be interpreted as the initial value for the new 423argument will be interpreted as the initial value for the new
 424.Dq bool ,
424.Dq int 425.Dq int
425or 426or
426.Dq quad 427.Dq quad
427node. 428node.
428This flag does not apply to any other type of node. 429This flag does not apply to any other type of node.
429The 430The
430.Fa newp 431.Fa newp
431and 432and
432.Fa newlen 433.Fa newlen
433arguments describe the data external to SYSCTL that is to be 434arguments describe the data external to SYSCTL that is to be
434instrumented. 435instrumented.
435One of 436One of
436.Fa func , 437.Fa func ,
@@ -494,36 +495,38 @@ The @@ -494,36 +495,38 @@ The
494prototype and function that needs to ensure that a newly assigned 495prototype and function that needs to ensure that a newly assigned
495value is within a certain range (presuming external data) would look 496value is within a certain range (presuming external data) would look
496like the following: 497like the following:
497.Pp 498.Pp
498.Bd -literal -offset indent -compact 499.Bd -literal -offset indent -compact
499static int sysctl_helper(SYSCTLFN_PROTO); 500static int sysctl_helper(SYSCTLFN_PROTO);
500 501
501static int 502static int
502sysctl_helper(SYSCTLFN_ARGS) 503sysctl_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
521The use of the 524The 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.
526The single argument to the 529The single argument to the
527.Dv SYSCTLFN_CALL 530.Dv SYSCTLFN_CALL
528macro is the pointer to the node being examined. 531macro is the pointer to the node being examined.
529.Pp 532.Pp