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