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