Debian Codegraph @

upstream/debian-unstable/man2/sysctl.2

raw
1 .\" Copyright 1996, Andries E. Brouwer <[email protected]>
2 .\" Copyright, the authors of the Linux man-pages project
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .TH sysctl 2 2026-02-10 "Linux man-pages 6.18"
7 .SH NAME
8 sysctl \- read/write system parameters
9 .SH SYNOPSIS
10 .nf
11 .B #include <unistd.h>
12 .B #include <linux/sysctl.h>
13 .P
14 .BI "[[deprecated]] int _sysctl(struct __sysctl_args *" args );
15 .fi
16 .SH DESCRIPTION
17 .B This system call no longer exists on current kernels!
18 See NOTES.
19 .P
20 The
21 .BR _sysctl ()
22 call reads and/or writes kernel parameters.
23 For example, the hostname,
24 or the maximum number of open files.
25 The argument has the form
26 .P
27 .in +4n
28 .EX
29 struct __sysctl_args {
30 int *name; /* integer vector describing variable */
31 int nlen; /* number of elements of this vector */
32 void *oldval; /* 0 or address where to store old value */
33 size_t *oldlenp; /* available room for old value,
34 overwritten by actual size of old value */
35 void *newval; /* 0 or address of new value */
36 size_t newlen; /* size of new value */
37 };
38 .EE
39 .in
40 .P
41 This call does a search in a tree structure, possibly resembling
42 a directory tree under
43 .IR /proc/sys ,
44 and if the requested item is found calls some appropriate routine
45 to read or modify the value.
46 .SH RETURN VALUE
47 Upon successful completion,
48 .BR _sysctl ()
49 returns 0.
50 Otherwise, a value of \-1 is returned and
51 .I errno
52 is set to indicate the error.
53 .SH ERRORS
54 .TP
55 .B EACCES
56 .TQ
57 .B EPERM
58 No search permission for one of the encountered "directories",
59 or no read permission where
60 .I oldval
61 was nonzero, or no write permission where
62 .I newval
63 was nonzero.
64 .TP
65 .B EFAULT
66 The invocation asked for the previous value by setting
67 .I oldval
68 non-NULL, but allowed zero room in
69 .IR oldlenp .
70 .TP
71 .B ENOTDIR
72 .I name
73 was not found.
74 .SH STANDARDS
75 Linux.
76 .SH HISTORY
77 4.4BSD,
78 Linux 1.3.57.
79 Removed in Linux 5.5, glibc 2.32.
80 .P
81 Only Linux has the
82 .I /proc/sys
83 mirror, and the object naming schemes differ between Linux and 4.4BSD,
84 but the declaration of the
85 .BR sysctl ()
86 function is the same in both.
87 .SH NOTES
88 Use of this system call was long discouraged:
89 since Linux 2.6.24,
90 uses of this system call result in warnings in the kernel log,
91 and in Linux 5.5, the system call was finally removed.
92 Use the
93 .I /proc/sys
94 interface instead.
95 .P
96 Note that on older kernels where this system call still exists,
97 it is available only if the kernel was configured with the
98 .B CONFIG_SYSCTL_SYSCALL
99 option.
100 Furthermore, glibc does not provide a wrapper for this system call,
101 necessitating the use of
102 .BR syscall (2).
103 .SH BUGS
104 The object names vary between kernel versions,
105 making this system call worthless for applications.
106 .P
107 Not all available objects are properly documented.
108 .P
109 It is not yet possible to change operating system by writing to
110 .IR /proc/sys/kernel/ostype .
111 .SH EXAMPLES
112 .\" SRC BEGIN (sysctl.c)
113 .EX
114 #define _GNU_SOURCE
115 #include <stdcountof.h>
116 #include <stdio.h>
117 #include <stdlib.h>
118 #include <string.h>
119 #include <sys/syscall.h>
120 #include <unistd.h>
121 \&
122 #include <linux/sysctl.h>
123 \&
124 int _sysctl(struct __sysctl_args *args);
125 \&
126 #define OSNAMESZ 100
127 \&
128 int
129 main(void)
130 {
131 int name[] = { CTL_KERN, KERN_OSTYPE };
132 char osname[OSNAMESZ];
133 size_t osnamelth;
134 struct __sysctl_args args;
135 \&
136 memset(&args, 0, sizeof(args));
137 args.name = name;
138 args.nlen = countof(name);
139 args.oldval = osname;
140 args.oldlenp = &osnamelth;
141 \&
142 osnamelth = sizeof(osname);
143 \&
144 if (syscall(SYS__sysctl, &args) == \-1) {
145 perror("_sysctl");
146 exit(EXIT_FAILURE);
147 }
148 printf("This machine is running %*s\[rs]n", (int) osnamelth, osname);
149 exit(EXIT_SUCCESS);
150 }
151 .EE
152 .\" SRC END
153 .SH SEE ALSO
154 .BR proc (5)