1UTMP(5)                    Linux Programmer's Manual                   UTMP(5)
2
3
4

NAME

6       utmp, wtmp - login records
7

SYNOPSIS

9       #include <utmp.h>
10

DESCRIPTION

12       The utmp file allows one to discover information about who is currently
13       using the system.  There may be more users currently using the  system,
14       because not all programs use utmp logging.
15
16       Warning:  utmp  must not be writable by the user class "other", because
17       many system programs (foolishly) depend on  its  integrity.   You  risk
18       faked  system  logfiles  and modifications of system files if you leave
19       utmp writable to any user other than the owner and group owner  of  the
20       file.
21
22       The  file  is  a  sequence  of  utmp structures, declared as follows in
23       <utmp.h> (note that this is only one  of  several  definitions  around;
24       details depend on the version of libc):
25
26           /* Values for ut_type field, below */
27
28           #define EMPTY         0 /* Record does not contain valid info
29                                      (formerly known as UT_UNKNOWN on Linux) */
30           #define RUN_LVL       1 /* Change in system run-level (see
31                                      init(8)) */
32           #define BOOT_TIME     2 /* Time of system boot (in ut_tv) */
33           #define NEW_TIME      3 /* Time after system clock change
34                                      (in ut_tv) */
35           #define OLD_TIME      4 /* Time before system clock change
36                                      (in ut_tv) */
37           #define INIT_PROCESS  5 /* Process spawned by init(8) */
38           #define LOGIN_PROCESS 6 /* Session leader process for user login */
39           #define USER_PROCESS  7 /* Normal process */
40           #define DEAD_PROCESS  8 /* Terminated process */
41           #define ACCOUNTING    9 /* Not implemented */
42
43           #define UT_LINESIZE      32
44           #define UT_NAMESIZE      32
45           #define UT_HOSTSIZE     256
46
47           struct exit_status {              /* Type for ut_exit, below */
48               short int e_termination;      /* Process termination status */
49               short int e_exit;             /* Process exit status */
50           };
51
52           struct utmp {
53               short   ut_type;              /* Type of record */
54               pid_t   ut_pid;               /* PID of login process */
55               char    ut_line[UT_LINESIZE]; /* Device name of tty - "/dev/" */
56               char    ut_id[4];             /* Terminal name suffix,
57                                                or inittab(5) ID */
58               char    ut_user[UT_NAMESIZE]; /* Username */
59               char    ut_host[UT_HOSTSIZE]; /* Hostname for remote login, or
60                                                kernel version for run-level
61                                                messages */
62               struct  exit_status ut_exit;  /* Exit status of a process
63                                                marked as DEAD_PROCESS; not
64                                                used by Linux init (1 */
65               /* The ut_session and ut_tv fields must be the same size when
66                  compiled 32- and 64-bit.  This allows data files and shared
67                  memory to be shared between 32- and 64-bit applications. */
68           #if __WORDSIZE == 64 && defined __WORDSIZE_COMPAT32
69               int32_t ut_session;           /* Session ID (getsid(2)),
70                                                used for windowing */
71               struct {
72                   int32_t tv_sec;           /* Seconds */
73                   int32_t tv_usec;          /* Microseconds */
74               } ut_tv;                      /* Time entry was made */
75           #else
76                long   ut_session;           /* Session ID */
77                struct timeval ut_tv;        /* Time entry was made */
78           #endif
79
80               int32_t ut_addr_v6[4];        /* Internet address of remote
81                                                host; IPv4 address uses
82                                                just ut_addr_v6[0] */
83               char __unused[20];            /* Reserved for future use */
84           };
85
86           /* Backward compatibility hacks */
87           #define ut_name ut_user
88           #ifndef _NO_UT_TIME
89           #define ut_time ut_tv.tv_sec
90           #endif
91           #define ut_xtime ut_tv.tv_sec
92           #define ut_addr ut_addr_v6[0]
93
94       This  structure  gives the name of the special file associated with the
95       user's terminal, the user's login name, and the time of  login  in  the
96       form of time(2).  String fields are terminated by a null byte ('\0') if
97       they are shorter than the size of the field.
98
99       The first entries ever created result  from  init(1)  processing  init‐
100       tab(5).   Before  an entry is processed, though, init(1) cleans up utmp
101       by setting ut_type to  DEAD_PROCESS,  clearing  ut_user,  ut_host,  and
102       ut_time   with  null  bytes  for  each  record  which  ut_type  is  not
103       DEAD_PROCESS or RUN_LVL and where no process with  PID  ut_pid  exists.
104       If  no empty record with the needed ut_id can be found, init(1) creates
105       a new one.  It sets ut_id from the inittab, ut_pid and ut_time  to  the
106       current values, and ut_type to INIT_PROCESS.
107
108       mingetty(8)  (or  agetty(8))  locates  the  entry  by  the PID, changes
109       ut_type to LOGIN_PROCESS, changes ut_time, sets ut_line, and waits  for
110       connection  to be established.  login(1), after a user has been authen‐
111       ticated, changes ut_type to USER_PROCESS,  changes  ut_time,  and  sets
112       ut_host  and  ut_addr.   Depending  on  mingetty(8)  (or agetty(8)) and
113       login(1), records may be located by ut_line instead of  the  preferable
114       ut_pid.
115
116       When init(1) finds that a process has exited, it locates its utmp entry
117       by ut_pid, sets ut_type to DEAD_PROCESS, and  clears  ut_user,  ut_host
118       and ut_time with null bytes.
119
120       xterm(1)  and  other  terminal emulators directly create a USER_PROCESS
121       record and generate the ut_id by using the string that suffix  part  of
122       the terminal name (the characters following /dev/[pt]ty).  If they find
123       a DEAD_PROCESS for this ID, they recycle it, otherwise  they  create  a
124       new  entry.   If they can, they will mark it as DEAD_PROCESS on exiting
125       and it is advised that they null ut_line, ut_time, ut_user, and ut_host
126       as well.
127
128       telnetd(8)  sets  up  a  LOGIN_PROCESS  entry  and  leaves  the rest to
129       login(1) as usual.  After the telnet session ends, telnetd(8) cleans up
130       utmp in the described way.
131
132       The  wtmp  file  records all logins and logouts.  Its format is exactly
133       like utmp except that a null username indicates a logout on the associ‐
134       ated terminal.  Furthermore, the terminal name ~ with username shutdown
135       or reboot indicates a system shutdown or reboot and the pair of  termi‐
136       nal  names  |/}  logs  the old/new system time when date(1) changes it.
137       wtmp is maintained by login(1), init(1), and some versions of  getty(8)
138       (e.g.,  mingetty(8)  or agetty(8)).  None of these programs creates the
139       file, so if it is removed, record-keeping is turned off.
140

FILES

142       /var/run/utmp
143       /var/log/wtmp
144

CONFORMING TO

146       POSIX.1 does not specify a utmp structure, but rather one named  utmpx,
147       with  specifications  for  the  fields ut_type, ut_pid, ut_line, ut_id,
148       ut_user, and ut_tv.  POSIX.1  does  not  specify  the  lengths  of  the
149       ut_line and ut_user fields.
150
151       Linux defines the utmpx structure to be the same as the utmp structure.
152
153   Comparison with historical systems
154       Linux  utmp entries conform neither to v7/BSD nor to System V; they are
155       a mix of the two.
156
157       v7/BSD has fewer fields;  most  importantly  it  lacks  ut_type,  which
158       causes  native  v7/BSD-like  programs  to display (for example) dead or
159       login entries.  Further, there is no configuration file which allocates
160       slots to sessions.  BSD does so because it lacks ut_id fields.
161
162       In  Linux  (as  in  System  V),  the ut_id field of a record will never
163       change once it has been set, which reserves that slot without needing a
164       configuration file.  Clearing ut_id may result in race conditions lead‐
165       ing to corrupted utmp entries and potential security  holes.   Clearing
166       the  abovementioned  fields  by  filling  them  with  null bytes is not
167       required by System V semantics, but makes it possible to run many  pro‐
168       grams  which  assume BSD semantics and which do not modify utmp.  Linux
169       uses the BSD conventions for line contents, as documented above.
170
171       System V has no ut_host or ut_addr_v6 fields.
172

NOTES

174       Unlike various other systems, where utmp logging  can  be  disabled  by
175       removing  the  file,  utmp  must always exist on Linux.  If you want to
176       disable who(1), then do not make utmp world readable.
177
178       The file format is machine-dependent, so it is recommended that  it  be
179       processed only on the machine architecture where it was created.
180
181       Note  that  on  biarch  platforms,  that is, systems which can run both
182       32-bit and 64-bit applications (x86-64, ppc64, s390x, etc.),  ut_tv  is
183       the  same  size  in  32-bit  mode as in 64-bit mode.  The same goes for
184       ut_session and ut_time if they are present.  This allows data files and
185       shared  memory  to  be  shared  between 32-bit and 64-bit applications.
186       This is achieved by changing the type of  ut_session  to  int32_t,  and
187       that  of  ut_tv to a struct with two int32_t fields tv_sec and tv_usec.
188       Since ut_tv may not be the same as struct timeval, then instead of  the
189       call:
190
191           gettimeofday((struct timeval *) &ut.ut_tv, NULL);
192
193       the following method of setting this field is recommended:
194
195           struct utmp ut;
196           struct timeval tv;
197
198           gettimeofday(&tv, NULL);
199           ut.ut_tv.tv_sec = tv.tv_sec;
200           ut.ut_tv.tv_usec = tv.tv_usec;
201

SEE ALSO

203       ac(1),  date(1),  init(1),  last(1), login(1), logname(1), lslogins(1),
204       users(1),  utmpdump(1),  who(1),  getutent(3),  getutmp(3),   login(3),
205       logout(3), logwtmp(3), updwtmp(3)
206

COLOPHON

208       This  page  is  part of release 5.04 of the Linux man-pages project.  A
209       description of the project, information about reporting bugs,  and  the
210       latest     version     of     this    page,    can    be    found    at
211       https://www.kernel.org/doc/man-pages/.
212
213
214
215Linux                             2017-09-15                           UTMP(5)
Impressum