OSDN Git Service

(split) LDP: draft snapshot generated from latest ja.po files.
[linuxjm/LDP_man-pages.git] / draft / man3 / getutent.3
1 .\" Copyright 1995 Mark D. Roth (roth@uiuc.edu)
2 .\"
3 .\" This is free documentation; you can redistribute it and/or
4 .\" modify it under the terms of the GNU General Public License as
5 .\" published by the Free Software Foundation; either version 2 of
6 .\" the License, or (at your option) any later version.
7 .\"
8 .\" The GNU General Public License's references to "object code"
9 .\" and "executables" are to be interpreted as the output of any
10 .\" document formatting or typesetting system, including
11 .\" intermediate and printed output.
12 .\"
13 .\" This manual is distributed in the hope that it will be useful,
14 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
15 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 .\" GNU General Public License for more details.
17 .\"
18 .\" You should have received a copy of the GNU General Public
19 .\" License along with this manual; if not, write to the Free
20 .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111,
21 .\" USA.
22 .\"
23 .\" References consulted:
24 .\"     Linux libc source code
25 .\"     Solaris manpages
26 .\"
27 .\" Modified Thu Jul 25 14:43:46 MET DST 1996 by Michael Haardt
28 .\"     <michael@cantor.informatik.rwth-aachen.de>
29 .\"
30 .\"*******************************************************************
31 .\"
32 .\" This file was generated with po4a. Translate the source file.
33 .\"
34 .\"*******************************************************************
35 .TH GETUTENT 3 2008\-06\-29 "" "Linux Programmer's Manual"
36 .SH 名前
37 getutent, getutid, getutline, pututline, setutent, endutent, utmpname \- utmp
38 ファイルのエントリにアクセスする
39 .SH 書式
40 \fB#include <utmp.h>\fP
41 .sp
42 \fBstruct utmp *getutent(void);\fP
43 .br
44 \fBstruct utmp *getutid(struct utmp *\fP\fIut\fP\fB);\fP
45 .br
46 \fBstruct utmp *getutline(struct utmp *\fP\fIut\fP\fB);\fP
47 .sp
48 \fBstruct utmp *pututline(struct utmp *\fP\fIut\fP\fB);\fP
49 .sp
50 \fBvoid setutent(void);\fP
51 .br
52 \fBvoid endutent(void);\fP
53 .sp
54 \fBint utmpname(const char *\fP\fIfile\fP\fB);\fP
55 .SH 説明
56 新しいアプリケーションでは、これらの関数の "utmpx" 版を使用すべきである。 これらは POSIX.1 で規定されている。「準拠」の節を参照。
57
58 \fButmpname\fP()  は、他の utmp 関数がアクセスする (utmp フォーマットの)  ファイルの名前を指定する。他の関数を使う前に
59 \fButmpname\fP()  を使って ファイル名の指定を行わなかった場合は、 \fI<path.h>\fP で 定義されている
60 \fB_PATH_UTMP\fP がファイル名とみなされる。
61 .PP
62 \fBsetutent\fP()  は、ファイルポインタを utmp ファイルの先頭に移動する。
63 一般的には、他の関数を使う前にこの関数を呼び出しておくと良いだろう。
64 .PP
65 \fBendutent\fP()  は utmp ファイルをクローズする。ユーザーコードで
66 他の関数を使ってこのファイルにアクセスを行った時は、最後にこの関数を 呼び出すべきである。
67 .PP
68 \fBgetutent\fP()  は utmp ファイルの現在のファイル位置から一行読み込み、 行の各フィールドの内容を収めた構造体へのポインタを返す。
69 この構造体の定義は \fButmp\fP(5)  に書かれている。
70 .PP
71 \fBgetutid\fP()  は、 utmp ファイル中の現在の位置から順方向 (末尾に向かう方向) へ \fIut\fP に基く検索を行う。
72 \fIut\fP\->ut_type が \fBRUN_LVL\fP, \fBBOOT_TIME\fP, \fBNEW_TIME\fP, \fBOLD_TIME\fP の
73 いずれかなら、 \fBgetutid\fP()  は \fBut_type\fP フィールドが \fIut\fP\->ut_type
74 に一致する最初のエントリを探す。 \fIut\fP\->ut_type が \fBINIT_PROCESS\fP, \fBLOGIN_PROCESS\fP,
75 \fBUSER_PROCESS\fP, \fBDEAD_PROCESS\fP のいずれかなら、 \fBgetutid\fP()  は \fIut_id\fP フィールドが
76 \fIut\fP\->ut_id に 一致する最初のエントリを探す。
77 .PP
78 \fBgetutline\fP()  は、 utmp ファイルの現在の位置から末尾に向かって検索を行う。 \fIut_type\fP が
79 \fBUSER_PROCESS\fP または \fBLOGIN_PROCESS\fP で、 \fIut_line\fP フィールドが \fIut\fP\->ut_line
80 にマッチする最初の行を返す。
81 .PP
82 \fBpututline\fP()  は \fIutmp\fP 構造体 \fIut\fP の内容を utmp ファイルに書き出す。 \fBpututline\fP()  は
83 \fBgetutid\fP()  を用いて、新たなエントリを 挿入するのにふさわしい場所を探す。 \fIut\fP を挿入するふさわしい場所が
84 見つからない場合は、新たなエントリをファイルの末尾に追加する。
85 .SH 返り値
86 \fBgetutent\fP(), \fBgetutid\fP(), \fBgetutline\fP()  は、成功すると \fIstruct utmp\fP
87 へのポインタを返す。 失敗すると NULL を返す (レコードが見つからなかった場合も失敗となる)。 この \fIstruct utmp\fP
88 は静的な記憶領域に確保され、次にこれらの関数を 呼び出した際に上書きされるかもしれない。
89
90 \fBpututline\fP()  は成功すると \fIut\fP を返す。失敗すると NULL を返す。
91
92 \fButmpname\fP()  は、新しい名前の格納に成功すると 0 を返し、失敗すると \-1 を返す。
93 .SH エラー
94 .TP 
95 \fBENOMEM\fP
96 メモリ不足。
97 .TP 
98 \fBESRCH\fP
99 レコードが見つからなかった。
100 .PP
101 関数 \fBsetutent\fP(), \fBpututline\fP(), \fBgetut*\fP()  は \fBopen\fP(2)
102 に書かれている理由でも失敗することがある。
103 .SH ファイル
104 /var/run/utmp 現在ログイン中のユーザーのデータベース
105 .br
106 /var/log/wtmp 過去のユーザーログインのデータベース
107 .SH 準拠
108 XPG2, SVr4.
109 .LP
110 XPG2 と SVID 2 では、 \fBpututline\fP()  関数は値を返さないとされており、 (AIX, HP\-UX, Linux libc5
111 などの) 多くのシステムではそうなっている。 HP\-UX では、上述の \fBpututline\fP()  と同じプロトタイプを持つ 新しい関数
112 \fB_pututline\fP()  が導入されている (この関数は Linux libc5 にもある)。
113 .LP
114 現在では、Linux 以外のシステムでは、これらの関数は全て廃止されている。 SUSv1 の後に出てきた POSIX.1\-2001
115 では、もはやこれらの関数はなく、 代わりに以下のものを使う。
116 .sp
117 \fB#include <utmpx.h>\fP
118 .sp
119 \fBstruct utmpx *getutxent(void);\fP
120 .br
121 \fBstruct utmpx *getutxid(const struct utmpx *);\fP
122 .br
123 \fBstruct utmpx *getutxline(const struct utmpx *);\fP
124 .br
125 \fBstruct utmpx *pututxline(const struct utmpx *);\fP
126 .br
127 \fBvoid setutxent(void);\fP
128 .br
129 \fBvoid endutxent(void);\fP
130 .PP
131 これらの関数は glibc により提供されており、 "x" がない関数と同じ処理を行うが、 \fIstruct utmpx\fP を使用する。 Linux
132 では、この構造体の定義は \fIstruct utmp\fP と同じになっている。 完全を期すために、glibc では \fButmpxname\fP()
133 も提供している。この関数は POSIX.1 では規定されていない。
134 .PP
135 Linux 以外のシステムでは、 \fIutmpx\fP 構造体は \fIutmp\fP 構造体の上位集合 (superset) になっていて、
136 追加のフィールドがあったり、既存のフィールドのサイズが大きくなっていたり するものもある。複数のファイルが使用されている場合もあり、多くの場合
137 \fI/var/*/utmpx\fP と \fI/var/*/wtmpx\fP というファイルが使われる。
138 .LP
139 一方、 Linux glibc では複数の \fIutmpx\fP ファイル は使われていない。 \fIutmp\fP 構造体が十分に大きいからである。
140 \fIgetutxent\fP() などの関数は \fIgetutent\fP() などの別名となっている。
141 .SH 注意
142 .SS "glibc での注意"
143 上記の関数群はスレッド・セーフではない。 glibc にはリエントラント版 (reentrant) が追加されている。
144 .sp
145 .nf
146 \fB#define _GNU_SOURCE\fP    /* or _SVID_SOURCE or _BSD_SOURCE;
147 \&                          \fBfeature_test_macros(7)\fP 参照 */
148 \fB#include <utmp.h>\fP
149 .sp
150 \fBint getutent_r(struct utmp *\fP\fIubuf\fP\fB, struct utmp **\fP\fIubufp\fP\fB);\fP
151 .sp
152 \fBint getutid_r(struct utmp *\fP\fIut\fP\fB,\fP
153 \fB              struct utmp *\fP\fIubuf\fP\fB, struct utmp **\fP\fIubufp\fP\fB);\fP
154 .sp
155 \fBint getutline_r(struct utmp *\fP\fIut\fP\fB,\fP
156 \fB                struct utmp *\fP\fIubuf\fP\fB, struct utmp **\fP\fIubufp\fP\fB);\fP
157 .fi
158 .sp
159 これらの関数は GNU での拡張であり、末尾の _r をとった名前の関数と 同様の機能を持つ。 \fIubuf\fP
160 パラメータは結果を格納する場所を指定する。 成功すると 0 を返し、結果へのポインタを \fI*ubufp\fP に書き込む。エラーの場合 \-1 を返す。
161 上記の関数に対応する utmpx 版は存在しない (POSIX.1 ではこれらの関数を規定されていない)。
162 .SH 例
163 以下の例では、 utmp のレコードの追加・削除を行っている。このコードは、 擬似端末 (pseudo terminal)
164 から実行されることを想定している。 実際のアプリケーションでは \fBgetpwuid\fP(3)  と \fBttyname\fP(3)
165 の戻り値を検査するべきである。
166 .PP
167 .nf
168 #include <string.h>
169 #include <stdlib.h>
170 #include <pwd.h>
171 #include <unistd.h>
172 #include <utmp.h>
173
174 int
175 main(int argc, char *argv[])
176 {
177     struct utmp entry;
178
179     system("echo before adding entry:;who");
180
181     entry.ut_type = USER_PROCESS;
182     entry.ut_pid = getpid();
183     strcpy(entry.ut_line, ttyname(STDIN_FILENO) + strlen("/dev/"));
184     /* only correct for ptys named /dev/tty[pqr][0\-9a\-z] */
185     strcpy(entry.ut_id, ttyname(STDIN_FILENO) + strlen("/dev/tty"));
186     time(&entry.ut_time);
187     strcpy(entry.ut_user, getpwuid(getuid())\->pw_name);
188     memset(entry.ut_host, 0, UT_HOSTSIZE);
189     entry.ut_addr = 0;
190     setutent();
191     pututline(&entry);
192
193     system("echo after adding entry:;who");
194
195     entry.ut_type = DEAD_PROCESS;
196     memset(entry.ut_line, 0, UT_LINESIZE);
197     entry.ut_time = 0;
198     memset(entry.ut_user, 0, UT_NAMESIZE);
199     setutent();
200     pututline(&entry);
201
202     system("echo after removing entry:;who");
203
204     endutent();
205     exit(EXIT_SUCCESS);
206 }
207 .fi
208 .SH 関連項目
209 \fBgetutmp\fP(3), \fButmp\fP(5)