]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/sysctl.2
fuse.4: ffix
[thirdparty/man-pages.git] / man2 / sysctl.2
CommitLineData
fea681da
MK
1.\" Copyright (C) 1996 Andries Brouwer (aeb@cwi.nl)
2.\"
93015253 3.\" %%%LICENSE_START(VERBATIM)
fea681da
MK
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.
c13182ef 12.\"
fea681da
MK
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.
c13182ef 20.\"
fea681da
MK
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 23.\" %%%LICENSE_END
fea681da
MK
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.\"
b8efb414 30.TH SYSCTL 2 2016-10-08 "Linux" "Linux Programmer's Manual"
fea681da
MK
31.SH NAME
32sysctl \- read/write system parameters
33.SH SYNOPSIS
16718a1c 34.nf
fea681da 35.B #include <unistd.h>
527d9933 36.br
fea681da 37.B #include <linux/sysctl.h>
fea681da
MK
38.sp
39.BI "int _sysctl(struct __sysctl_args *" args );
16718a1c 40.fi
45c99e3e
MK
41
42.IR Note :
43There is no glibc wrapper for this system call; see NOTES.
fea681da 44.SH DESCRIPTION
a113945f 45.B Do not use this system call!
5f06e2ff
MK
46See NOTES.
47
fea681da 48The
e511ffb6 49.BR _sysctl ()
c13182ef
MK
50call reads and/or writes kernel parameters.
51For example, the hostname,
52or the maximum number of open files.
53The argument has the form
fea681da 54.PP
088a639b 55.in +4n
fea681da
MK
56.nf
57struct __sysctl_args {
90b36ddd
MK
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 */
fea681da
MK
65};
66.fi
90b36ddd 67.in
fea681da
MK
68.PP
69This call does a search in a tree structure, possibly resembling
70a directory tree under
8478ee02 71.IR /proc/sys ,
fea681da
MK
72and if the requested item is found calls some appropriate routine
73to read or modify the value.
47297adb 74.SH RETURN VALUE
fea681da 75Upon successful completion,
e511ffb6 76.BR _sysctl ()
c13182ef
MK
77returns 0.
78Otherwise, a value of \-1 is returned and
fea681da
MK
79.I errno
80is set to indicate the error.
81.SH ERRORS
82.TP
cbb57e74
MK
83.BR EACCES ", " EPERM
84No search permission for one of the encountered "directories",
85or no read permission where
86.I oldval
87was nonzero, or no write permission where
88.I newval
89was nonzero.
90.TP
fea681da
MK
91.B EFAULT
92The invocation asked for the previous value by setting
93.I oldval
94non-NULL, but allowed zero room in
95.IR oldlenp .
96.TP
97.B ENOTDIR
98.I name
99was not found.
47297adb 100.SH CONFORMING TO
8382f16d 101This call is Linux-specific, and should not be used in programs
fea681da
MK
102intended to be portable.
103A
e511ffb6 104.BR sysctl ()
c13182ef
MK
105call has been present in Linux since version 1.3.57.
106It originated in
1074.4BSD.
108Only Linux has the
fea681da 109.I /proc/sys
b14d4aa5 110mirror, and the object naming schemes differ between Linux and 4.4BSD,
fea681da 111but the declaration of the
2777b1ca 112.BR sysctl ()
fea681da 113function is the same in both.
f5b03186
MK
114.SH NOTES
115Glibc does not provide a wrapper for this system call; call it using
116.BR syscall (2).
45c99e3e
MK
117Or rather...
118.I don't
119call it:
3efbc18c
MK
120use of this system call has long been discouraged,
121and it is so unloved that
4922b5d5 122\fBit is likely to disappear in a future kernel version\fP.
fb7339df 123.\" See http://lwn.net/Articles/247243/
431dcaeb 124Since Linux 2.6.24,
bef43fac
MK
125uses 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.
3efbc18c 128Remove it from your programs now; use the
fea681da
MK
129.I /proc/sys
130interface instead.
28474c20
MK
131
132This system call is available only if the kernel was configured with the
133.B CONFIG_SYSCTL_SYSCALL
134option.
3efbc18c
MK
135.SH BUGS
136The object names vary between kernel versions,
137making this system call worthless for applications.
ef17a8a1 138.PP
fea681da 139Not all available objects are properly documented.
ef17a8a1 140.PP
fea681da
MK
141It is not yet possible to change operating system by writing to
142.IR /proc/sys/kernel/ostype .
2b2581ee
MK
143.SH EXAMPLE
144.nf
c12fd10d
MK
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>
2b2581ee
MK
151#include <linux/sysctl.h>
152
c12fd10d 153int _sysctl(struct __sysctl_args *args );
2b2581ee 154
2b2581ee
MK
155#define OSNAMESZ 100
156
2b2581ee
MK
157int
158main(void)
159{
c12fd10d
MK
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;
988db661 170
2b2581ee 171 osnamelth = sizeof(osname);
988db661 172
29059a65 173 if (syscall(SYS__sysctl, &args) == \-1) {
c12fd10d
MK
174 perror("_sysctl");
175 exit(EXIT_FAILURE);
176 }
43940e36 177 printf("This machine is running %*s\\n", osnamelth, osname);
2b2581ee
MK
178 exit(EXIT_SUCCESS);
179}
180.fi
47297adb 181.SH SEE ALSO
fea681da 182.BR proc (5)