1 .\" Copyright 1995 Mark D. Roth (roth@uiuc.edu)
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.
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.
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.
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,
23 .\" References consulted:
24 .\" Linux libc source code
27 .\" Modified Thu Jul 25 14:43:46 MET DST 1996 by Michael Haardt
28 .\" <michael@cantor.informatik.rwth-aachen.de>
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
37 .TH GETUTENT 3 2008-06-29 "" "Linux Programmer's Manual"
39 getutent, getutid, getutline, pututline, setutent, endutent, utmpname \-
40 utmp ¥Õ¥¡¥¤¥ë¤Î¥¨¥ó¥È¥ê¤Ë¥¢¥¯¥»¥¹¤¹¤ë
44 .B struct utmp *getutent(void);
46 .BI "struct utmp *getutid(struct utmp *" ut );
48 .BI "struct utmp *getutline(struct utmp *" ut );
50 .BI "struct utmp *pututline(struct utmp *" ut );
52 .B void setutent(void);
54 .B void endutent(void);
56 .BI "int utmpname(const char *" file );
58 ¿·¤·¤¤¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Ï¡¢¤³¤ì¤é¤Î´Ø¿ô¤Î "utmpx" ÈǤò»ÈÍѤ¹¤Ù¤¤Ç¤¢¤ë¡£
59 ¤³¤ì¤é¤Ï POSIX.1 ¤Çµ¬Äꤵ¤ì¤Æ¤¤¤ë¡£¡Ö½àµò¡×¤ÎÀá¤ò»²¾È¡£
62 ¤Ï¡¢Â¾¤Î utmp ´Ø¿ô¤¬¥¢¥¯¥»¥¹¤¹¤ë (utmp ¥Õ¥©¡¼¥Þ¥Ã¥È¤Î)
63 ¥Õ¥¡¥¤¥ë¤Î̾Á°¤ò»ØÄꤹ¤ë¡£Â¾¤Î´Ø¿ô¤ò»È¤¦Á°¤Ë
66 ¥Õ¥¡¥¤¥ë̾¤Î»ØÄê¤ò¹Ô¤ï¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï¡¢ \fI<path.h>\fP ¤Ç
67 ÄêµÁ¤µ¤ì¤Æ¤¤¤ë \fB_PATH_UTMP\fP ¤¬¥Õ¥¡¥¤¥ë̾¤È¤ß¤Ê¤µ¤ì¤ë¡£
70 ¤Ï¡¢¥Õ¥¡¥¤¥ë¥Ý¥¤¥ó¥¿¤ò utmp ¥Õ¥¡¥¤¥ë¤ÎÀèƬ¤Ë°ÜÆ°¤¹¤ë¡£
71 °ìÈÌŪ¤Ë¤Ï¡¢Â¾¤Î´Ø¿ô¤ò»È¤¦Á°¤Ë¤³¤Î´Ø¿ô¤ò¸Æ¤Ó½Ð¤·¤Æ¤ª¤¯¤ÈÎɤ¤¤À¤í¤¦¡£
74 ¤Ï utmp ¥Õ¥¡¥¤¥ë¤ò¥¯¥í¡¼¥º¤¹¤ë¡£¥æ¡¼¥¶¡¼¥³¡¼¥É¤Ç
75 ¾¤Î´Ø¿ô¤ò»È¤Ã¤Æ¤³¤Î¥Õ¥¡¥¤¥ë¤Ë¥¢¥¯¥»¥¹¤ò¹Ô¤Ã¤¿»þ¤Ï¡¢ºÇ¸å¤Ë¤³¤Î´Ø¿ô¤ò
79 ¤Ï utmp ¥Õ¥¡¥¤¥ë¤Î¸½ºß¤Î¥Õ¥¡¥¤¥ë°ÌÃÖ¤«¤é°ì¹ÔÆɤ߹þ¤ß¡¢
80 ¹Ô¤Î³Æ¥Õ¥£¡¼¥ë¥É¤ÎÆâÍƤò¼ý¤á¤¿¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤òÊÖ¤¹¡£
86 ¤Ï¡¢ utmp ¥Õ¥¡¥¤¥ëÃæ¤Î¸½ºß¤Î°ÌÃÖ¤«¤é½çÊý¸þ
87 (ËöÈø¤Ë¸þ¤«¤¦Êý¸þ) ¤Ø \fIut\fP ¤Ë´ð¤¯¸¡º÷¤ò¹Ô¤¦¡£ \fIut\fP\->ut_type ¤¬
88 \fBRUN_LVL\fP, \fBBOOT_TIME\fP, \fBNEW_TIME\fP, \fBOLD_TIME\fP ¤Î
91 ¤Ï \fBut_type\fP ¥Õ¥£¡¼¥ë¥É¤¬
92 \fIut\fP\->ut_type ¤Ë°ìÃפ¹¤ëºÇ½é¤Î¥¨¥ó¥È¥ê¤òõ¤¹¡£
93 \fIut\fP\->ut_type ¤¬ \fBINIT_PROCESS\fP, \fBLOGIN_PROCESS\fP,
94 \fBUSER_PROCESS\fP, \fBDEAD_PROCESS\fP ¤Î¤¤¤º¤ì¤«¤Ê¤é¡¢
98 ¥Õ¥£¡¼¥ë¥É¤¬ \fIut\fP\->ut_id ¤Ë
99 °ìÃפ¹¤ëºÇ½é¤Î¥¨¥ó¥È¥ê¤òõ¤¹¡£
102 ¤Ï¡¢ utmp ¥Õ¥¡¥¤¥ë¤Î¸½ºß¤Î°ÌÃÖ¤«¤éËöÈø¤Ë¸þ¤«¤Ã¤Æ¸¡º÷¤ò¹Ô¤¦¡£
104 ¤¬ \fBUSER_PROCESS\fP ¤Þ¤¿¤Ï \fBLOGIN_PROCESS\fP ¤Ç¡¢
106 ¥Õ¥£¡¼¥ë¥É¤¬ \fIut\fP->ut_line ¤Ë¥Þ¥Ã¥Á¤¹¤ëºÇ½é¤Î¹Ô¤òÊÖ¤¹¡£
111 ¹½Â¤ÂÎ \fIut\fP ¤ÎÆâÍƤò utmp ¥Õ¥¡¥¤¥ë¤Ë½ñ¤½Ð¤¹¡£
115 ¤òÍѤ¤¤Æ¡¢¿·¤¿¤Ê¥¨¥ó¥È¥ê¤ò
116 ÁÞÆþ¤¹¤ë¤Î¤Ë¤Õ¤µ¤ï¤·¤¤¾ì½ê¤òõ¤¹¡£ \fIut\fP ¤òÁÞÆþ¤¹¤ë¤Õ¤µ¤ï¤·¤¤¾ì½ê¤¬
117 ¸«¤Ä¤«¤é¤Ê¤¤¾ì¹ç¤Ï¡¢¿·¤¿¤Ê¥¨¥ó¥È¥ê¤ò¥Õ¥¡¥¤¥ë¤ÎËöÈø¤ËÄɲ乤롣
122 ¤Ï¡¢À®¸ù¤¹¤ë¤È \fIstruct utmp\fP ¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
123 ¼ºÇÔ¤¹¤ë¤È NULL ¤òÊÖ¤¹ (¥ì¥³¡¼¥É¤¬¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¾ì¹ç¤â¼ºÇԤȤʤë)¡£
124 ¤³¤Î \fIstruct utmp\fP ¤ÏÀÅŪ¤Êµ²±Îΰè¤Ë³ÎÊݤµ¤ì¡¢¼¡¤Ë¤³¤ì¤é¤Î´Ø¿ô¤ò
125 ¸Æ¤Ó½Ð¤·¤¿ºÝ¤Ë¾å½ñ¤¤µ¤ì¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
130 ¤òÊÖ¤¹¡£¼ºÇÔ¤¹¤ë¤È NULL ¤òÊÖ¤¹¡£
133 ¤Ï¡¢¿·¤·¤¤Ì¾Á°¤Î³ÊǼ¤ËÀ®¸ù¤¹¤ë¤È 0 ¤òÊÖ¤·¡¢¼ºÇÔ¤¹¤ë¤È \-1 ¤òÊÖ¤¹¡£
140 ¥ì¥³¡¼¥É¤¬¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¡£
148 ¤Ë½ñ¤«¤ì¤Æ¤¤¤ëÍýͳ¤Ç¤â¼ºÇÔ¤¹¤ë¤³¤È¤¬¤¢¤ë¡£
150 /var/run/utmp ¸½ºß¥í¥°¥¤¥óÃæ¤Î¥æ¡¼¥¶¡¼¤Î¥Ç¡¼¥¿¥Ù¡¼¥¹
152 /var/log/wtmp ²áµî¤Î¥æ¡¼¥¶¡¼¥í¥°¥¤¥ó¤Î¥Ç¡¼¥¿¥Ù¡¼¥¹
156 XPG2 ¤È SVID 2 ¤Ç¤Ï¡¢
158 ´Ø¿ô¤ÏÃͤòÊÖ¤µ¤Ê¤¤¤È¤µ¤ì¤Æ¤ª¤ê¡¢
159 (AIX, HP-UX, Linux libc5 ¤Ê¤É¤Î) ¿¤¯¤Î¥·¥¹¥Æ¥à¤Ç¤Ï¤½¤¦¤Ê¤Ã¤Æ¤¤¤ë¡£
162 ¤ÈƱ¤¸¥×¥í¥È¥¿¥¤¥×¤ò»ý¤Ä
166 (¤³¤Î´Ø¿ô¤Ï Linux libc5 ¤Ë¤â¤¢¤ë)¡£
168 ¸½ºß¤Ç¤Ï¡¢Linux °Ê³°¤Î¥·¥¹¥Æ¥à¤Ç¤Ï¡¢¤³¤ì¤é¤Î´Ø¿ô¤ÏÁ´¤ÆÇѻߤµ¤ì¤Æ¤¤¤ë¡£
169 SUSv1 ¤Î¸å¤Ë½Ð¤Æ¤¤¿ POSIX.1-2001 ¤Ç¤Ï¡¢¤â¤Ï¤ä¤³¤ì¤é¤Î´Ø¿ô¤Ï¤Ê¤¯¡¢
170 Âå¤ï¤ê¤Ë°Ê²¼¤Î¤â¤Î¤ò»È¤¦¡£
172 .B #include <utmpx.h>
174 .B struct utmpx *getutxent(void);
176 .B struct utmpx *getutxid(const struct utmpx *);
178 .B struct utmpx *getutxline(const struct utmpx *);
180 .B struct utmpx *pututxline(const struct utmpx *);
182 .B void setutxent(void);
184 .B void endutxent(void);
186 ¤³¤ì¤é¤Î´Ø¿ô¤Ï glibc ¤Ë¤è¤êÄ󶡤µ¤ì¤Æ¤ª¤ê¡¢
187 "x" ¤¬¤Ê¤¤´Ø¿ô¤ÈƱ¤¸½èÍý¤ò¹Ô¤¦¤¬¡¢
190 Linux ¤Ç¤Ï¡¢¤³¤Î¹½Â¤ÂΤÎÄêµÁ¤Ï
193 ´°Á´¤ò´ü¤¹¤¿¤á¤Ë¡¢glibc ¤Ç¤Ï
195 ¤âÄ󶡤·¤Æ¤¤¤ë¡£¤³¤Î´Ø¿ô¤Ï POSIX.1 ¤Ç¤Ïµ¬Äꤵ¤ì¤Æ¤¤¤Ê¤¤¡£
197 Linux °Ê³°¤Î¥·¥¹¥Æ¥à¤Ç¤Ï¡¢
198 \fIutmpx\fP ¹½Â¤ÂÎ¤Ï \fIutmp\fP ¹½Â¤ÂΤξå°Ì½¸¹ç (superset) ¤Ë¤Ê¤Ã¤Æ¤¤¤Æ¡¢
199 ÄɲäΥե£¡¼¥ë¥É¤¬¤¢¤Ã¤¿¤ê¡¢´û¸¤Î¥Õ¥£¡¼¥ë¥É¤Î¥µ¥¤¥º¤¬Â礤¯¤Ê¤Ã¤Æ¤¤¤¿¤ê
200 ¤¹¤ë¤â¤Î¤â¤¢¤ë¡£Ê£¿ô¤Î¥Õ¥¡¥¤¥ë¤¬»ÈÍѤµ¤ì¤Æ¤¤¤ë¾ì¹ç¤â¤¢¤ê¡¢Â¿¤¯¤Î¾ì¹ç
204 ¤È¤¤¤¦¥Õ¥¡¥¤¥ë¤¬»È¤ï¤ì¤ë¡£
206 °ìÊý¡¢ Linux glibc ¤Ç¤ÏÊ£¿ô¤Î \fIutmpx\fP ¥Õ¥¡¥¤¥ë ¤Ï»È¤ï¤ì¤Æ¤¤¤Ê¤¤¡£
207 \fIutmp\fP ¹½Â¤ÂΤ¬½½Ê¬¤ËÂ礤¤¤«¤é¤Ç¤¢¤ë¡£
208 \fIgetutxent\fP() ¤Ê¤É¤Î´Ø¿ô¤Ï \fIgetutent\fP() ¤Ê¤É¤ÎÊÌ̾¤È¤Ê¤Ã¤Æ¤¤¤ë¡£
211 ¾åµ¤Î´Ø¿ô·²¤Ï¥¹¥ì¥Ã¥É¡¦¥»¡¼¥Õ¤Ç¤Ï¤Ê¤¤¡£
212 glibc ¤Ë¤Ï¥ê¥¨¥ó¥È¥é¥ó¥ÈÈÇ (reentrant) ¤¬Äɲ䵤ì¤Æ¤¤¤ë¡£
215 .BR "#define _GNU_SOURCE" " /* or _SVID_SOURCE or _BSD_SOURCE;
216 .RB "\& " feature_test_macros(7) " »²¾È */"
219 .BI "int getutent_r(struct utmp *" ubuf ", struct utmp **" ubufp );
221 .BI "int getutid_r(struct utmp *" ut ,
222 .BI " struct utmp *" ubuf ", struct utmp **" ubufp );
224 .BI "int getutline_r(struct utmp *" ut ,
225 .BI " struct utmp *" ubuf ", struct utmp **" ubufp );
228 ¤³¤ì¤é¤Î´Ø¿ô¤Ï GNU ¤Ç¤Î³ÈÄ¥¤Ç¤¢¤ê¡¢ËöÈø¤Î _r ¤ò¤È¤Ã¤¿Ì¾Á°¤Î´Ø¿ô¤È
231 ¥Ñ¥é¥á¡¼¥¿¤Ï·ë²Ì¤ò³ÊǼ¤¹¤ë¾ì½ê¤ò»ØÄꤹ¤ë¡£
232 À®¸ù¤¹¤ë¤È 0 ¤òÊÖ¤·¡¢·ë²Ì¤Ø¤Î¥Ý¥¤¥ó¥¿¤ò
234 ¤Ë½ñ¤¹þ¤à¡£¥¨¥é¡¼¤Î¾ì¹ç \-1 ¤òÊÖ¤¹¡£
235 ¾åµ¤Î´Ø¿ô¤ËÂбþ¤¹¤ë utmpx ÈǤϸºß¤·¤Ê¤¤
236 (POSIX.1 ¤Ç¤Ï¤³¤ì¤é¤Î´Ø¿ô¤òµ¬Äꤵ¤ì¤Æ¤¤¤Ê¤¤)¡£
238 °Ê²¼¤ÎÎã¤Ç¤Ï¡¢ utmp ¤Î¥ì¥³¡¼¥É¤ÎÄɲᦺï½ü¤ò¹Ô¤Ã¤Æ¤¤¤ë¡£¤³¤Î¥³¡¼¥É¤Ï¡¢
239 µ¼»÷üËö (pseudo terminal) ¤«¤é¼Â¹Ô¤µ¤ì¤ë¤³¤È¤òÁÛÄꤷ¤Æ¤¤¤ë¡£
240 ¼ÂºÝ¤Î¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Ï
244 ¤ÎÌá¤êÃͤò¸¡ºº¤¹¤ë¤Ù¤¤Ç¤¢¤ë¡£
254 main(int argc, char *argv[])
258 system("echo before adding entry:;who");
260 entry.ut_type = USER_PROCESS;
261 entry.ut_pid = getpid();
262 strcpy(entry.ut_line, ttyname(STDIN_FILENO) + strlen("/dev/"));
263 /* only correct for ptys named /dev/tty[pqr][0\-9a\-z] */
264 strcpy(entry.ut_id, ttyname(STDIN_FILENO) + strlen("/dev/tty"));
265 time(&entry.ut_time);
266 strcpy(entry.ut_user, getpwuid(getuid())\->pw_name);
267 memset(entry.ut_host, 0, UT_HOSTSIZE);
272 system("echo after adding entry:;who");
274 entry.ut_type = DEAD_PROCESS;
275 memset(entry.ut_line, 0, UT_LINESIZE);
277 memset(entry.ut_user, 0, UT_NAMESIZE);
281 system("echo after removing entry:;who");