OSDN Git Service

(split) LDP: Update the version to 3.53 in PO files
[linuxjm/LDP_man-pages.git] / draft / 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 2013\-04\-19 "" "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
95 エラーが発生した場合、これらの関数は \fIerrno\fP にエラーの原因を示す値を設定する。
96 .SH エラー
97 .TP 
98 \fBENOMEM\fP
99 メモリ不足。
100 .TP 
101 \fBESRCH\fP
102 レコードが見つからなかった。
103 .PP
104 関数 \fBsetutent\fP(), \fBpututline\fP(), \fBgetut*\fP()  は \fBopen\fP(2)
105 に書かれている理由でも失敗することがある。
106 .SH ファイル
107 /var/run/utmp 現在ログイン中のユーザーのデータベース
108 .br
109 /var/log/wtmp 過去のユーザーログインのデータベース
110 .SH 準拠
111 XPG2, SVr4.
112 .LP
113 XPG2 と SVID 2 では、 \fBpututline\fP()  関数は値を返さないとされており、 (AIX, HP\-UX, Linux libc5
114 などの) 多くのシステムではそうなっている。 HP\-UX では、上述の \fBpututline\fP()  と同じプロトタイプを持つ 新しい関数
115 \fB_pututline\fP()  が導入されている (この関数は Linux libc5 にもある)。
116 .LP
117 現在では、Linux 以外のシステムでは、これらの関数は全て廃止されている。 SUSv1 の後に出てきた POSIX.1\-2001
118 では、もはやこれらの関数はなく、 代わりに以下のものを使う。
119 .sp
120 \fB#include <utmpx.h>\fP
121 .sp
122 \fBstruct utmpx *getutxent(void);\fP
123 .br
124 \fBstruct utmpx *getutxid(const struct utmpx *);\fP
125 .br
126 \fBstruct utmpx *getutxline(const struct utmpx *);\fP
127 .br
128 \fBstruct utmpx *pututxline(const struct utmpx *);\fP
129 .br
130 \fBvoid setutxent(void);\fP
131 .br
132 \fBvoid endutxent(void);\fP
133 .PP
134 これらの関数は glibc により提供されており、 "x" がない関数と同じ処理を行うが、 \fIstruct utmpx\fP を使用する。 Linux
135 では、この構造体の定義は \fIstruct utmp\fP と同じになっている。 完全を期すために、glibc では \fButmpxname\fP()
136 も提供している。この関数は POSIX.1 では規定されていない。
137 .PP
138 Linux 以外のシステムでは、 \fIutmpx\fP 構造体は \fIutmp\fP 構造体の上位集合 (superset) になっていて、
139 追加のフィールドがあったり、既存のフィールドのサイズが大きくなっていたり するものもある。複数のファイルが使用されている場合もあり、多くの場合
140 \fI/var/*/utmpx\fP と \fI/var/*/wtmpx\fP というファイルが使われる。
141 .LP
142 一方、 Linux glibc では複数の \fIutmpx\fP ファイル は使われていない。
143 \fIutmp\fP 構造体が十分に大きいからである。
144 上記の名前に "x" が付いた関数は "x" が付いていない対応する関数の別名と
145 なっている (例えば \fIgetutxent\fP() は \fIgetutent\fP() の別名である)。
146 .SH 注意
147 .SS "glibc での注意"
148 上記の関数群はスレッド・セーフではない。 glibc にはリエントラント版 (reentrant) が追加されている。
149 .sp
150 .nf
151 \fB#define _GNU_SOURCE\fP    /* or _SVID_SOURCE or _BSD_SOURCE;
152 \&                          \fBfeature_test_macros\fP(7) 参照 */
153 \fB#include <utmp.h>\fP
154 .sp
155 \fBint getutent_r(struct utmp *\fP\fIubuf\fP\fB, struct utmp **\fP\fIubufp\fP\fB);\fP
156 .sp
157 \fBint getutid_r(struct utmp *\fP\fIut\fP\fB,\fP
158 \fB              struct utmp *\fP\fIubuf\fP\fB, struct utmp **\fP\fIubufp\fP\fB);\fP
159 .sp
160 \fBint getutline_r(struct utmp *\fP\fIut\fP\fB,\fP
161 \fB                struct utmp *\fP\fIubuf\fP\fB, struct utmp **\fP\fIubufp\fP\fB);\fP
162 .fi
163 .sp
164 これらの関数は GNU での拡張であり、末尾の _r をとった名前の関数と 同様の機能を持つ。 \fIubuf\fP
165 パラメータは結果を格納する場所を指定する。 成功すると 0 を返し、結果へのポインタを \fI*ubufp\fP に書き込む。エラーの場合 \-1 を返す。
166 上記の関数に対応する utmpx 版は存在しない (POSIX.1 ではこれらの関数を規定されていない)。
167 .SH 例
168 以下の例では、 utmp のレコードの追加・削除を行っている。このコードは、 擬似端末 (pseudo terminal)
169 から実行されることを想定している。 実際のアプリケーションでは \fBgetpwuid\fP(3)  と \fBttyname\fP(3)
170 の戻り値を検査するべきである。
171 .PP
172 .nf
173 #include <string.h>
174 #include <stdlib.h>
175 #include <pwd.h>
176 #include <unistd.h>
177 #include <utmp.h>
178
179 int
180 main(int argc, char *argv[])
181 {
182     struct utmp entry;
183
184     system("echo before adding entry:;who");
185
186     entry.ut_type = USER_PROCESS;
187     entry.ut_pid = getpid();
188     strcpy(entry.ut_line, ttyname(STDIN_FILENO) + strlen("/dev/"));
189     /* only correct for ptys named /dev/tty[pqr][0\-9a\-z] */
190     strcpy(entry.ut_id, ttyname(STDIN_FILENO) + strlen("/dev/tty"));
191     time(&entry.ut_time);
192     strcpy(entry.ut_user, getpwuid(getuid())\->pw_name);
193     memset(entry.ut_host, 0, UT_HOSTSIZE);
194     entry.ut_addr = 0;
195     setutent();
196     pututline(&entry);
197
198     system("echo after adding entry:;who");
199
200     entry.ut_type = DEAD_PROCESS;
201     memset(entry.ut_line, 0, UT_LINESIZE);
202     entry.ut_time = 0;
203     memset(entry.ut_user, 0, UT_NAMESIZE);
204     setutent();
205     pututline(&entry);
206
207     system("echo after removing entry:;who");
208
209     endutent();
210     exit(EXIT_SUCCESS);
211 }
212 .fi
213 .SH 関連項目
214 \fBgetutmp\fP(3), \fButmp\fP(5)
215 .SH この文書について
216 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.53 の一部
217 である。プロジェクトの説明とバグ報告に関する情報は
218 http://www.kernel.org/doc/man\-pages/ に書かれている。