1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
|
.\" Copyright 1995 Mark D. Roth (roth@uiuc.edu)
.\"
.\" This is free documentation; you can redistribute it and/or
.\" modify it under the terms of the GNU General Public License as
.\" published by the Free Software Foundation; either version 2 of
.\" the License, or (at your option) any later version.
.\"
.\" The GNU General Public License's references to "object code"
.\" and "executables" are to be interpreted as the output of any
.\" document formatting or typesetting system, including
.\" intermediate and printed output.
.\"
.\" This manual is distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
.\" GNU General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public
.\" License along with this manual; if not, write to the Free
.\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111,
.\" USA.
.\"
.\" References consulted:
.\" Linux libc source code
.\" Solaris manpages
.\"
.\" Modified Thu Jul 25 14:43:46 MET DST 1996 by Michael Haardt
.\" <michael@cantor.informatik.rwth-aachen.de>
.\"
.\" Japanese Version Copyright (c) 1998 NAKANO Takeo all rights reserved.
.\" Translated 1998-03-15, NAKANO Takeo <nakano@apm.seikei.ac.jp>
.\" Updated 2001-10-16, Kentaro Shirakata <argrath@ub32.org>
.\" Updated 2002-01-03, Kentaro Shirakata <argrath@ub32.org>
.\" Updated 2005-03-18, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
.\" Updated 2008-08-11, Akihiro MOTOKI, LDP v3.05
.\"
.TH GETUTENT 3 2008-06-29 "" "Linux Programmer's Manual"
.SH ̾
getutent, getutid, getutline, pututline, setutent, endutent, utmpname \-
utmp եΥȥ˥
.SH
.B #include <utmp.h>
.sp
.B struct utmp *getutent(void);
.br
.BI "struct utmp *getutid(struct utmp *" ut );
.br
.BI "struct utmp *getutline(struct utmp *" ut );
.sp
.BI "struct utmp *pututline(struct utmp *" ut );
.sp
.B void setutent(void);
.br
.B void endutent(void);
.sp
.BI "int utmpname(const char *" file );
.SH
ץꥱǤϡδؿ "utmpx" ǤѤ٤Ǥ롣
POSIX.1 ǵꤵƤ롣ֽפȡ
.BR utmpname ()
ϡ¾ utmp ؿ (utmp եޥåȤ)
ե̾ꤹ롣¾δؿȤ
.BR utmpname ()
Ȥä
ե̾λԤʤäϡ \fI<path.h>\fP
Ƥ \fB_PATH_UTMP\fP ե̾Ȥߤʤ롣
.PP
.BR setutent ()
ϡեݥ utmp եƬ˰ư롣
Ūˤϡ¾δؿȤˤδؿƤӽФƤɤ
.PP
.BR endutent ()
utmp ե롣桼ɤ
¾δؿȤäƤΥե˥ԤäϡǸˤδؿ
ƤӽФ٤Ǥ롣
.PP
.BR getutent ()
utmp եθߤΥե֤ɤ߹ߡ
ԤγƥեɤƤ¤ΤؤΥݥ֤
ι¤Τ
.BR utmp (5)
˽Ƥ롣
.PP
.BR getutid ()
ϡ utmp եθߤΰ֤
(˸) \fIut\fP ˴𤯸Ԥ \fIut\fP\->ut_type
\fBRUN_LVL\fP, \fBBOOT_TIME\fP, \fBNEW_TIME\fP, \fBOLD_TIME\fP
줫ʤ顢
.BR getutid ()
\fBut_type\fP եɤ
\fIut\fP\->ut_type ˰פǽΥȥõ
\fIut\fP\->ut_type \fBINIT_PROCESS\fP, \fBLOGIN_PROCESS\fP,
\fBUSER_PROCESS\fP, \fBDEAD_PROCESS\fP Τ줫ʤ顢
.BR getutid ()
.I ut_id
եɤ \fIut\fP\->ut_id
פǽΥȥõ
.PP
.BR getutline ()
ϡ utmp եθߤΰ֤˸äƸԤ
.I ut_type
\fBUSER_PROCESS\fP ޤ \fBLOGIN_PROCESS\fP ǡ
.I ut_line
եɤ \fIut\fP->ut_line ˥ޥåǽιԤ֤
.PP
.BR pututline ()
.I utmp
¤ \fIut\fP Ƥ utmp ե˽Ф
.BR pututline ()
.BR getutid ()
Ѥơʥȥ
Τˤդ路õ \fIut\fP դ路꤬
Ĥʤϡʥȥեɲä롣
.SH ֤
.BR getutent (),
.BR getutid (),
.BR getutline ()
ϡ \fIstruct utmp\fP ؤΥݥ֤
Ԥ NULL ֤ (쥳ɤĤʤä⼺ԤȤʤ)
\fIstruct utmp\fP Ūʵΰ˳ݤ졢ˤδؿ
ƤӽФݤ˾뤫⤷ʤ
.BR pututline ()
.I ut
֤Ԥ NULL ֤
.BR utmpname ()
ϡ̾γǼ 0 ֤Ԥ \-1 ֤
.SH 顼
.TP
.B ENOMEM
.TP
.B ESRCH
쥳ɤĤʤä
.PP
ؿ
.BR setutent (),
.BR pututent (),
.BR getut* ()
.BR open (2)
˽ƤͳǤ⼺Ԥ뤳Ȥ롣
.SH ե
/var/run/utmp ߥΥ桼Υǡ١
.br
/var/log/wtmp Υ桼Υǡ١
.SH
XPG2, SVr4.
.LP
XPG2 SVID 2 Ǥϡ
.BR pututline ()
ؿ֤ͤʤȤƤꡢ
(AIX, HP-UX, Linux libc5 ʤɤ) ¿ΥƥǤϤʤäƤ롣
HP-UX ǤϡҤ
.BR pututline ()
Ʊץȥפ
ؿ
.BR _pututline ()
ƳƤ
(δؿ Linux libc5 ˤ⤢)
.LP
ߤǤϡLinux ʳΥƥǤϡδؿѻߤƤ롣
SUSv1 θ˽ФƤ POSIX.1-2001 ǤϡϤ䤳δؿϤʤ
˰ʲΤΤȤ
.sp
.B #include <utmpx.h>
.sp
.B struct utmpx *getutxent(void);
.br
.B struct utmpx *getutxid(const struct utmpx *);
.br
.B struct utmpx *getutxline(const struct utmpx *);
.br
.B struct utmpx *pututxline(const struct utmpx *);
.br
.B void setutxent(void);
.br
.B void endutxent(void);
.PP
δؿ glibc ˤƤꡢ
"x" ʤؿƱԤ
.I "struct utmpx"
Ѥ롣
Linux Ǥϡι¤Τ
.I "struct utmp"
ƱˤʤäƤ롣
ˡglibc Ǥ
.BR utmpxname ()
Ƥ롣δؿ POSIX.1 ǤϵꤵƤʤ
.PP
Linux ʳΥƥǤϡ
\fIutmpx\fP ¤Τ \fIutmp\fP ¤Τξ̽ (superset) ˤʤäƤơ
ɲäΥեɤäꡢ¸ΥեɤΥ礭ʤäƤ
Τ⤢롣ʣΥե뤬ѤƤ⤢ꡢ¿ξ
.I /var/*/utmpx
.I /var/*/wtmpx
Ȥե뤬Ȥ롣
.LP
Linux glibc Ǥʣ \fIutmpx\fP ե ϻȤƤʤ
\fIutmp\fP ¤Τʬ礭Ǥ롣
\fIgetutxent\fP() ʤɤδؿ \fIgetutent\fP() ʤɤ̾ȤʤäƤ롣
.SH
.SS glibc Ǥ
嵭δؿϥåɡդǤϤʤ
glibc ˤϥꥨȥ (reentrant) ɲäƤ롣
.sp
.nf
.BR "#define _GNU_SOURCE" " /* or _SVID_SOURCE or _BSD_SOURCE */"
.B #include <utmp.h>
.sp
.BI "int getutent_r(struct utmp *" ubuf ", struct utmp **" ubufp );
.sp
.BI "int getutid_r(struct utmp *" ut ,
.BI " struct utmp *" ubuf ", struct utmp **" ubufp );
.sp
.BI "int getutline_r(struct utmp *" ut ,
.BI " struct utmp *" ubuf ", struct utmp **" ubufp );
.fi
.sp
δؿ GNU ǤγĥǤꡢ _r Ȥä̾δؿ
Ʊͤεǽġ
.I ubuf
ѥϷ̤Ǽꤹ롣
0 ֤̤ؤΥݥ
.I *ubufp
˽ࡣ顼ξ \-1 ֤
嵭δؿб utmpx Ǥ¸ߤʤ
(POSIX.1 ǤϤδؿꤵƤʤ)
.SH
ʲǤϡ utmp Υ쥳ɤɲáԤäƤ롣Υɤϡ
ü (pseudo terminal) ¹Ԥ뤳ȤꤷƤ롣
ºݤΥץꥱǤ
.BR getpwuid (3)
.BR ttyname (3)
ͤ٤Ǥ롣
.PP
.nf
#include <string.h>
#include <stdlib.h>
#include <pwd.h>
#include <unistd.h>
#include <utmp.h>
int
main(int argc, char *argv[])
{
struct utmp entry;
system("echo before adding entry:;who");
entry.ut_type = USER_PROCESS;
entry.ut_pid = getpid();
strcpy(entry.ut_line, ttyname(STDIN_FILENO) + strlen("/dev/"));
/* only correct for ptys named /dev/tty[pqr][0\-9a\-z] */
strcpy(entry.ut_id, ttyname(STDIN_FILENO) + strlen("/dev/tty"));
time(&entry.ut_time);
strcpy(entry.ut_user, getpwuid(getuid())\->pw_name);
memset(entry.ut_host, 0, UT_HOSTSIZE);
entry.ut_addr = 0;
setutent();
pututline(&entry);
system("echo after adding entry:;who");
entry.ut_type = DEAD_PROCESS;
memset(entry.ut_line, 0, UT_LINESIZE);
entry.ut_time = 0;
memset(entry.ut_user, 0, UT_NAMESIZE);
setutent();
pututline(&entry);
system("echo after removing entry:;who");
endutent();
exit(EXIT_SUCCESS);
}
.fi
.SH Ϣ
.BR getutmp (3),
.BR utmp (5),
.BR feature_test_macros (7)
|