243 lines
7.1 KiB
HTML
243 lines
7.1 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of SYSCTL</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>SYSCTL</H1>
|
|
Section: Linux Programmer's Manual (2)<BR>Updated: 2020-02-09<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
sysctl - read/write system parameters
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/unistd.h">unistd.h</A>></B>
|
|
<B>#include <<A HREF="file:///usr/include/linux/sysctl.h">linux/sysctl.h</A>></B>
|
|
|
|
<B>int _sysctl(struct __sysctl_args *</B><I>args</I><B>);</B>
|
|
</PRE>
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
<B>This system call no longer exists on current kernels!</B>
|
|
|
|
See NOTES.
|
|
<P>
|
|
|
|
The
|
|
<B>_sysctl</B>()
|
|
|
|
call reads and/or writes kernel parameters.
|
|
For example, the hostname,
|
|
or the maximum number of open files.
|
|
The argument has the form
|
|
<P>
|
|
|
|
|
|
|
|
struct __sysctl_args {
|
|
<BR> int *name; /* integer vector describing variable */
|
|
<BR> int nlen; /* length of this vector */
|
|
<BR> void *oldval; /* 0 or address where to store old value */
|
|
<BR> size_t *oldlenp; /* available room for old value,
|
|
<BR> overwritten by actual size of old value */
|
|
<BR> void *newval; /* 0 or address of new value */
|
|
<BR> size_t newlen; /* size of new value */
|
|
};
|
|
|
|
|
|
<P>
|
|
|
|
This call does a search in a tree structure, possibly resembling
|
|
a directory tree under
|
|
<I>/proc/sys</I>,
|
|
|
|
and if the requested item is found calls some appropriate routine
|
|
to read or modify the value.
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
Upon successful completion,
|
|
<B>_sysctl</B>()
|
|
|
|
returns 0.
|
|
Otherwise, a value of -1 is returned and
|
|
<I>errno</I>
|
|
|
|
is set to indicate the error.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="1"><B>EACCES</B>, <B>EPERM</B>
|
|
|
|
<DD>
|
|
No search permission for one of the encountered "directories",
|
|
or no read permission where
|
|
<I>oldval</I>
|
|
|
|
was nonzero, or no write permission where
|
|
<I>newval</I>
|
|
|
|
was nonzero.
|
|
<DT id="2"><B>EFAULT</B>
|
|
|
|
<DD>
|
|
The invocation asked for the previous value by setting
|
|
<I>oldval</I>
|
|
|
|
non-NULL, but allowed zero room in
|
|
<I>oldlenp</I>.
|
|
|
|
<DT id="3"><B>ENOTDIR</B>
|
|
|
|
<DD>
|
|
<I>name</I>
|
|
|
|
was not found.
|
|
</DL>
|
|
<A NAME="lbAG"> </A>
|
|
<H2>VERSIONS</H2>
|
|
|
|
This system call first appeared in Linux 1.3.57.
|
|
It was removed in Linux 5.5.
|
|
<A NAME="lbAH"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
This call is Linux-specific, and should not be used in programs
|
|
intended to be portable.
|
|
It originated in
|
|
4.4BSD.
|
|
Only Linux has the
|
|
<I>/proc/sys</I>
|
|
|
|
mirror, and the object naming schemes differ between Linux and 4.4BSD,
|
|
but the declaration of the
|
|
<B>sysctl</B>()
|
|
|
|
function is the same in both.
|
|
<A NAME="lbAI"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
Use of this system call was long discouraged:
|
|
since Linux 2.6.24,
|
|
uses of this system call result in warnings in the kernel log,
|
|
and in Linux 5.5, the system call was finally removed.
|
|
Use the
|
|
<I>/proc/sys</I>
|
|
|
|
interface instead.
|
|
<P>
|
|
|
|
Note that on older kernels where this system call still exists,
|
|
it is available only if the kernel was configured with the
|
|
<B>CONFIG_SYSCTL_SYSCALL</B>
|
|
|
|
option.
|
|
Furthermore,
|
|
glibc does not provide a wrapper for this system call,
|
|
necessitating the use of
|
|
<B><A HREF="/cgi-bin/man/man2html?2+syscall">syscall</A></B>(2).
|
|
|
|
<P>
|
|
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>BUGS</H2>
|
|
|
|
The object names vary between kernel versions,
|
|
making this system call worthless for applications.
|
|
<P>
|
|
|
|
Not all available objects are properly documented.
|
|
<P>
|
|
|
|
It is not yet possible to change operating system by writing to
|
|
<I>/proc/sys/kernel/ostype</I>.
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H2>EXAMPLE</H2>
|
|
|
|
|
|
#define _GNU_SOURCE
|
|
#include <<A HREF="file:///usr/include/unistd.h">unistd.h</A>>
|
|
#include <<A HREF="file:///usr/include/sys/syscall.h">sys/syscall.h</A>>
|
|
#include <<A HREF="file:///usr/include/string.h">string.h</A>>
|
|
#include <<A HREF="file:///usr/include/stdio.h">stdio.h</A>>
|
|
#include <<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>>
|
|
#include <<A HREF="file:///usr/include/linux/sysctl.h">linux/sysctl.h</A>>
|
|
<P>
|
|
int _sysctl(struct __sysctl_args *args );
|
|
<P>
|
|
#define OSNAMESZ 100
|
|
<P>
|
|
int
|
|
main(void)
|
|
{
|
|
<BR> struct __sysctl_args args;
|
|
<BR> char osname[OSNAMESZ];
|
|
<BR> size_t osnamelth;
|
|
<BR> int name[] = { CTL_KERN, KERN_OSTYPE };
|
|
<P>
|
|
<BR> memset(&args, 0, sizeof(struct __sysctl_args));
|
|
<BR> args.name = name;
|
|
<BR> args.nlen = sizeof(name)/sizeof(name[0]);
|
|
<BR> args.oldval = osname;
|
|
<BR> args.oldlenp = &osnamelth;
|
|
<P>
|
|
<BR> osnamelth = sizeof(osname);
|
|
<P>
|
|
<BR> if (syscall(SYS__sysctl, &args) == -1) {
|
|
<BR> perror("_sysctl");
|
|
<BR> exit(EXIT_FAILURE);
|
|
<BR> }
|
|
<BR> printf("This machine is running %*s\n", osnamelth, osname);
|
|
<BR> exit(EXIT_SUCCESS);
|
|
}
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?5+proc">proc</A></B>(5)
|
|
|
|
<A NAME="lbAM"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="4"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="5"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="6"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="7"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="8"><A HREF="#lbAF">ERRORS</A><DD>
|
|
<DT id="9"><A HREF="#lbAG">VERSIONS</A><DD>
|
|
<DT id="10"><A HREF="#lbAH">CONFORMING TO</A><DD>
|
|
<DT id="11"><A HREF="#lbAI">NOTES</A><DD>
|
|
<DT id="12"><A HREF="#lbAJ">BUGS</A><DD>
|
|
<DT id="13"><A HREF="#lbAK">EXAMPLE</A><DD>
|
|
<DT id="14"><A HREF="#lbAL">SEE ALSO</A><DD>
|
|
<DT id="15"><A HREF="#lbAM">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:35 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|