.\" Copyright (C) 1996 Andries Brouwer (aeb@cwi.nl) .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\" Written 11 April 1996 by Andries Brouwer .\" 960412: Added comments from Stephen Tweedie .\" Modified Tue Oct 22 22:28:41 1996 by Eric S. Raymond .\" Modified Mon Jan 5 20:31:04 1998 by aeb. .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 1997-1998 HANATAKA Shinya .\" all rights reserved. .\" Translated 1997-12-12, HANATAKA Shinya .\" Modified 1998-05-11, HANATAKA Shinya .\" Updated 2007-10-11, Akihiro MOTOKI , LDP v2.66 .\" Updated 2013-05-01, Akihiro MOTOKI .\" .TH SYSCTL 2 2012\-12\-22 Linux "Linux Programmer's Manual" .SH 名前 sysctl \- システムパラメーターを読み書きする .SH 書式 .nf \fB#include \fP .br \fB#include \fP .sp \fBint _sysctl(struct __sysctl_args *\fP\fIargs\fP\fB);\fP .fi \fI注\fP: このシステムコールには glibc のラッパー関数は存在しない。「注意」の節を参照。 .SH 説明 \fBこのシステムコールを使用しないこと!\fP 「注意」の節を参照。 \fB_sysctl\fP() コールはカーネルパラメーターを読み書きする。例えば、 ホストネームや同時にオープンできるファイルの最大数など。 引き数は以下の形式である。 .PP .in +4n .nf 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 */ }; .fi .in .PP このコールは \fI/proc/sys\fP の下のディレクトリツリーに似た木構造(tree structure)を検索する。 そして、要求された項目が見つかった場合は適切なルーチンを呼び出して 値を読んだり修正したりする。 .SH 返り値 成功した場合は \fB_sysctl\fP() は 0 を返す。失敗した場合、\-1 が返され、 \fIerrno\fP がそのエラーを示す値に設定される。 .SH エラー .TP \fBEFAULT\fP \fIoldval\fP に NULL でない値を設定して、以前の値を要求しているのに、 \fIoldlenp\fP に空きがない。 .TP \fBENOTDIR\fP \fIname\fP が見つからなかった。 .TP \fBEACCES\fP か \fBEPERM\fP 「ディレクトリ」のどれかに検索許可がなかったか、 \fIoldval\fP が 0 でないのに読み込み許可がなかったか、 \fInewval\fP が 0 でないのに書き込み許可がなかった。 .SH 準拠 このコールは Linux 特有であり、移植を意図したプログラムで使用しては いけない。 \fBsysctl\fP() コールは Linux のバージョン 1.3.57 から存在している。 これは 4.4BSD に由来している。Linux は \fI/proc/sys\fP に写し(mirror)をもっており、項目の名前の付け方が Linux と 4.4BSD では 異っている。しかし \fBsysctl\fP() 関数の宣言は両方で同じである。 .SH 注意 .\" See http://lwn.net/Articles/247243/ .\" Though comments in suggest that it is needed by old glibc binaries, .\" so maybe it's not going away. glibc はこのシステムコールに対するラッパー関数を提供していない。 \fBsyscall\fP(2) を使って呼び出すこと。というよりは・・・このシステムコールを呼び出さないこと。 長い間このシステムコールの使用は非推奨とされており、 「将来のバージョンのカーネルで削除されるようだ」と言われるほどである。 あなたのプログラムにこのシステムコールがあれば、すぐにでも削除すること。 代わりに \fI/proc/sys\fP インターフェースを使用すること。 このシステムコールは、カーネルの \fBCONFIG_SYSCTL_SYSCALL\fP オプションが有効になっている場合のみ利用できる。 .SH バグ オブジェクトの名前は、カーネルのバージョンごとに異なっている。 このため、このシステムコールはアプリケーションにとって 無価値なものとなっている。 .PP 全ての可能な項目が正確に記述されているわけではない。 .PP 今のところ \fI/proc/sys/kernel/ostype\fP に書き込むことでオペーレーティングシステムを変えることはできない。 .SH 例 .nf #define _GNU_SOURCE #include #include #include #include #include #include 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(struct __sysctl_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\en", osnamelth, osname); exit(EXIT_SUCCESS); } .fi .SH 関連項目 \fBproc\fP(5) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。