OSDN Git Service

3ac5b30926a5610d6269ffd3968672b7f0e65c5a
[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 .\" Japanese Version Copyright (c) 1998 NAKANO Takeo all rights reserved.
31 .\" Translated 1998-03-15, NAKANO Takeo <nakano@apm.seikei.ac.jp>
32 .\" Updated 2001-10-16, Kentaro Shirakata <argrath@ub32.org>
33 .\" Updated 2002-01-03, Kentaro Shirakata <argrath@ub32.org>
34 .\" Updated 2005-03-18, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
35 .\" Updated 2008-08-11, Akihiro MOTOKI, LDP v3.05
36 .\"
37 .TH GETUTENT 3 2008-06-29 "" "Linux Programmer's Manual"
38 .\"O .SH NAME
39 .SH 名前
40 .\"O getutent, getutid, getutline, pututline, setutent, endutent,
41 .\"O utmpname \- access utmp file entries
42 getutent, getutid, getutline, pututline, setutent, endutent, utmpname \-
43 utmp ファイルのエントリにアクセスする
44 .\"O .SH SYNOPSIS
45 .SH 書式
46 .B #include <utmp.h>
47 .sp
48 .B struct utmp *getutent(void);
49 .br
50 .BI "struct utmp *getutid(struct utmp *" ut );
51 .br
52 .BI "struct utmp *getutline(struct utmp *" ut );
53 .sp
54 .BI "struct utmp *pututline(struct utmp *" ut );
55 .sp
56 .B void setutent(void);
57 .br
58 .B void endutent(void);
59 .sp
60 .BI "int utmpname(const char *" file );
61 .\"O .SH DESCRIPTION
62 .SH 説明
63 .\"O New applications should use the POSIX.1-specified "utmpx" versions of
64 .\"O these functions; see CONFORMING TO.
65 新しいアプリケーションでは、これらの関数の "utmpx" 版を使用すべきである。
66 これらは POSIX.1 で規定されている。「準拠」の節を参照。
67
68 .\"O .BR utmpname ()
69 .\"O sets the name of the utmp-format file for the other utmp
70 .\"O functions to access.
71 .\"O If
72 .\"O .BR utmpname ()
73 .\"O is not used to set the filename
74 .\"O before the other functions are used, they assume \fB_PATH_UTMP\fP, as
75 .\"O defined in \fI<paths.h>\fP.
76 .BR utmpname ()
77 は、他の utmp 関数がアクセスする (utmp フォーマットの)
78 ファイルの名前を指定する。他の関数を使う前に
79 .BR utmpname ()
80 を使って
81 ファイル名の指定を行わなかった場合は、 \fI<path.h>\fP で
82 定義されている \fB_PATH_UTMP\fP がファイル名とみなされる。
83 .PP
84 .\"O .BR setutent ()
85 .\"O rewinds the file pointer to the beginning of the utmp file.
86 .\"O It is generally a good idea to call it before any of the other
87 .\"O functions.
88 .BR setutent ()
89 は、ファイルポインタを utmp ファイルの先頭に移動する。
90 一般的には、他の関数を使う前にこの関数を呼び出しておくと良いだろう。
91 .PP
92 .\"O .BR endutent ()
93 .\"O closes the utmp file.
94 .\"O It should be called when the user
95 .\"O code is done accessing the file with the other functions.
96 .BR endutent ()
97 は utmp ファイルをクローズする。ユーザーコードで
98 他の関数を使ってこのファイルにアクセスを行った時は、最後にこの関数を
99 呼び出すべきである。
100 .PP
101 .\"O .BR getutent ()
102 .\"O reads a line from the current file position in the utmp file.
103 .\"O It returns a pointer to a structure containing the fields of
104 .\"O the line.
105 .BR getutent ()
106 は utmp ファイルの現在のファイル位置から一行読み込み、
107 行の各フィールドの内容を収めた構造体へのポインタを返す。
108 .\"O The definition of this structure is shown in
109 .\"O .BR utmp (5).
110 この構造体の定義は
111 .BR utmp (5)
112 に書かれている。
113 .PP
114 .\"O .BR getutid ()
115 .\"O searches forward from the current file position in the utmp
116 .\"O file based upon \fIut\fP.
117 .\"O If \fIut\fP\->ut_type is one of \fBRUN_LVL\fP,
118 .\"O \fBBOOT_TIME\fP, \fBNEW_TIME\fP, or \fBOLD_TIME\fP,
119 .\"O .BR getutid ()
120 .\"O will
121 .\"O find the first entry whose \fIut_type\fP field matches \fIut\fP\->ut_type.
122 .\"O If \fIut\fP\->ut_type is one of \fBINIT_PROCESS\fP, \fBLOGIN_PROCESS\fP,
123 .\"O \fBUSER_PROCESS\fP, or \fBDEAD_PROCESS\fP,
124 .\"O .BR getutid ()
125 .\"O will find the
126 .\"O first entry whose
127 .\"O .I ut_id
128 .\"O field matches \fIut\fP\->ut_id.
129 .BR getutid ()
130 は、 utmp ファイル中の現在の位置から順方向
131 (末尾に向かう方向) へ \fIut\fP に基く検索を行う。 \fIut\fP\->ut_type が
132 \fBRUN_LVL\fP, \fBBOOT_TIME\fP, \fBNEW_TIME\fP, \fBOLD_TIME\fP の
133 いずれかなら、
134 .BR getutid ()
135 は \fBut_type\fP フィールドが
136 \fIut\fP\->ut_type に一致する最初のエントリを探す。
137 \fIut\fP\->ut_type が \fBINIT_PROCESS\fP, \fBLOGIN_PROCESS\fP,
138 \fBUSER_PROCESS\fP, \fBDEAD_PROCESS\fP のいずれかなら、
139 .BR getutid ()
140
141 .I ut_id
142 フィールドが \fIut\fP\->ut_id に
143 一致する最初のエントリを探す。
144 .PP
145 .\"O .BR getutline ()
146 .\"O searches forward from the current file position in the utmp file.
147 .\"O It scans entries whose
148 .\"O .I ut_type
149 .\"O is \fBUSER_PROCESS\fP
150 .\"O or \fBLOGIN_PROCESS\fP and returns the first one whose
151 .\"O .I ut_line
152 .\"O field
153 .\"O matches \fIut\->ut_line\fP.
154 .BR getutline ()
155 は、 utmp ファイルの現在の位置から末尾に向かって検索を行う。
156 .I ut_type
157 が \fBUSER_PROCESS\fP または \fBLOGIN_PROCESS\fP で、
158 .I ut_line
159 フィールドが \fIut\fP->ut_line にマッチする最初の行を返す。
160 .PP
161 .\"O .BR pututline ()
162 .\"O writes the
163 .\"O .I utmp
164 .\"O structure \fIut\fP into the utmp file.
165 .\"O It uses
166 .\"O .BR getutid ()
167 .\"O to search for the proper place in the file to insert
168 .\"O the new entry.
169 .\"O If it cannot find an appropriate slot for \fIut\fP,
170 .\"O .BR pututline ()
171 .\"O will append the new entry to the end of the file.
172 .BR pututline ()
173
174 .I utmp
175 構造体 \fIut\fP の内容を utmp ファイルに書き出す。
176 .BR pututline ()
177
178 .BR getutid ()
179 を用いて、新たなエントリを
180 挿入するのにふさわしい場所を探す。 \fIut\fP を挿入するふさわしい場所が
181 見つからない場合は、新たなエントリをファイルの末尾に追加する。
182 .\"O .SH "RETURN VALUE"
183 .SH 返り値
184 .\"O .BR getutent (),
185 .\"O .BR getutid (),
186 .\"O and
187 .\"O .BR getutline ()
188 .\"O return a pointer to a \fIstruct utmp\fP on success,
189 .\"O and NULL on failure (which includes the "record not found" case).
190 .\"O This \fIstruct utmp\fP is allocated in static storage, and may be
191 .\"O overwritten by subsequent calls.
192 .BR getutent (),
193 .BR getutid (),
194 .BR getutline ()
195 は、成功すると \fIstruct utmp\fP へのポインタを返す。
196 失敗すると NULL を返す (レコードが見つからなかった場合も失敗となる)。
197 この \fIstruct utmp\fP は静的な記憶領域に確保され、次にこれらの関数を
198 呼び出した際に上書きされるかもしれない。
199
200 .\"O On success
201 .\"O .BR pututline ()
202 .\"O returns
203 .\"O .IR ut ;
204 .\"O on failure, it returns NULL.
205 .BR pututline ()
206 は成功すると
207 .I ut
208 を返す。失敗すると NULL を返す。
209
210 .\"O .BR utmpname ()
211 .\"O returns 0 if the new name was successfully stored, or \-1 on failure.
212 .BR utmpname ()
213 は、新しい名前の格納に成功すると 0 を返し、失敗すると \-1 を返す。
214 .\"O .SH ERRORS
215 .SH エラー
216 .TP
217 .B ENOMEM
218 .\"O Out of memory.
219 メモリ不足。
220 .TP
221 .B ESRCH
222 .\"O Record not found.
223 レコードが見つからなかった。
224 .PP
225 .\"O .BR setutent (),
226 .\"O .BR pututline (),
227 .\"O and the
228 .\"O .B getut* ()
229 .\"O functions can also fail for the reasons described in
230 .\"O .BR open (2).
231 関数
232 .BR setutent (),
233 .BR pututline (),
234 .BR getut* ()
235
236 .BR open (2)
237 に書かれている理由でも失敗することがある。
238 .\"O .SH FILES
239 .SH ファイル
240 .\"O /var/run/utmp      database of currently logged-in users
241 .\"O .br
242 .\"O /var/log/wtmp      database of past user logins
243 /var/run/utmp     現在ログイン中のユーザーのデータベース
244 .br
245 /var/log/wtmp     過去のユーザーログインのデータベース
246 .\"O .SH "CONFORMING TO"
247 .SH 準拠
248 XPG2, SVr4.
249 .LP
250 .\"O In XPG2 and SVID 2 the function
251 .\"O .BR pututline ()
252 .\"O is documented
253 .\"O to return void, and that is what it does on many systems
254 .\"O (AIX, HP-UX, Linux libc5).
255 XPG2 と SVID 2 では、
256 .BR pututline ()
257 関数は値を返さないとされており、
258 (AIX, HP-UX, Linux libc5 などの) 多くのシステムではそうなっている。
259 .\"O HP-UX introduces a new function
260 .\"O .BR _pututline ()
261 .\"O with the prototype given above for
262 .\"O .BR pututline ()
263 .\"O (also found in Linux libc5).
264 HP-UX では、上述の
265 .BR pututline ()
266 と同じプロトタイプを持つ
267 新しい関数
268 .BR _pututline ()
269 が導入されている
270 (この関数は Linux libc5 にもある)。
271 .LP
272 .\"O All these functions are obsolete now on non-Linux systems.
273 現在では、Linux 以外のシステムでは、これらの関数は全て廃止されている。
274 .\"O POSIX.1-2001, following SUSv1,
275 .\"O does not have any of these functions, but instead uses
276 SUSv1 の後に出てきた POSIX.1-2001 では、もはやこれらの関数はなく、
277 代わりに以下のものを使う。
278 .sp
279 .B #include <utmpx.h>
280 .sp
281 .B struct utmpx *getutxent(void);
282 .br
283 .B struct utmpx *getutxid(const struct utmpx *);
284 .br
285 .B struct utmpx *getutxline(const struct utmpx *);
286 .br
287 .B struct utmpx *pututxline(const struct utmpx *);
288 .br
289 .B void setutxent(void);
290 .br
291 .B void endutxent(void);
292 .PP
293 .\"O These functions are provided by glibc,
294 .\"O and perform the same task as their equivalents without the "x", but use
295 .\"O .IR "struct utmpx" ,
296 .\"O defined on Linux to be the same as
297 .\"O .IR "struct utmp" .
298 .\"O For completeness, glibc also provides
299 .\"O .BR utmpxname (),
300 .\"O although this function is not specified by POSIX.1.
301 これらの関数は glibc により提供されており、
302 "x" がない関数と同じ処理を行うが、
303 .I "struct utmpx"
304 を使用する。
305 Linux では、この構造体の定義は
306 .I "struct utmp"
307 と同じになっている。
308 完全を期すために、glibc では
309 .BR utmpxname ()
310 も提供している。この関数は POSIX.1 では規定されていない。
311 .PP
312 .\"O On some other systems,
313 .\"O the \fIutmpx\fP structure is a superset of the \fIutmp\fP structure,
314 .\"O with additional fields, and larger versions of the existing fields,
315 .\"O and parallel files are maintained, often
316 .\"O .I /var/*/utmpx
317 .\"O and
318 .\"O .IR /var/*/wtmpx .
319 Linux 以外のシステムでは、
320 \fIutmpx\fP 構造体は \fIutmp\fP 構造体の上位集合 (superset) になっていて、
321 追加のフィールドがあったり、既存のフィールドのサイズが大きくなっていたり
322 するものもある。複数のファイルが使用されている場合もあり、多くの場合
323 .I /var/*/utmpx
324
325 .I /var/*/wtmpx
326 というファイルが使われる。
327 .LP
328 .\"O Linux glibc on the other hand does not use a parallel \fIutmpx\fP file
329 .\"O since its \fIutmp\fP structure is already large enough.
330 .\"O The functions \fBgetutxent\fP()
331 .\"O etc. are aliases for \fBgetutent\fP() etc.
332 一方、 Linux glibc では複数の \fIutmpx\fP ファイル は使われていない。
333 \fIutmp\fP 構造体が十分に大きいからである。
334 \fIgetutxent\fP() などの関数は \fIgetutent\fP() などの別名となっている。
335 .\"O .SH NOTES
336 .SH 注意
337 .\"O .SS Glibc Notes
338 .SS glibc での注意
339 .\"O The above functions are not thread-safe.
340 .\"O Glibc adds reentrant versions
341 上記の関数群はスレッド・セーフではない。
342 glibc にはリエントラント版 (reentrant) が追加されている。
343 .sp
344 .nf
345 .BR "#define _GNU_SOURCE" "    /* or _SVID_SOURCE or _BSD_SOURCE;
346 .\"O .RB "\&                          see " feature_test_macros(7) " */"
347 .RB "\&                          " feature_test_macros(7) " 参照 */"
348 .B #include <utmp.h>
349 .sp
350 .BI "int getutent_r(struct utmp *" ubuf ", struct utmp **" ubufp );
351 .sp
352 .BI "int getutid_r(struct utmp *" ut ,
353 .BI "              struct utmp *" ubuf ", struct utmp **" ubufp );
354 .sp
355 .BI "int getutline_r(struct utmp *" ut ,
356 .BI "                struct utmp *" ubuf ", struct utmp **" ubufp );
357 .fi
358 .sp
359 .\"O These functions are GNU extensions, analogs of the functions of the
360 .\"O same name without the _r suffix.
361 .\"O The
362 .\"O .I ubuf
363 .\"O argument gives these functions a place to store their result.
364 .\"O On success they return 0, and a pointer to the result is written in
365 .\"O .IR *ubufp .
366 .\"O On error these functions return \-1.
367 .\"O There are no utmpx equivalents of the above functions.
368 .\"O (POSIX.1 does not specify such functions.)
369 これらの関数は GNU での拡張であり、末尾の _r をとった名前の関数と
370 同様の機能を持つ。
371 .I ubuf
372 パラメータは結果を格納する場所を指定する。
373 成功すると 0 を返し、結果へのポインタを
374 .I *ubufp
375 に書き込む。エラーの場合 \-1 を返す。
376 上記の関数に対応する utmpx 版は存在しない
377 (POSIX.1 ではこれらの関数を規定されていない)。
378 .\"O .SH EXAMPLE
379 .SH 例
380 .\"O The following example adds and removes a utmp record, assuming it is run
381 .\"O from within a pseudo terminal.
382 .\"O For usage in a real application, you
383 .\"O should check the return values of
384 .\"O .BR getpwuid (3)
385 .\"O and
386 .\"O .BR ttyname (3).
387 以下の例では、 utmp のレコードの追加・削除を行っている。このコードは、
388 擬似端末 (pseudo terminal) から実行されることを想定している。
389 実際のアプリケーションでは
390 .BR getpwuid (3)
391
392 .BR ttyname (3)
393 の戻り値を検査するべきである。
394 .PP
395 .nf
396 #include <string.h>
397 #include <stdlib.h>
398 #include <pwd.h>
399 #include <unistd.h>
400 #include <utmp.h>
401
402 int
403 main(int argc, char *argv[])
404 {
405     struct utmp entry;
406
407     system("echo before adding entry:;who");
408
409     entry.ut_type = USER_PROCESS;
410     entry.ut_pid = getpid();
411     strcpy(entry.ut_line, ttyname(STDIN_FILENO) + strlen("/dev/"));
412     /* only correct for ptys named /dev/tty[pqr][0\-9a\-z] */
413     strcpy(entry.ut_id, ttyname(STDIN_FILENO) + strlen("/dev/tty"));
414     time(&entry.ut_time);
415     strcpy(entry.ut_user, getpwuid(getuid())\->pw_name);
416     memset(entry.ut_host, 0, UT_HOSTSIZE);
417     entry.ut_addr = 0;
418     setutent();
419     pututline(&entry);
420
421     system("echo after adding entry:;who");
422
423     entry.ut_type = DEAD_PROCESS;
424     memset(entry.ut_line, 0, UT_LINESIZE);
425     entry.ut_time = 0;
426     memset(entry.ut_user, 0, UT_NAMESIZE);
427     setutent();
428     pututline(&entry);
429
430     system("echo after removing entry:;who");
431
432     endutent();
433     exit(EXIT_SUCCESS);
434 }
435 .fi
436 .\"O .SH "SEE ALSO"
437 .SH 関連項目
438 .BR getutmp (3),
439 .BR utmp (5)