]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/sysctl.2
man*/: ffix (Use '.TQ' where appropriate)
[thirdparty/man-pages.git] / man2 / sysctl.2
CommitLineData
fea681da
MK
1.\" Copyright (C) 1996 Andries Brouwer (aeb@cwi.nl)
2.\"
5fbde956 3.\" SPDX-License-Identifier: Linux-man-pages-copyleft
fea681da
MK
4.\"
5.\" Written 11 April 1996 by Andries Brouwer <aeb@cwi.nl>
6.\" 960412: Added comments from Stephen Tweedie
7.\" Modified Tue Oct 22 22:28:41 1996 by Eric S. Raymond <esr@thyrsus.com>
8.\" Modified Mon Jan 5 20:31:04 1998 by aeb.
9.\"
4c1c5274 10.TH sysctl 2 (date) "Linux man-pages (unreleased)"
fea681da
MK
11.SH NAME
12sysctl \- read/write system parameters
13.SH SYNOPSIS
16718a1c 14.nf
fea681da 15.B #include <unistd.h>
fea681da 16.B #include <linux/sysctl.h>
68e4db0a 17.PP
7f78a555 18.BI "[[deprecated]] int _sysctl(struct __sysctl_args *" args );
16718a1c 19.fi
fea681da 20.SH DESCRIPTION
5dc3d7b7 21.B This system call no longer exists on current kernels!
5f06e2ff 22See NOTES.
efeece04 23.PP
fea681da 24The
e511ffb6 25.BR _sysctl ()
c13182ef
MK
26call reads and/or writes kernel parameters.
27For example, the hostname,
28or the maximum number of open files.
29The argument has the form
fea681da 30.PP
088a639b 31.in +4n
b8302363 32.EX
fea681da 33struct __sysctl_args {
90b36ddd
MK
34 int *name; /* integer vector describing variable */
35 int nlen; /* length of this vector */
36 void *oldval; /* 0 or address where to store old value */
37 size_t *oldlenp; /* available room for old value,
38 overwritten by actual size of old value */
39 void *newval; /* 0 or address of new value */
40 size_t newlen; /* size of new value */
fea681da 41};
b8302363 42.EE
90b36ddd 43.in
fea681da
MK
44.PP
45This call does a search in a tree structure, possibly resembling
46a directory tree under
8478ee02 47.IR /proc/sys ,
fea681da
MK
48and if the requested item is found calls some appropriate routine
49to read or modify the value.
47297adb 50.SH RETURN VALUE
fea681da 51Upon successful completion,
e511ffb6 52.BR _sysctl ()
c13182ef
MK
53returns 0.
54Otherwise, a value of \-1 is returned and
fea681da
MK
55.I errno
56is set to indicate the error.
57.SH ERRORS
58.TP
6fdb1c03
AC
59.B EACCES
60.TQ
61.B EPERM
cbb57e74
MK
62No search permission for one of the encountered "directories",
63or no read permission where
64.I oldval
65was nonzero, or no write permission where
66.I newval
67was nonzero.
68.TP
fea681da
MK
69.B EFAULT
70The invocation asked for the previous value by setting
71.I oldval
72non-NULL, but allowed zero room in
73.IR oldlenp .
74.TP
75.B ENOTDIR
76.I name
77was not found.
3113c7f3 78.SH STANDARDS
4131356c
AC
79Linux.
80.SH HISTORY
81Linux 1.3.57.
82Removed in Linux 5.5, glibc 2.32.
83.PP
c13182ef
MK
84It originated in
854.4BSD.
86Only Linux has the
fea681da 87.I /proc/sys
b14d4aa5 88mirror, and the object naming schemes differ between Linux and 4.4BSD,
fea681da 89but the declaration of the
2777b1ca 90.BR sysctl ()
fea681da 91function is the same in both.
f5b03186 92.SH NOTES
5dc3d7b7
MK
93Use of this system call was long discouraged:
94since Linux 2.6.24,
95uses of this system call result in warnings in the kernel log,
96and in Linux 5.5, the system call was finally removed.
97Use the
fea681da
MK
98.I /proc/sys
99interface instead.
efeece04 100.PP
5dc3d7b7
MK
101Note that on older kernels where this system call still exists,
102it is available only if the kernel was configured with the
28474c20
MK
103.B CONFIG_SYSCTL_SYSCALL
104option.
16cc03ca 105Furthermore, glibc does not provide a wrapper for this system call,
5dc3d7b7
MK
106necessitating the use of
107.BR syscall (2).
3efbc18c
MK
108.SH BUGS
109The object names vary between kernel versions,
110making this system call worthless for applications.
ef17a8a1 111.PP
fea681da 112Not all available objects are properly documented.
ef17a8a1 113.PP
fea681da
MK
114It is not yet possible to change operating system by writing to
115.IR /proc/sys/kernel/ostype .
a14af333 116.SH EXAMPLES
33857069 117.\" SRC BEGIN (sysctl.c)
207050fa 118.EX
c12fd10d 119#define _GNU_SOURCE
c12fd10d
MK
120#include <stdio.h>
121#include <stdlib.h>
4ae706b0
AC
122#include <string.h>
123#include <sys/syscall.h>
124#include <unistd.h>
fe5dba13 125\&
2b2581ee 126#include <linux/sysctl.h>
fe5dba13 127\&
6a6393de 128#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
fe5dba13 129\&
e707017b 130int _sysctl(struct __sysctl_args *args);
fe5dba13 131\&
2b2581ee 132#define OSNAMESZ 100
fe5dba13 133\&
2b2581ee
MK
134int
135main(void)
136{
0b94bd78
AC
137 int name[] = { CTL_KERN, KERN_OSTYPE };
138 char osname[OSNAMESZ];
139 size_t osnamelth;
140 struct __sysctl_args args;
fe5dba13 141\&
bbedcb75 142 memset(&args, 0, sizeof(args));
c12fd10d 143 args.name = name;
6a6393de 144 args.nlen = ARRAY_SIZE(name);
c12fd10d
MK
145 args.oldval = osname;
146 args.oldlenp = &osnamelth;
fe5dba13 147\&
2b2581ee 148 osnamelth = sizeof(osname);
fe5dba13 149\&
29059a65 150 if (syscall(SYS__sysctl, &args) == \-1) {
c12fd10d
MK
151 perror("_sysctl");
152 exit(EXIT_FAILURE);
153 }
e0247658 154 printf("This machine is running %*s\en", (int) osnamelth, osname);
2b2581ee
MK
155 exit(EXIT_SUCCESS);
156}
207050fa 157.EE
33857069 158.\" SRC END
47297adb 159.SH SEE ALSO
fea681da 160.BR proc (5)