]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/sysctl.2
Wrapped long lines, wrapped at sentence boundaries; stripped trailing
[thirdparty/man-pages.git] / man2 / sysctl.2
1 .\" Copyright (C) 1996 Andries Brouwer (aeb@cwi.nl)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" Written 11 April 1996 by Andries Brouwer <aeb@cwi.nl>
24 .\" 960412: Added comments from Stephen Tweedie
25 .\" Modified Tue Oct 22 22:28:41 1996 by Eric S. Raymond <esr@thyrsus.com>
26 .\" Modified Mon Jan 5 20:31:04 1998 by aeb.
27 .\"
28 .TH SYSCTL 2 1996-04-11 "Linux 1.3.85" "Linux Programmer's Manual"
29 .SH NAME
30 sysctl \- read/write system parameters
31 .SH SYNOPSIS
32 .nf
33 .B #include <unistd.h>
34 .br
35 .B #include <linux/unistd.h>
36 .br
37 .B #include <linux/sysctl.h>
38 .br
39 .B #include <errno.h>
40 .sp
41 .B _syscall1(int, _sysctl, struct __sysctl_args *, args)
42 /* Using \fBsyscall\fP(2) may be preferable; see \fBintro\fP(2) */
43 .sp
44 .BI "int _sysctl(struct __sysctl_args *" args );
45 .fi
46 .SH DESCRIPTION
47 The
48 .BR _sysctl ()
49 call reads and/or writes kernel parameters.
50 For example, the hostname,
51 or the maximum number of open files.
52 The argument has the form
53 .PP
54 .nf
55 struct __sysctl_args {
56 int *name; /* integer vector describing variable */
57 int nlen; /* length of this vector */
58 void *oldval; /* 0 or address where to store old value */
59 size_t *oldlenp; /* available room for old value,
60 overwritten by actual size of old value */
61 void *newval; /* 0 or address of new value */
62 size_t newlen; /* size of new value */
63 };
64 .fi
65 .PP
66 This call does a search in a tree structure, possibly resembling
67 a directory tree under
68 .IR /proc/sys ,
69 and if the requested item is found calls some appropriate routine
70 to read or modify the value.
71 .SH EXAMPLE
72 .nf
73 #include <linux/unistd.h>
74 #include <linux/types.h>
75 #include <linux/sysctl.h>
76
77 _syscall1(int, _sysctl, struct __sysctl_args *, args);
78 int sysctl(int *name, int nlen, void *oldval, size_t *oldlenp,
79 void *newval, size_t newlen)
80 {
81 struct __sysctl_args args = { name, nlen, oldval, oldlenp,
82 newval, newlen };
83 return _sysctl(&args);
84 }
85
86 #define SIZE(x) sizeof(x)/sizeof(x[0])
87 #define OSNAMESZ 100
88
89 char osname[OSNAMESZ];
90 int osnamelth;
91 int name[] = { CTL_KERN, KERN_OSTYPE };
92
93 int
94 main(void)
95 {
96 osnamelth = sizeof(osname);
97 if (sysctl(name, SIZE(name), osname, &osnamelth, 0, 0))
98 perror("sysctl");
99 else
100 printf("This machine is running %*s\en", osnamelth, osname);
101 return 0;
102 }
103 .fi
104 .SH "RETURN VALUE"
105 Upon successful completion,
106 .BR _sysctl ()
107 returns 0.
108 Otherwise, a value of \-1 is returned and
109 .I errno
110 is set to indicate the error.
111 .SH ERRORS
112 .TP
113 .B EFAULT
114 The invocation asked for the previous value by setting
115 .I oldval
116 non-NULL, but allowed zero room in
117 .IR oldlenp .
118 .TP
119 .B ENOTDIR
120 .I name
121 was not found.
122 .TP
123 .B EPERM
124 No search permission for one of the encountered `directories',
125 or no read permission where
126 .I oldval
127 was non-zero, or no write permission where
128 .I newval
129 was non-zero.
130 .SH "CONFORMING TO"
131 This call is Linux specific, and should not be used in programs
132 intended to be portable.
133 A
134 .BR sysctl ()
135 call has been present in Linux since version 1.3.57.
136 It originated in
137 4.4BSD.
138 Only Linux has the
139 .I /proc/sys
140 mirror, and the object naming schemes differ between Linux and 4.4BSD,
141 but the declaration of the
142 .BR sysctl (2)
143 function is the same in both.
144 .SH BUGS
145 The object names vary between kernel versions.
146 THIS MAKES THIS SYSTEM CALL WORTHLESS FOR APPLICATIONS.
147 Use the
148 .I /proc/sys
149 interface instead.
150 .br
151 Not all available objects are properly documented.
152 .br
153 It is not yet possible to change operating system by writing to
154 .IR /proc/sys/kernel/ostype .
155 .SH "SEE ALSO"
156 .BR proc (5)