]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/sysctl.2
getdents.2, sysctl.2: EXAMPLES: Fix bugs related to printf(3)
[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.\"
1d767b55 10.TH SYSCTL 2 2021-03-22 "Linux" "Linux Programmer's Manual"
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
fea681da 18.BI "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.
47297adb 79.SH CONFORMING TO
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
MK
117#define _GNU_SOURCE
118#include <unistd.h>
119#include <sys/syscall.h>
120#include <string.h>
121#include <stdio.h>
122#include <stdlib.h>
2b2581ee
MK
123#include <linux/sysctl.h>
124
c12fd10d 125int _sysctl(struct __sysctl_args *args );
2b2581ee 126
2b2581ee
MK
127#define OSNAMESZ 100
128
2b2581ee
MK
129int
130main(void)
131{
c12fd10d
MK
132 struct __sysctl_args args;
133 char osname[OSNAMESZ];
134 size_t osnamelth;
135 int name[] = { CTL_KERN, KERN_OSTYPE };
136
bbedcb75 137 memset(&args, 0, sizeof(args));
c12fd10d
MK
138 args.name = name;
139 args.nlen = sizeof(name)/sizeof(name[0]);
140 args.oldval = osname;
141 args.oldlenp = &osnamelth;
988db661 142
2b2581ee 143 osnamelth = sizeof(osname);
988db661 144
29059a65 145 if (syscall(SYS__sysctl, &args) == \-1) {
c12fd10d
MK
146 perror("_sysctl");
147 exit(EXIT_FAILURE);
148 }
e0247658 149 printf("This machine is running %*s\en", (int) osnamelth, osname);
2b2581ee
MK
150 exit(EXIT_SUCCESS);
151}
207050fa 152.EE
33857069 153.\" SRC END
47297adb 154.SH SEE ALSO
fea681da 155.BR proc (5)