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