OSDN Git Service

Convert release and draft pages to UTF-8.
[linuxjm/jm.git] / manual / LDP_man-pages / 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 .\" Japanese Version Copyright (c) 1997-1998 HANATAKA Shinya
29 .\"         all rights reserved.
30 .\" Translated 1997-12-12, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
31 .\" Modified 1998-05-11, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
32 .\" Updated 2007-10-11, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.66
33 .\"
34 .\"WORD:        parameter               パラメーター
35 .\"WORD:        kernel                  カーネル
36 .\"WORD:        hostname                ホストネーム
37 .\"WORD:        open                    オープン
38 .\"WORD:        directory               ディレクトリ
39 .\"WORD:        tree                    ツリー
40 .\"
41 .TH SYSCTL 2 2008-11-20 "Linux" "Linux Programmer's Manual"
42 .SH 名前
43 sysctl \- システム・パラメーターを読み書きする
44 .SH 書式
45 .nf
46 .B #include <unistd.h>
47 .br
48 .B #include <linux/sysctl.h>
49 .sp
50 .BI "int _sysctl(struct __sysctl_args *" args );
51 .fi
52 .SH 説明
53 .B このシステムコールを使用しないこと!
54 「注意」の節を参照。
55
56 .BR _sysctl ()
57 コールはカーネルパラメーターを読み書きする。例えば、
58 ホストネームや同時にオープンできるファイルの最大数など。
59 引き数は以下の形式である。
60 .PP
61 .in +4n
62 .nf
63 struct __sysctl_args {
64     int    *name;    /* integer vector describing variable */
65     int     nlen;    /* length of this vector */
66     void   *oldval;  /* 0 or address where to store old value */
67     size_t *oldlenp; /* available room for old value,
68                         overwritten by actual size of old value */
69     void   *newval;  /* 0 or address of new value */
70     size_t  newlen;  /* size of new value */
71 };
72 .fi
73 .in
74 .PP
75 このコールは
76 .I /proc/sys
77 の下のディレクトリ・ツリーに似た木構造(tree structure)を検索する。
78 そして、要求された項目が見つかった場合は適切なルーチンを呼び出して
79 値を読んだり修正したりする。
80 .SH 返り値
81 成功した場合は
82 .BR _sysctl ()
83 は 0 を返す。失敗した場合、\-1 が返され、
84 .I errno
85 がそのエラーを示す値に設定される。
86 .SH エラー
87 .TP
88 .B EFAULT
89 .I oldval
90 に NULL でない値を設定して、以前の値を要求しているのに、
91 .I oldlenp
92 に空きがない。
93 .TP
94 .B ENOTDIR
95 .I name
96 が見つからなかった。
97 .TP
98 .B EPERM
99 「ディレクトリ」のどれかに検索許可がなかったか、
100 .I oldval
101 が 0 でないのに読み込み許可がなかったか、
102 .I newval
103 が 0 でないのに書き込み許可がなかった。
104 .SH 準拠
105 このコールは Linux 特有であり、移植を意図したプログラムで使用しては
106 いけない。
107 .SH 歴史
108 .BR sysctl ()
109 コールは
110 Linux のバージョン 1.3.57 から存在している。
111 これは 4.4BSD に由来している。Linux は
112 .I /proc/sys
113 に写し(mirror)をもっており、項目の名前の付け方が Linux と 4.4BSD では
114 異っている。しかし
115 .BR sysctl ()
116 関数の宣言は両方で同じである。
117 .SH 注意
118 glibc はこのシステムコールに対するラッパー関数を提供していない。
119 .BR syscall (2)
120 を使って呼び出すこと。
121
122 というよりは・・・このシステムコールを呼び出さないこと。
123 長い間このシステムコールの使用は非推奨とされており、
124 「将来のバージョンのカーネルで削除されるようだ」と言われるほどである。
125 .\" http://lwn.net/Articles/247243/ 参照
126 あなたのプログラムにこのシステムコールがあれば、すぐにでも削除すること。
127 代わりに
128 .I /proc/sys
129 インターフェースを使用すること。
130 .SH バグ
131 オブジェクトの名前は、カーネルのバージョンごとに異なっている。
132 このため、このシステム・コールはアプリケーションにとって
133 無価値なものとなっている。
134 .PP
135 全ての可能な項目が正確に記述されているわけではない。
136 .PP
137 今のところ
138 .I /proc/sys/kernel/ostype
139 に書き込むことでオペーレーティング・システムを変えることはできない。
140 .SH 例
141 .nf
142 #define _GNU_SOURCE
143 #include <unistd.h>
144 #include <sys/syscall.h>
145 #include <string.h>
146 #include <stdio.h>
147 #include <stdlib.h>
148 #include <linux/sysctl.h>
149
150 int _sysctl(struct __sysctl_args *args );
151
152 #define OSNAMESZ 100
153
154 int
155 main(void)
156 {
157     struct __sysctl_args args;
158     char osname[OSNAMESZ];
159     size_t osnamelth;
160     int name[] = { CTL_KERN, KERN_OSTYPE };
161
162     memset(&args, 0, sizeof(struct __sysctl_args));
163     args.name = name;
164     args.nlen = sizeof(name)/sizeof(name[0]);
165     args.oldval = osname;
166     args.oldlenp = &osnamelth;
167
168     osnamelth = sizeof(osname);
169
170     if (syscall(SYS__sysctl, &args) == \-1) {
171         perror("_sysctl");
172         exit(EXIT_FAILURE);
173     }
174     printf("This machine is running %*s\\n", osnamelth, osname);
175     exit(EXIT_SUCCESS);
176 }
177 .fi
178 .SH 関連項目
179 .BR proc (5)