]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/sysctl.2
Many pages: Use correct letter case in page titles (TH)
[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
cbb57e74
MK
59.BR EACCES ", " EPERM
60No search permission for one of the encountered "directories",
61or no read permission where
62.I oldval
63was nonzero, or no write permission where
64.I newval
65was nonzero.
66.TP
fea681da
MK
67.B EFAULT
68The invocation asked for the previous value by setting
69.I oldval
70non-NULL, but allowed zero room in
71.IR oldlenp .
72.TP
73.B ENOTDIR
74.I name
75was not found.
5dc3d7b7
MK
76.SH VERSIONS
77This system call first appeared in Linux 1.3.57.
f4077c2c 78It was removed in Linux 5.5; glibc support was removed in version 2.32.
3113c7f3 79.SH STANDARDS
8382f16d 80This call is Linux-specific, and should not be used in programs
fea681da 81intended to be portable.
c13182ef
MK
82It originated in
834.4BSD.
84Only Linux has the
fea681da 85.I /proc/sys
b14d4aa5 86mirror, and the object naming schemes differ between Linux and 4.4BSD,
fea681da 87but the declaration of the
2777b1ca 88.BR sysctl ()
fea681da 89function is the same in both.
f5b03186 90.SH NOTES
5dc3d7b7
MK
91Use of this system call was long discouraged:
92since Linux 2.6.24,
93uses of this system call result in warnings in the kernel log,
94and in Linux 5.5, the system call was finally removed.
95Use the
fea681da
MK
96.I /proc/sys
97interface instead.
efeece04 98.PP
5dc3d7b7
MK
99Note that on older kernels where this system call still exists,
100it is available only if the kernel was configured with the
28474c20
MK
101.B CONFIG_SYSCTL_SYSCALL
102option.
16cc03ca 103Furthermore, glibc does not provide a wrapper for this system call,
5dc3d7b7
MK
104necessitating the use of
105.BR syscall (2).
3efbc18c
MK
106.SH BUGS
107The object names vary between kernel versions,
108making this system call worthless for applications.
ef17a8a1 109.PP
fea681da 110Not all available objects are properly documented.
ef17a8a1 111.PP
fea681da
MK
112It is not yet possible to change operating system by writing to
113.IR /proc/sys/kernel/ostype .
a14af333 114.SH EXAMPLES
33857069 115.\" SRC BEGIN (sysctl.c)
207050fa 116.EX
c12fd10d 117#define _GNU_SOURCE
c12fd10d
MK
118#include <stdio.h>
119#include <stdlib.h>
4ae706b0
AC
120#include <string.h>
121#include <sys/syscall.h>
122#include <unistd.h>
123
2b2581ee
MK
124#include <linux/sysctl.h>
125
6a6393de
AC
126#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
127
e707017b 128int _sysctl(struct __sysctl_args *args);
2b2581ee 129
2b2581ee
MK
130#define OSNAMESZ 100
131
2b2581ee
MK
132int
133main(void)
134{
0b94bd78
AC
135 int name[] = { CTL_KERN, KERN_OSTYPE };
136 char osname[OSNAMESZ];
137 size_t osnamelth;
138 struct __sysctl_args args;
c12fd10d 139
bbedcb75 140 memset(&args, 0, sizeof(args));
c12fd10d 141 args.name = name;
6a6393de 142 args.nlen = ARRAY_SIZE(name);
c12fd10d
MK
143 args.oldval = osname;
144 args.oldlenp = &osnamelth;
988db661 145
2b2581ee 146 osnamelth = sizeof(osname);
988db661 147
29059a65 148 if (syscall(SYS__sysctl, &args) == \-1) {
c12fd10d
MK
149 perror("_sysctl");
150 exit(EXIT_FAILURE);
151 }
e0247658 152 printf("This machine is running %*s\en", (int) osnamelth, osname);
2b2581ee
MK
153 exit(EXIT_SUCCESS);
154}
207050fa 155.EE
33857069 156.\" SRC END
47297adb 157.SH SEE ALSO
fea681da 158.BR proc (5)