]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/sysctl.2
Update these pages to reflect the fact that the _syscallN() macros have
[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 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/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 BUGS
107 The object names vary between kernel versions.
108 THIS MAKES THIS SYSTEM CALL WORTHLESS FOR APPLICATIONS.
109 Use the
110 .I /proc/sys
111 interface instead.
112 .PP
113 Not all available objects are properly documented.
114 .PP
115 It is not yet possible to change operating system by writing to
116 .IR /proc/sys/kernel/ostype .
117 .SH EXAMPLE
118 .nf
119 #define _GNU_SOURCE
120 #include <unistd.h>
121 #include <sys/syscall.h>
122 #include <string.h>
123 #include <stdio.h>
124 #include <stdlib.h>
125 #include <linux/sysctl.h>
126
127 int _sysctl(struct __sysctl_args *args );
128
129 #define OSNAMESZ 100
130
131 int
132 main(void)
133 {
134 struct __sysctl_args args;
135 char osname[OSNAMESZ];
136 size_t osnamelth;
137 int name[] = { CTL_KERN, KERN_OSTYPE };
138
139 memset(&args, 0, sizeof(struct __sysctl_args));
140 args.name = name;
141 args.nlen = sizeof(name)/sizeof(name[0]);
142 args.oldval = osname;
143 args.oldlenp = &osnamelth;
144
145 osnamelth = sizeof(osname);
146
147 if (syscall(SYS__sysctl, &args) == -1) {
148 perror("_sysctl");
149 exit(EXIT_FAILURE);
150 }
151 printf("This machine is running %*s\n", osnamelth, osname);
152 exit(EXIT_SUCCESS);
153 }
154 .fi
155 .SH NOTES
156 Glibc does not provide a wrapper for this system call; call it using
157 .BR syscall (2).
158 .SH "SEE ALSO"
159 .BR proc (5)