]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/sysctl.2
Removed trailing white space at end of lines
[thirdparty/man-pages.git] / man2 / sysctl.2
CommitLineData
fea681da
MK
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.
c13182ef 11.\"
fea681da
MK
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.
c13182ef 19.\"
fea681da
MK
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.\"
5f06e2ff 28.TH SYSCTL 2 2008-11-20 "Linux" "Linux Programmer's Manual"
fea681da
MK
29.SH NAME
30sysctl \- read/write system parameters
31.SH SYNOPSIS
16718a1c 32.nf
fea681da 33.B #include <unistd.h>
527d9933 34.br
fea681da 35.B #include <linux/sysctl.h>
fea681da
MK
36.sp
37.BI "int _sysctl(struct __sysctl_args *" args );
16718a1c 38.fi
fea681da 39.SH DESCRIPTION
a113945f 40.B Do not use this system call!
5f06e2ff
MK
41See NOTES.
42
fea681da 43The
e511ffb6 44.BR _sysctl ()
c13182ef
MK
45call reads and/or writes kernel parameters.
46For example, the hostname,
47or the maximum number of open files.
48The argument has the form
fea681da 49.PP
088a639b 50.in +4n
fea681da
MK
51.nf
52struct __sysctl_args {
90b36ddd
MK
53 int *name; /* integer vector describing variable */
54 int nlen; /* length of this vector */
55 void *oldval; /* 0 or address where to store old value */
56 size_t *oldlenp; /* available room for old value,
57 overwritten by actual size of old value */
58 void *newval; /* 0 or address of new value */
59 size_t newlen; /* size of new value */
fea681da
MK
60};
61.fi
90b36ddd 62.in
fea681da
MK
63.PP
64This call does a search in a tree structure, possibly resembling
65a directory tree under
8478ee02 66.IR /proc/sys ,
fea681da
MK
67and if the requested item is found calls some appropriate routine
68to read or modify the value.
fea681da
MK
69.SH "RETURN VALUE"
70Upon successful completion,
e511ffb6 71.BR _sysctl ()
c13182ef
MK
72returns 0.
73Otherwise, a value of \-1 is returned and
fea681da
MK
74.I errno
75is set to indicate the error.
76.SH ERRORS
77.TP
78.B EFAULT
79The invocation asked for the previous value by setting
80.I oldval
81non-NULL, but allowed zero room in
82.IR oldlenp .
83.TP
84.B ENOTDIR
85.I name
86was not found.
87.TP
88.B EPERM
2d986c92 89No search permission for one of the encountered "directories",
fea681da
MK
90or no read permission where
91.I oldval
eba72288 92was non-zero, or no write permission where
fea681da 93.I newval
eba72288 94was non-zero.
fea681da 95.SH "CONFORMING TO"
8382f16d 96This call is Linux-specific, and should not be used in programs
fea681da
MK
97intended to be portable.
98A
e511ffb6 99.BR sysctl ()
c13182ef
MK
100call has been present in Linux since version 1.3.57.
101It originated in
1024.4BSD.
103Only Linux has the
fea681da 104.I /proc/sys
b14d4aa5 105mirror, and the object naming schemes differ between Linux and 4.4BSD,
fea681da 106but the declaration of the
2777b1ca 107.BR sysctl ()
fea681da 108function is the same in both.
f5b03186
MK
109.SH NOTES
110Glibc does not provide a wrapper for this system call; call it using
111.BR syscall (2).
3efbc18c
MK
112
113Or rather... don't call it:
114use of this system call has long been discouraged,
115and it is so unloved that
4922b5d5 116\fBit is likely to disappear in a future kernel version\fP.
fb7339df 117.\" See http://lwn.net/Articles/247243/
3efbc18c 118Remove it from your programs now; use the
fea681da
MK
119.I /proc/sys
120interface instead.
3efbc18c
MK
121.SH BUGS
122The object names vary between kernel versions,
123making this system call worthless for applications.
ef17a8a1 124.PP
fea681da 125Not all available objects are properly documented.
ef17a8a1 126.PP
fea681da
MK
127It is not yet possible to change operating system by writing to
128.IR /proc/sys/kernel/ostype .
2b2581ee
MK
129.SH EXAMPLE
130.nf
c12fd10d
MK
131#define _GNU_SOURCE
132#include <unistd.h>
133#include <sys/syscall.h>
134#include <string.h>
135#include <stdio.h>
136#include <stdlib.h>
2b2581ee
MK
137#include <linux/sysctl.h>
138
c12fd10d 139int _sysctl(struct __sysctl_args *args );
2b2581ee 140
2b2581ee
MK
141#define OSNAMESZ 100
142
2b2581ee
MK
143int
144main(void)
145{
c12fd10d
MK
146 struct __sysctl_args args;
147 char osname[OSNAMESZ];
148 size_t osnamelth;
149 int name[] = { CTL_KERN, KERN_OSTYPE };
150
151 memset(&args, 0, sizeof(struct __sysctl_args));
152 args.name = name;
153 args.nlen = sizeof(name)/sizeof(name[0]);
154 args.oldval = osname;
155 args.oldlenp = &osnamelth;
988db661 156
2b2581ee 157 osnamelth = sizeof(osname);
988db661 158
29059a65 159 if (syscall(SYS__sysctl, &args) == \-1) {
c12fd10d
MK
160 perror("_sysctl");
161 exit(EXIT_FAILURE);
162 }
43940e36 163 printf("This machine is running %*s\\n", osnamelth, osname);
2b2581ee
MK
164 exit(EXIT_SUCCESS);
165}
166.fi
fea681da
MK
167.SH "SEE ALSO"
168.BR proc (5)