sigaction.2: Minor tweaks to Peter's patch
[man-pages.git] / man2 / sysctl.2
blob2188389dc95694c5733d0ce52f48cd6089d0a922
1 .\" Copyright (C) 1996 Andries Brouwer (aeb@cwi.nl)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" Written 11 April 1996 by Andries Brouwer <aeb@cwi.nl>
26 .\" 960412: Added comments from Stephen Tweedie
27 .\" Modified Tue Oct 22 22:28:41 1996 by Eric S. Raymond <esr@thyrsus.com>
28 .\" Modified Mon Jan  5 20:31:04 1998 by aeb.
29 .\"
30 .TH SYSCTL 2 2021-03-22 "Linux" "Linux Programmer's Manual"
31 .SH NAME
32 sysctl \- read/write system parameters
33 .SH SYNOPSIS
34 .nf
35 .B #include <unistd.h>
36 .B #include <linux/sysctl.h>
37 .PP
38 .BI "int _sysctl(struct __sysctl_args *" args );
39 .fi
40 .SH DESCRIPTION
41 .B This system call no longer exists on current kernels!
42 See NOTES.
43 .PP
44 The
45 .BR _sysctl ()
46 call reads and/or writes kernel parameters.
47 For example, the hostname,
48 or the maximum number of open files.
49 The argument has the form
50 .PP
51 .in +4n
52 .EX
53 struct __sysctl_args {
54     int    *name;    /* integer vector describing variable */
55     int     nlen;    /* length of this vector */
56     void   *oldval;  /* 0 or address where to store old value */
57     size_t *oldlenp; /* available room for old value,
58                         overwritten by actual size of old value */
59     void   *newval;  /* 0 or address of new value */
60     size_t  newlen;  /* size of new value */
62 .EE
63 .in
64 .PP
65 This call does a search in a tree structure, possibly resembling
66 a directory tree under
67 .IR /proc/sys ,
68 and if the requested item is found calls some appropriate routine
69 to read or modify the value.
70 .SH RETURN VALUE
71 Upon successful completion,
72 .BR _sysctl ()
73 returns 0.
74 Otherwise, a value of \-1 is returned and
75 .I errno
76 is set to indicate the error.
77 .SH ERRORS
78 .TP
79 .BR EACCES ", " EPERM
80 No search permission for one of the encountered "directories",
81 or no read permission where
82 .I oldval
83 was nonzero, or no write permission where
84 .I newval
85 was nonzero.
86 .TP
87 .B EFAULT
88 The invocation asked for the previous value by setting
89 .I oldval
90 non-NULL, but allowed zero room in
91 .IR oldlenp .
92 .TP
93 .B ENOTDIR
94 .I name
95 was not found.
96 .SH VERSIONS
97 This system call first appeared in Linux 1.3.57.
98 It was removed in Linux 5.5; glibc support was removed in version 2.32.
99 .SH CONFORMING TO
100 This call is Linux-specific, and should not be used in programs
101 intended to be portable.
102 It originated in
103 4.4BSD.
104 Only Linux has the
105 .I /proc/sys
106 mirror, and the object naming schemes differ between Linux and 4.4BSD,
107 but the declaration of the
108 .BR sysctl ()
109 function is the same in both.
110 .SH NOTES
111 Use of this system call was long discouraged:
112 since Linux 2.6.24,
113 uses of this system call result in warnings in the kernel log,
114 and in Linux 5.5, the system call was finally removed.
115 Use the
116 .I /proc/sys
117 interface instead.
119 Note that on older kernels where this system call still exists,
120 it is available only if the kernel was configured with the
121 .B CONFIG_SYSCTL_SYSCALL
122 option.
123 Furthermore, glibc does not provide a wrapper for this system call,
124 necessitating the use of
125 .BR syscall (2).
126 .SH BUGS
127 The object names vary between kernel versions,
128 making this system call worthless for applications.
130 Not all available objects are properly documented.
132 It is not yet possible to change operating system by writing to
133 .IR /proc/sys/kernel/ostype .
134 .SH EXAMPLES
136 #define _GNU_SOURCE
137 #include <unistd.h>
138 #include <sys/syscall.h>
139 #include <string.h>
140 #include <stdio.h>
141 #include <stdlib.h>
142 #include <linux/sysctl.h>
144 int _sysctl(struct __sysctl_args *args );
146 #define OSNAMESZ 100
149 main(void)
151     struct __sysctl_args args;
152     char osname[OSNAMESZ];
153     size_t osnamelth;
154     int name[] = { CTL_KERN, KERN_OSTYPE };
156     memset(&args, 0, sizeof(args));
157     args.name = name;
158     args.nlen = sizeof(name)/sizeof(name[0]);
159     args.oldval = osname;
160     args.oldlenp = &osnamelth;
162     osnamelth = sizeof(osname);
164     if (syscall(SYS__sysctl, &args) == \-1) {
165         perror("_sysctl");
166         exit(EXIT_FAILURE);
167     }
168     printf("This machine is running %*s\en", osnamelth, osname);
169     exit(EXIT_SUCCESS);
172 .SH SEE ALSO
173 .BR proc (5)