OSDN Git Service

(split) LDP: Release pages for LDP v3.39.
[linuxjm/LDP_man-pages.git] / release / man2 / sysctl.2
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.
11 .\"
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.
19 .\"
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 .\"
28 .\"*******************************************************************
29 .\"
30 .\" This file was generated with po4a. Translate the source file.
31 .\"
32 .\"*******************************************************************
33 .TH SYSCTL 2 2008\-11\-20 Linux "Linux Programmer's Manual"
34 .SH 名前
35 sysctl \- システム・パラメーターを読み書きする
36 .SH 書式
37 .nf
38 \fB#include <unistd.h>\fP
39 .br
40 \fB#include <linux/sysctl.h>\fP
41 .sp
42 \fBint _sysctl(struct __sysctl_args *\fP\fIargs\fP\fB);\fP
43 .fi
44 .SH 説明
45 \fBこのシステムコールを使用しないこと!\fP 「注意」の節を参照。
46
47 \fB_sysctl\fP()  コールはカーネルパラメーターを読み書きする。例えば、 ホストネームや同時にオープンできるファイルの最大数など。
48 引き数は以下の形式である。
49 .PP
50 .in +4n
51 .nf
52 struct __sysctl_args {
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 */
60 };
61 .fi
62 .in
63 .PP
64 このコールは \fI/proc/sys\fP の下のディレクトリ・ツリーに似た木構造(tree structure)を検索する。
65 そして、要求された項目が見つかった場合は適切なルーチンを呼び出して 値を読んだり修正したりする。
66 .SH 返り値
67 成功した場合は \fB_sysctl\fP()  は 0 を返す。失敗した場合、\-1 が返され、 \fIerrno\fP がそのエラーを示す値に設定される。
68 .SH エラー
69 .TP 
70 \fBEFAULT\fP
71 \fIoldval\fP に NULL でない値を設定して、以前の値を要求しているのに、 \fIoldlenp\fP に空きがない。
72 .TP 
73 \fBENOTDIR\fP
74 \fIname\fP が見つからなかった。
75 .TP 
76 \fBEPERM\fP
77 「ディレクトリ」のどれかに検索許可がなかったか、 \fIoldval\fP が 0 でないのに読み込み許可がなかったか、 \fInewval\fP が 0
78 でないのに書き込み許可がなかった。
79 .SH 準拠
80 このコールは Linux 特有であり、移植を意図したプログラムで使用しては いけない。 \fBsysctl\fP()  コールは Linux のバージョン
81 1.3.57 から存在している。 これは 4.4BSD に由来している。Linux は \fI/proc/sys\fP
82 に写し(mirror)をもっており、項目の名前の付け方が Linux と 4.4BSD では 異っている。しかし \fBsysctl\fP()
83 関数の宣言は両方で同じである。
84 .SH 注意
85 glibc はこのシステムコールに対するラッパー関数を提供していない。 このシステムコールは呼び出すには \fBsyscall\fP(2)  を使うこと。
86
87 .\" See http://lwn.net/Articles/247243/
88 というよりは・・・このシステムコールを呼び出さないこと。 長い間このシステムコールの使用は非推奨とされており、
89 「将来のバージョンのカーネルで削除されるようだ」と言われるほどである。 あなたのプログラムにこのシステムコールがあれば、すぐにでも削除すること。
90 代わりに \fI/proc/sys\fP インターフェースを使用すること。
91 .SH バグ
92 オブジェクトの名前は、カーネルのバージョンごとに異なっている。 このため、このシステム・コールはアプリケーションにとって 無価値なものとなっている。
93 .PP
94 全ての可能な項目が正確に記述されているわけではない。
95 .PP
96 今のところ \fI/proc/sys/kernel/ostype\fP に書き込むことでオペーレーティング・システムを変えることはできない。
97 .SH 例
98 .nf
99 #define _GNU_SOURCE
100 #include <unistd.h>
101 #include <sys/syscall.h>
102 #include <string.h>
103 #include <stdio.h>
104 #include <stdlib.h>
105 #include <linux/sysctl.h>
106
107 int _sysctl(struct __sysctl_args *args );
108
109 #define OSNAMESZ 100
110
111 int
112 main(void)
113 {
114     struct __sysctl_args args;
115     char osname[OSNAMESZ];
116     size_t osnamelth;
117     int name[] = { CTL_KERN, KERN_OSTYPE };
118
119     memset(&args, 0, sizeof(struct __sysctl_args));
120     args.name = name;
121     args.nlen = sizeof(name)/sizeof(name[0]);
122     args.oldval = osname;
123     args.oldlenp = &osnamelth;
124
125     osnamelth = sizeof(osname);
126
127     if (syscall(SYS__sysctl, &args) == \-1) {
128         perror("_sysctl");
129         exit(EXIT_FAILURE);
130     }
131     printf("This machine is running %*s\en", osnamelth, osname);
132     exit(EXIT_SUCCESS);
133 }
134 .fi
135 .SH 関連項目
136 \fBproc\fP(5)