]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/sysctl.2
ffix
[thirdparty/man-pages.git] / man2 / sysctl.2
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.
11 .\"
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.
19 .\"
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 .\"
28 .TH SYSCTL 2 2007-09-22 "Linux" "Linux Programmer's Manual"
29 .SH NAME
30 sysctl \- read/write system parameters
31 .SH SYNOPSIS
32 .nf
33 .B #include <unistd.h>
34 .br
35 .B #include <linux/sysctl.h>
36 .sp
37 .BI "int _sysctl(struct __sysctl_args *" args );
38 .fi
39 .SH DESCRIPTION
40 The
41 .BR _sysctl ()
42 call reads and/or writes kernel parameters.
43 For example, the hostname,
44 or the maximum number of open files.
45 The argument has the form
46 .PP
47 .in +4n
48 .nf
49 struct __sysctl_args {
50 int *name; /* integer vector describing variable */
51 int nlen; /* length of this vector */
52 void *oldval; /* 0 or address where to store old value */
53 size_t *oldlenp; /* available room for old value,
54 overwritten by actual size of old value */
55 void *newval; /* 0 or address of new value */
56 size_t newlen; /* size of new value */
57 };
58 .fi
59 .in
60 .PP
61 This call does a search in a tree structure, possibly resembling
62 a directory tree under
63 .IR /proc/sys ,
64 and if the requested item is found calls some appropriate routine
65 to read or modify the value.
66 .SH "RETURN VALUE"
67 Upon successful completion,
68 .BR _sysctl ()
69 returns 0.
70 Otherwise, a value of \-1 is returned and
71 .I errno
72 is set to indicate the error.
73 .SH ERRORS
74 .TP
75 .B EFAULT
76 The invocation asked for the previous value by setting
77 .I oldval
78 non-NULL, but allowed zero room in
79 .IR oldlenp .
80 .TP
81 .B ENOTDIR
82 .I name
83 was not found.
84 .TP
85 .B EPERM
86 No search permission for one of the encountered "directories",
87 or no read permission where
88 .I oldval
89 was non-zero, or no write permission where
90 .I newval
91 was non-zero.
92 .SH "CONFORMING TO"
93 This call is Linux specific, and should not be used in programs
94 intended to be portable.
95 A
96 .BR sysctl ()
97 call has been present in Linux since version 1.3.57.
98 It originated in
99 4.4BSD.
100 Only Linux has the
101 .I /proc/sys
102 mirror, and the object naming schemes differ between Linux and 4.4BSD,
103 but the declaration of the
104 .BR sysctl ()
105 function is the same in both.
106 .SH NOTES
107 Glibc does not provide a wrapper for this system call; call it using
108 .BR syscall (2).
109
110 Or rather... don't call it:
111 use of this system call has long been discouraged,
112 and it is so unloved that
113 \fBit is likely to disappear in a future kernel version\fP.
114 .\" See http://lwn.net/Articles/247243/
115 Remove it from your programs now; use the
116 .I /proc/sys
117 interface instead.
118 .SH BUGS
119 The object names vary between kernel versions,
120 making this system call worthless for applications.
121 .PP
122 Not all available objects are properly documented.
123 .PP
124 It is not yet possible to change operating system by writing to
125 .IR /proc/sys/kernel/ostype .
126 .SH EXAMPLE
127 .nf
128 #define _GNU_SOURCE
129 #include <unistd.h>
130 #include <sys/syscall.h>
131 #include <string.h>
132 #include <stdio.h>
133 #include <stdlib.h>
134 #include <linux/sysctl.h>
135
136 int _sysctl(struct __sysctl_args *args );
137
138 #define OSNAMESZ 100
139
140 int
141 main(void)
142 {
143 struct __sysctl_args args;
144 char osname[OSNAMESZ];
145 size_t osnamelth;
146 int name[] = { CTL_KERN, KERN_OSTYPE };
147
148 memset(&args, 0, sizeof(struct __sysctl_args));
149 args.name = name;
150 args.nlen = sizeof(name)/sizeof(name[0]);
151 args.oldval = osname;
152 args.oldlenp = &osnamelth;
153
154 osnamelth = sizeof(osname);
155
156 if (syscall(SYS__sysctl, &args) == \-1) {
157 perror("_sysctl");
158 exit(EXIT_FAILURE);
159 }
160 printf("This machine is running %*s\\n", osnamelth, osname);
161 exit(EXIT_SUCCESS);
162 }
163 .fi
164 .SH "SEE ALSO"
165 .BR proc (5)