Blame man2/sysctl.2

Packit 7cfc04
.\" Copyright (C) 1996 Andries Brouwer (aeb@cwi.nl)
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(VERBATIM)
Packit 7cfc04
.\" Permission is granted to make and distribute verbatim copies of this
Packit 7cfc04
.\" manual provided the copyright notice and this permission notice are
Packit 7cfc04
.\" preserved on all copies.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Permission is granted to copy and distribute modified versions of this
Packit 7cfc04
.\" manual under the conditions for verbatim copying, provided that the
Packit 7cfc04
.\" entire resulting derived work is distributed under the terms of a
Packit 7cfc04
.\" permission notice identical to this one.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Since the Linux kernel and libraries are constantly changing, this
Packit 7cfc04
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
Packit 7cfc04
.\" responsibility for errors or omissions, or for damages resulting from
Packit 7cfc04
.\" the use of the information contained herein.  The author(s) may not
Packit 7cfc04
.\" have taken the same level of care in the production of this manual,
Packit 7cfc04
.\" which is licensed free of charge, as they might when working
Packit 7cfc04
.\" professionally.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Formatted or processed versions of this manual, if unaccompanied by
Packit 7cfc04
.\" the source, must acknowledge the copyright and authors of this work.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\" Written 11 April 1996 by Andries Brouwer <aeb@cwi.nl>
Packit 7cfc04
.\" 960412: Added comments from Stephen Tweedie
Packit 7cfc04
.\" Modified Tue Oct 22 22:28:41 1996 by Eric S. Raymond <esr@thyrsus.com>
Packit 7cfc04
.\" Modified Mon Jan  5 20:31:04 1998 by aeb.
Packit 7cfc04
.\"
Packit 7cfc04
.TH SYSCTL 2 2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
sysctl \- read/write system parameters
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.nf
Packit 7cfc04
.B #include <unistd.h>
Packit 7cfc04
.B #include <linux/sysctl.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int _sysctl(struct __sysctl_args *" args );
Packit 7cfc04
.fi
Packit 7cfc04
.PP
Packit 7cfc04
.IR Note :
Packit 7cfc04
There is no glibc wrapper for this system call; see NOTES.
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
.B Do not use this system call!
Packit 7cfc04
See NOTES.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.BR _sysctl ()
Packit 7cfc04
call reads and/or writes kernel parameters.
Packit 7cfc04
For example, the hostname,
Packit 7cfc04
or the maximum number of open files.
Packit 7cfc04
The argument has the form
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
struct __sysctl_args {
Packit 7cfc04
    int    *name;    /* integer vector describing variable */
Packit 7cfc04
    int     nlen;    /* length of this vector */
Packit 7cfc04
    void   *oldval;  /* 0 or address where to store old value */
Packit 7cfc04
    size_t *oldlenp; /* available room for old value,
Packit 7cfc04
                        overwritten by actual size of old value */
Packit 7cfc04
    void   *newval;  /* 0 or address of new value */
Packit 7cfc04
    size_t  newlen;  /* size of new value */
Packit 7cfc04
};
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
This call does a search in a tree structure, possibly resembling
Packit 7cfc04
a directory tree under
Packit 7cfc04
.IR /proc/sys ,
Packit 7cfc04
and if the requested item is found calls some appropriate routine
Packit 7cfc04
to read or modify the value.
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
Upon successful completion,
Packit 7cfc04
.BR _sysctl ()
Packit 7cfc04
returns 0.
Packit 7cfc04
Otherwise, a value of \-1 is returned and
Packit 7cfc04
.I errno
Packit 7cfc04
is set to indicate the error.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
.TP
Packit 7cfc04
.BR EACCES ", " EPERM
Packit 7cfc04
No search permission for one of the encountered "directories",
Packit 7cfc04
or no read permission where
Packit 7cfc04
.I oldval
Packit 7cfc04
was nonzero, or no write permission where
Packit 7cfc04
.I newval
Packit 7cfc04
was nonzero.
Packit 7cfc04
.TP
Packit 7cfc04
.B EFAULT
Packit 7cfc04
The invocation asked for the previous value by setting
Packit 7cfc04
.I oldval
Packit 7cfc04
non-NULL, but allowed zero room in
Packit 7cfc04
.IR oldlenp .
Packit 7cfc04
.TP
Packit 7cfc04
.B ENOTDIR
Packit 7cfc04
.I name
Packit 7cfc04
was not found.
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
This call is Linux-specific, and should not be used in programs
Packit 7cfc04
intended to be portable.
Packit 7cfc04
A
Packit 7cfc04
.BR sysctl ()
Packit 7cfc04
call has been present in Linux since version 1.3.57.
Packit 7cfc04
It originated in
Packit 7cfc04
4.4BSD.
Packit 7cfc04
Only Linux has the
Packit 7cfc04
.I /proc/sys
Packit 7cfc04
mirror, and the object naming schemes differ between Linux and 4.4BSD,
Packit 7cfc04
but the declaration of the
Packit 7cfc04
.BR sysctl ()
Packit 7cfc04
function is the same in both.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
Glibc does not provide a wrapper for this system call; call it using
Packit 7cfc04
.BR syscall (2).
Packit 7cfc04
Or rather...
Packit 7cfc04
.I don't
Packit 7cfc04
call it:
Packit 7cfc04
use of this system call has long been discouraged,
Packit 7cfc04
and it is so unloved that
Packit 7cfc04
\fBit is likely to disappear in a future kernel version\fP.
Packit 7cfc04
.\" See http://lwn.net/Articles/247243/
Packit 7cfc04
Since Linux 2.6.24,
Packit 7cfc04
uses of this system call result in warnings in the kernel log.
Packit 7cfc04
.\" Though comments in suggest that it is needed by old glibc binaries,
Packit 7cfc04
.\" so maybe it's not going away.
Packit 7cfc04
Remove it from your programs now; use the
Packit 7cfc04
.I /proc/sys
Packit 7cfc04
interface instead.
Packit 7cfc04
.PP
Packit 7cfc04
This system call is available only if the kernel was configured with the
Packit 7cfc04
.B CONFIG_SYSCTL_SYSCALL
Packit 7cfc04
option.
Packit 7cfc04
.SH BUGS
Packit 7cfc04
The object names vary between kernel versions,
Packit 7cfc04
making this system call worthless for applications.
Packit 7cfc04
.PP
Packit 7cfc04
Not all available objects are properly documented.
Packit 7cfc04
.PP
Packit 7cfc04
It is not yet possible to change operating system by writing to
Packit 7cfc04
.IR /proc/sys/kernel/ostype .
Packit 7cfc04
.SH EXAMPLE
Packit 7cfc04
.EX
Packit 7cfc04
#define _GNU_SOURCE
Packit 7cfc04
#include <unistd.h>
Packit 7cfc04
#include <sys/syscall.h>
Packit 7cfc04
#include <string.h>
Packit 7cfc04
#include <stdio.h>
Packit 7cfc04
#include <stdlib.h>
Packit 7cfc04
#include <linux/sysctl.h>
Packit 7cfc04
Packit 7cfc04
int _sysctl(struct __sysctl_args *args );
Packit 7cfc04
Packit 7cfc04
#define OSNAMESZ 100
Packit 7cfc04
Packit 7cfc04
int
Packit 7cfc04
main(void)
Packit 7cfc04
{
Packit 7cfc04
    struct __sysctl_args args;
Packit 7cfc04
    char osname[OSNAMESZ];
Packit 7cfc04
    size_t osnamelth;
Packit 7cfc04
    int name[] = { CTL_KERN, KERN_OSTYPE };
Packit 7cfc04
Packit 7cfc04
    memset(&args, 0, sizeof(struct __sysctl_args));
Packit 7cfc04
    args.name = name;
Packit 7cfc04
    args.nlen = sizeof(name)/sizeof(name[0]);
Packit 7cfc04
    args.oldval = osname;
Packit 7cfc04
    args.oldlenp = &osnamelth;
Packit 7cfc04
Packit 7cfc04
    osnamelth = sizeof(osname);
Packit 7cfc04
Packit 7cfc04
    if (syscall(SYS__sysctl, &args) == \-1) {
Packit 7cfc04
        perror("_sysctl");
Packit 7cfc04
        exit(EXIT_FAILURE);
Packit 7cfc04
    }
Packit 7cfc04
    printf("This machine is running %*s\\n", osnamelth, osname);
Packit 7cfc04
    exit(EXIT_SUCCESS);
Packit 7cfc04
}
Packit 7cfc04
.EE
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR proc (5)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.