]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/sysctl.2
After a note from Vasya Pupkin, I added <errno.h> to the SYNOPSIS
[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 .B #include <unistd.h>
33 .br
34 .B #include <linux/unistd.h>
35 .br
36 .B #include <linux/sysctl.h>
37 .br
38 .B #include <errno.h>
39 .sp
40 .B _syscall1(int, _sysctl, struct __sysctl_args *, args)
41 .sp
42 .BI "int _sysctl(struct __sysctl_args *" args );
43 .SH DESCRIPTION
44 The
45 .B _sysctl
46 call reads and/or writes kernel parameters. For example, the hostname,
47 or the maximum number of open files. The argument has the form
48 .PP
49 .nf
50 struct __sysctl_args {
51 int *name; /* integer vector describing variable */
52 int nlen; /* length of this vector */
53 void *oldval; /* 0 or address where to store old value */
54 size_t *oldlenp; /* available room for old value,
55 overwritten by actual size of old value */
56 void *newval; /* 0 or address of new value */
57 size_t newlen; /* size of new value */
58 };
59 .fi
60 .PP
61 This call does a search in a tree structure, possibly resembling
62 a directory tree under
63 .BR /proc/sys ,
64 and if the requested item is found calls some appropriate routine
65 to read or modify the value.
66
67 .SH EXAMPLE
68 .nf
69 #include <linux/unistd.h>
70 #include <linux/types.h>
71 #include <linux/sysctl.h>
72
73 _syscall1(int, _sysctl, struct __sysctl_args *, args);
74 int sysctl(int *name, int nlen, void *oldval, size_t *oldlenp,
75 void *newval, size_t newlen)
76 {
77 struct __sysctl_args args={name,nlen,oldval,oldlenp,newval,newlen};
78 return _sysctl(&args);
79 }
80
81 #define SIZE(x) sizeof(x)/sizeof(x[0])
82 #define OSNAMESZ 100
83
84 char osname[OSNAMESZ];
85 int osnamelth;
86 int name[] = { CTL_KERN, KERN_OSTYPE };
87
88 main(){
89 osnamelth = sizeof(osname);
90 if (sysctl(name, SIZE(name), osname, &osnamelth, 0, 0))
91 perror("sysctl");
92 else
93 printf("This machine is running %*s\en", osnamelth, osname);
94 return 0;
95 }
96 .fi
97
98 .SH "RETURN VALUE"
99 Upon successful completion,
100 .B _sysctl
101 returns 0. Otherwise, a value of \-1 is returned and
102 .I errno
103 is set to indicate the error.
104 .SH ERRORS
105 .TP
106 .B EFAULT
107 The invocation asked for the previous value by setting
108 .I oldval
109 non-NULL, but allowed zero room in
110 .IR oldlenp .
111 .TP
112 .B ENOTDIR
113 .I name
114 was not found.
115 .TP
116 .B EPERM
117 No search permission for one of the encountered `directories',
118 or no read permission where
119 .I oldval
120 was nonzero, or no write permission where
121 .I newval
122 was nonzero.
123 .SH "CONFORMING TO"
124 This call is Linux-specific, and should not be used in programs
125 intended to be portable.
126 A
127 .B sysctl
128 call has been present in Linux since version 1.3.57. It originated in
129 4.4BSD. Only Linux has the
130 .I /proc/sys
131 mirror, and the object naming schemes differ between Linux and BSD 4.4,
132 but the declaration of the
133 .BR sysctl (2)
134 function is the same in both.
135 .SH BUGS
136 The object names vary between kernel versions.
137 THIS MAKES THIS SYSTEM CALL WORTHLESS FOR APPLICATIONS.
138 Use the
139 .I /proc/sys
140 interface instead.
141 .br
142 Not all available objects are properly documented.
143 .br
144 It is not yet possible to change operating system by writing to
145 .IR /proc/sys/kernel/ostype .
146 .SH "SEE ALSO"
147 .BR proc (5)