Man page - _sysctl(2)

Packages contains this manual

Available languages:

en fr pl ja ru ro de

Manual

SYSCTL

名 前
書 式
説 明
返 り 値
エ ラ ー
バ ー ジ ョ ン
準 拠
注 意
バ グ

関 連 項 目
こ の 文 書 に つ い て

名 前

sysctl - シ ス テ ム パ ラ メ ー タ ー を 読 み 書 き す る

書 式

#include <unistd.h>
#include <linux/sysctl.h>

int _sysctl(struct __sysctl_args * args );

説 明

This system call no longer exists on current kernels! See NOTES.

_sysctl () コ ー ル は カ ー ネ ル パ ラ メ ー タ ー を 読 み 書 き す る 。 例 え ば 、 ホ ス ト ネ ー ム や 同 時 に オ ー プ ン で き る フ ァ イ ル の 最 大 数 な ど 。 引 数 は 以 下 の 形 式 で あ る 。

struct __sysctl_args {
int *name; /* integer vector describing variable */
int nlen; /* length of this vector */
void *oldval; /* 0 or address where to store old value */
size_t *oldlenp; /* available room for old value,
overwritten by actual size of old value */
void *newval; /* 0 or address of new value */
size_t newlen; /* size of new value */
};

こ の コ ー ル は /proc/sys の 下 の デ ィ レ ク ト リ ツ リ ー に 似 た 木 構 造 (tree structure)を 検 索 す る 。 そ し て 、 要 求 さ れ た 項 目 が 見 つ か っ た 場 合 は 適 切 な ル ー チ ン を 呼 び 出 し て 値 を 読 ん だ り 修 正 し た り す る 。

返 り 値

成 功 し た 場 合 は _sysctl () は 0 を 返 す 。 失 敗 し た 場 合 、 -1 が 返 さ れ 、 errno が そ の エ ラ ー を 示 す 値 に 設 定 さ れ る 。

エ ラ ー

EACCES EPERM

「 デ ィ レ ク ト リ 」 の ど れ か に 検 索 許 可 が な か っ た か 、 oldval が 0 で な い の に 読 み 込 み 許 可 が な か っ た か 、 newval が 0 で な い の に 書 き 込 み 許 可 が な か っ た 。

EFAULT

oldval に NULL で な い 値 を 設 定 し て 、 以 前 の 値 を 要 求 し て い る の に 、 oldlenp に 空 き が な い 。

ENOTDIR

name が 見 つ か ら な か っ た 。

バ ー ジ ョ ン

This system call first appeared in Linux 1.3.57. It was removed in Linux 5.5; glibc support was removed in version 2.32.

準 拠

こ の コ ー ル は Linux 特 有 で あ り 、 移 植 を 意 図 し た プ ロ グ ラ ム で 使 用 し て は い け な い 。 こ れ は 4.4BSD に 由 来 し て い る 。 Linux は /proc/sys に 写 し (mirror)を も っ て お り 、 項 目 の 名 前 の 付 け 方 が Linux と 4.4BSD で は 異 っ て い る 。 し か し sysctl () 関 数 の 宣 言 は 両 方 で 同 じ で あ る 。

注 意

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 /proc/sys interface instead.

Note that on older kernels where this system call still exists, it is available only if the kernel was configured with the CONFIG_SYSCTL_SYSCALL option. Furthermore, glibc does not provide a wrapper for this system call, necessitating the use of syscall (2).

バ グ

オ ブ ジ ェ ク ト の 名 前 は 、 カ ー ネ ル の バ ー ジ ョ ン ご と に 異 な っ て い る 。 こ の た め 、 こ の シ ス テ ム コ ー ル は ア プ リ ケ ー シ ョ ン に と っ て 無 価 値 な も の と な っ て い る 。

全 て の 可 能 な 項 目 が 正 確 に 記 述 さ れ て い る わ け で は な い 。

今 の と こ ろ /proc/sys/kernel/ostype に 書 き 込 む こ と で オ ペ ー レ ー テ ィ ン グ シ ス テ ム を 変 え る こ と は で き な い 。

#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <linux/sysctl.h>

int _sysctl(struct __sysctl_args *args );

#define OSNAMESZ 100

int
main(void)
{
struct __sysctl_args args;
char osname[OSNAMESZ];
size_t osnamelth;
int name[] = { CTL_KERN, KERN_OSTYPE };

memset(&args, 0, sizeof(args));
args.name = name;
args.nlen = sizeof(name)/sizeof(name[0]);
args.oldval = osname;
args.oldlenp = &osnamelth;

osnamelth = sizeof(osname);

if (syscall(SYS__sysctl, &args) == -1) {
perror("_sysctl");
exit(EXIT_FAILURE);
}
printf("This machine is running %*s\n", osnamelth, osname);
exit(EXIT_SUCCESS);
}

関 連 項 目

proc (5)

こ の 文 書 に つ い て

こ の man ペ ー ジ は Linux man-pages プ ロ ジ ェ ク ト の リ リ ー ス 5.10 の 一 部 で あ る 。 プ ロ ジ ェ ク ト の 説 明 と バ グ 報 告 に 関 す る 情 報 は https://www.kernel.org/doc/man-pages/ に 書 か れ て い る 。