OSDN Git Service

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