OSDN Git Service

3937581d556d3db78eafc1f2cb6bf05c7d99cac8
[linuxjm/LDP_man-pages.git] / original / man2 / sysctl.2
1 .\" Copyright (C) 1996 Andries Brouwer (aeb@cwi.nl)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" Written 11 April 1996 by Andries Brouwer <aeb@cwi.nl>
26 .\" 960412: Added comments from Stephen Tweedie
27 .\" Modified Tue Oct 22 22:28:41 1996 by Eric S. Raymond <esr@thyrsus.com>
28 .\" Modified Mon Jan  5 20:31:04 1998 by aeb.
29 .\"
30 .TH SYSCTL 2 2012-12-22 "Linux" "Linux Programmer's Manual"
31 .SH NAME
32 sysctl \- read/write system parameters
33 .SH SYNOPSIS
34 .nf
35 .B #include <unistd.h>
36 .br
37 .B #include <linux/sysctl.h>
38 .sp
39 .BI "int _sysctl(struct __sysctl_args *" args );
40 .fi
41
42 .IR Note :
43 There is no glibc wrapper for this system call; see NOTES.
44 .SH DESCRIPTION
45 .B Do not use this system call!
46 See NOTES.
47
48 The
49 .BR _sysctl ()
50 call reads and/or writes kernel parameters.
51 For example, the hostname,
52 or the maximum number of open files.
53 The argument has the form
54 .PP
55 .in +4n
56 .nf
57 struct __sysctl_args {
58     int    *name;    /* integer vector describing variable */
59     int     nlen;    /* length of this vector */
60     void   *oldval;  /* 0 or address where to store old value */
61     size_t *oldlenp; /* available room for old value,
62                         overwritten by actual size of old value */
63     void   *newval;  /* 0 or address of new value */
64     size_t  newlen;  /* size of new value */
65 };
66 .fi
67 .in
68 .PP
69 This call does a search in a tree structure, possibly resembling
70 a directory tree under
71 .IR /proc/sys ,
72 and if the requested item is found calls some appropriate routine
73 to read or modify the value.
74 .SH RETURN VALUE
75 Upon successful completion,
76 .BR _sysctl ()
77 returns 0.
78 Otherwise, a value of \-1 is returned and
79 .I errno
80 is set to indicate the error.
81 .SH ERRORS
82 .TP
83 .B EFAULT
84 The invocation asked for the previous value by setting
85 .I oldval
86 non-NULL, but allowed zero room in
87 .IR oldlenp .
88 .TP
89 .B ENOTDIR
90 .I name
91 was not found.
92 .TP
93 .BR EACCES ", " EPERM
94 No search permission for one of the encountered "directories",
95 or no read permission where
96 .I oldval
97 was nonzero, or no write permission where
98 .I newval
99 was nonzero.
100 .SH CONFORMING TO
101 This call is Linux-specific, and should not be used in programs
102 intended to be portable.
103 A
104 .BR sysctl ()
105 call has been present in Linux since version 1.3.57.
106 It originated in
107 4.4BSD.
108 Only Linux has the
109 .I /proc/sys
110 mirror, and the object naming schemes differ between Linux and 4.4BSD,
111 but the declaration of the
112 .BR sysctl ()
113 function is the same in both.
114 .SH NOTES
115 Glibc does not provide a wrapper for this system call; call it using
116 .BR syscall (2).
117 Or rather...
118 .I don't
119 call it:
120 use of this system call has long been discouraged,
121 and it is so unloved that
122 \fBit is likely to disappear in a future kernel version\fP.
123 .\" See http://lwn.net/Articles/247243/
124 Since Linux 2.6.24,
125 uses of this system call result in warnings in the kernel log.
126 .\" Though comments in suggest that it is needed by old glibc binaries,
127 .\" so maybe it's not going away.
128 Remove it from your programs now; use the
129 .I /proc/sys
130 interface instead.
131
132 This system call is available only if the kernel was configured with the
133 .B CONFIG_SYSCTL_SYSCALL
134 option.
135 .SH BUGS
136 The object names vary between kernel versions,
137 making this system call worthless for applications.
138 .PP
139 Not all available objects are properly documented.
140 .PP
141 It is not yet possible to change operating system by writing to
142 .IR /proc/sys/kernel/ostype .
143 .SH EXAMPLE
144 .nf
145 #define _GNU_SOURCE
146 #include <unistd.h>
147 #include <sys/syscall.h>
148 #include <string.h>
149 #include <stdio.h>
150 #include <stdlib.h>
151 #include <linux/sysctl.h>
152
153 int _sysctl(struct __sysctl_args *args );
154
155 #define OSNAMESZ 100
156
157 int
158 main(void)
159 {
160     struct __sysctl_args args;
161     char osname[OSNAMESZ];
162     size_t osnamelth;
163     int name[] = { CTL_KERN, KERN_OSTYPE };
164
165     memset(&args, 0, sizeof(struct __sysctl_args));
166     args.name = name;
167     args.nlen = sizeof(name)/sizeof(name[0]);
168     args.oldval = osname;
169     args.oldlenp = &osnamelth;
170
171     osnamelth = sizeof(osname);
172
173     if (syscall(SYS__sysctl, &args) == \-1) {
174         perror("_sysctl");
175         exit(EXIT_FAILURE);
176     }
177     printf("This machine is running %*s\\n", osnamelth, osname);
178     exit(EXIT_SUCCESS);
179 }
180 .fi
181 .SH SEE ALSO
182 .BR proc (5)
183 .SH COLOPHON
184 This page is part of release 3.67 of the Linux
185 .I man-pages
186 project.
187 A description of the project,
188 information about reporting bugs,
189 and the latest version of this page,
190 can be found at
191 \%http://www.kernel.org/doc/man\-pages/.