]>
Commit | Line | Data |
---|---|---|
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 |
12 | sysctl \- 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 | 22 | See NOTES. |
efeece04 | 23 | .PP |
fea681da | 24 | The |
e511ffb6 | 25 | .BR _sysctl () |
c13182ef MK |
26 | call reads and/or writes kernel parameters. |
27 | For example, the hostname, | |
28 | or the maximum number of open files. | |
29 | The argument has the form | |
fea681da | 30 | .PP |
088a639b | 31 | .in +4n |
b8302363 | 32 | .EX |
fea681da | 33 | struct __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 |
45 | This call does a search in a tree structure, possibly resembling | |
46 | a directory tree under | |
8478ee02 | 47 | .IR /proc/sys , |
fea681da MK |
48 | and if the requested item is found calls some appropriate routine |
49 | to read or modify the value. | |
47297adb | 50 | .SH RETURN VALUE |
fea681da | 51 | Upon successful completion, |
e511ffb6 | 52 | .BR _sysctl () |
c13182ef MK |
53 | returns 0. |
54 | Otherwise, a value of \-1 is returned and | |
fea681da MK |
55 | .I errno |
56 | is set to indicate the error. | |
57 | .SH ERRORS | |
58 | .TP | |
cbb57e74 MK |
59 | .BR EACCES ", " EPERM |
60 | No search permission for one of the encountered "directories", | |
61 | or no read permission where | |
62 | .I oldval | |
63 | was nonzero, or no write permission where | |
64 | .I newval | |
65 | was nonzero. | |
66 | .TP | |
fea681da MK |
67 | .B EFAULT |
68 | The invocation asked for the previous value by setting | |
69 | .I oldval | |
70 | non-NULL, but allowed zero room in | |
71 | .IR oldlenp . | |
72 | .TP | |
73 | .B ENOTDIR | |
74 | .I name | |
75 | was not found. | |
5dc3d7b7 MK |
76 | .SH VERSIONS |
77 | This system call first appeared in Linux 1.3.57. | |
f4077c2c | 78 | It was removed in Linux 5.5; glibc support was removed in version 2.32. |
47297adb | 79 | .SH CONFORMING TO |
8382f16d | 80 | This call is Linux-specific, and should not be used in programs |
fea681da | 81 | intended to be portable. |
c13182ef MK |
82 | It originated in |
83 | 4.4BSD. | |
84 | Only Linux has the | |
fea681da | 85 | .I /proc/sys |
b14d4aa5 | 86 | mirror, and the object naming schemes differ between Linux and 4.4BSD, |
fea681da | 87 | but the declaration of the |
2777b1ca | 88 | .BR sysctl () |
fea681da | 89 | function is the same in both. |
f5b03186 | 90 | .SH NOTES |
5dc3d7b7 MK |
91 | Use of this system call was long discouraged: |
92 | since Linux 2.6.24, | |
93 | uses of this system call result in warnings in the kernel log, | |
94 | and in Linux 5.5, the system call was finally removed. | |
95 | Use the | |
fea681da MK |
96 | .I /proc/sys |
97 | interface instead. | |
efeece04 | 98 | .PP |
5dc3d7b7 MK |
99 | Note that on older kernels where this system call still exists, |
100 | it is available only if the kernel was configured with the | |
28474c20 MK |
101 | .B CONFIG_SYSCTL_SYSCALL |
102 | option. | |
16cc03ca | 103 | Furthermore, glibc does not provide a wrapper for this system call, |
5dc3d7b7 MK |
104 | necessitating the use of |
105 | .BR syscall (2). | |
3efbc18c MK |
106 | .SH BUGS |
107 | The object names vary between kernel versions, | |
108 | making this system call worthless for applications. | |
ef17a8a1 | 109 | .PP |
fea681da | 110 | Not all available objects are properly documented. |
ef17a8a1 | 111 | .PP |
fea681da MK |
112 | It 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 | 128 | int _sysctl(struct __sysctl_args *args); |
2b2581ee | 129 | |
2b2581ee MK |
130 | #define OSNAMESZ 100 |
131 | ||
2b2581ee MK |
132 | int |
133 | main(void) | |
134 | { | |
c12fd10d MK |
135 | struct __sysctl_args args; |
136 | char osname[OSNAMESZ]; | |
137 | size_t osnamelth; | |
138 | int name[] = { CTL_KERN, KERN_OSTYPE }; | |
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) |