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