user_namespaces.7: Document /proc/PID/projid_map
[man-pages.git] / man5 / utmp.5
blob3f608c98c42d21f82f491ad1fc4622214af25d75
1 .\" Copyright (c) 1993 Michael Haardt (michael@cantor.informatik.rwth-aachen.de),
2 .\" Fri Apr  2 11:32:09 MET DST 1993
3 .\"
4 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
5 .\" This is free documentation; you can redistribute it and/or
6 .\" modify it under the terms of the GNU General Public License as
7 .\" published by the Free Software Foundation; either version 2 of
8 .\" the License, or (at your option) any later version.
9 .\"
10 .\" The GNU General Public License's references to "object code"
11 .\" and "executables" are to be interpreted as the output of any
12 .\" document formatting or typesetting system, including
13 .\" intermediate and printed output.
14 .\"
15 .\" This manual is distributed in the hope that it will be useful,
16 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
17 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 .\" GNU General Public License for more details.
19 .\"
20 .\" You should have received a copy of the GNU General Public
21 .\" License along with this manual; if not, see
22 .\" <http://www.gnu.org/licenses/>.
23 .\" %%%LICENSE_END
24 .\"
25 .\" Modified 1993-07-25 by Rik Faith (faith@cs.unc.edu)
26 .\" Modified 1995-02-26 by Michael Haardt
27 .\" Modified 1996-07-20 by Michael Haardt
28 .\" Modified 1997-07-02 by Nicolás Lichtmaier <nick@debian.org>
29 .\" Modified 2004-10-31 by aeb, following Gwenole Beauchesne
30 .TH UTMP 5 2021-03-22 "Linux" "Linux Programmer's Manual"
31 .SH NAME
32 utmp, wtmp \- login records
33 .SH SYNOPSIS
34 .nf
35 .B #include <utmp.h>
36 .fi
37 .SH DESCRIPTION
38 The
39 .I utmp
40 file allows one to discover information about who is currently using the
41 system.
42 There may be more users currently using the system, because not
43 all programs use utmp logging.
44 .PP
45 .B Warning:
46 .I utmp
47 must not be writable by the user class "other",
48 because many system programs (foolishly)
49 depend on its integrity.
50 You risk faked system logfiles and
51 modifications of system files if you leave
52 .I utmp
53 writable to any user other than the owner and group owner of the file.
54 .PP
55 The file is a sequence of
56 .I utmp
57 structures,
58 declared as follows in
59 .IR <utmp.h>
60 (note that this is only one of several definitions
61 around; details depend on the version of libc):
62 .PP
63 .in +4n
64 .EX
65 /* Values for ut_type field, below */
67 #define EMPTY         0 /* Record does not contain valid info
68                            (formerly known as UT_UNKNOWN on Linux) */
69 #define RUN_LVL       1 /* Change in system run\-level (see
70                            \fBinit\fP(1)) */
71 #define BOOT_TIME     2 /* Time of system boot (in \fIut_tv\fP) */
72 #define NEW_TIME      3 /* Time after system clock change
73                            (in \fIut_tv\fP) */
74 #define OLD_TIME      4 /* Time before system clock change
75                            (in \fIut_tv\fP) */
76 #define INIT_PROCESS  5 /* Process spawned by \fBinit\fP(1) */
77 #define LOGIN_PROCESS 6 /* Session leader process for user login */
78 #define USER_PROCESS  7 /* Normal process */
79 #define DEAD_PROCESS  8 /* Terminated process */
80 #define ACCOUNTING    9 /* Not implemented */
82 #define UT_LINESIZE      32
83 #define UT_NAMESIZE      32
84 #define UT_HOSTSIZE     256
86 struct exit_status {              /* Type for ut_exit, below */
87     short e_termination;          /* Process termination status */
88     short e_exit;                 /* Process exit status */
91 struct utmp {
92     short   ut_type;              /* Type of record */
93     pid_t   ut_pid;               /* PID of login process */
94     char    ut_line[UT_LINESIZE]; /* Device name of tty \- "/dev/" */
95     char    ut_id[4];             /* Terminal name suffix,
96                                      or inittab(5) ID */
97     char    ut_user[UT_NAMESIZE]; /* Username */
98     char    ut_host[UT_HOSTSIZE]; /* Hostname for remote login, or
99                                      kernel version for run\-level
100                                      messages */
101     struct  exit_status ut_exit;  /* Exit status of a process
102                                      marked as DEAD_PROCESS; not
103                                      used by Linux init(1) */
104     /* The ut_session and ut_tv fields must be the same size when
105        compiled 32\- and 64\-bit.  This allows data files and shared
106        memory to be shared between 32\- and 64\-bit applications. */
107 #if __WORDSIZE == 64 && defined __WORDSIZE_COMPAT32
108     int32_t ut_session;           /* Session ID (\fBgetsid\fP(2)),
109                                      used for windowing */
110     struct {
111         int32_t tv_sec;           /* Seconds */
112         int32_t tv_usec;          /* Microseconds */
113     } ut_tv;                      /* Time entry was made */
114 #else
115      long   ut_session;           /* Session ID */
116      struct timeval ut_tv;        /* Time entry was made */
117 #endif
119     int32_t ut_addr_v6[4];        /* Internet address of remote
120                                      host; IPv4 address uses
121                                      just ut_addr_v6[0] */
122     char __unused[20];            /* Reserved for future use */
125 /* Backward compatibility hacks */
126 #define ut_name ut_user
127 #ifndef _NO_UT_TIME
128 #define ut_time ut_tv.tv_sec
129 #endif
130 #define ut_xtime ut_tv.tv_sec
131 #define ut_addr ut_addr_v6[0]
135 This structure gives the name of the special file associated with the
136 user's terminal, the user's login name, and the time of login in the form
138 .BR time (2).
139 String fields are terminated by a null byte (\(aq\e0\(aq)
140 if they are shorter than the size
141 of the field.
143 The first entries ever created result from
144 .BR init (1)
145 processing
146 .BR inittab (5).
147 Before an entry is processed, though,
148 .BR init (1)
149 cleans up utmp by setting \fIut_type\fP to \fBDEAD_PROCESS\fP, clearing
150 \fIut_user\fP, \fIut_host\fP, and \fIut_time\fP with null bytes for each
151 record which \fIut_type\fP is not \fBDEAD_PROCESS\fP or \fBRUN_LVL\fP
152 and where no process with PID \fIut_pid\fP exists.
153 If no empty record
154 with the needed \fIut_id\fP can be found,
155 .BR init (1)
156 creates a new one.
157 It sets \fIut_id\fP from the inittab, \fIut_pid\fP and \fIut_time\fP to the
158 current values, and \fIut_type\fP to \fBINIT_PROCESS\fP.
160 .BR mingetty (8)
162 .BR agetty (8))
163 locates the entry by the PID, changes \fIut_type\fP to
164 \fBLOGIN_PROCESS\fP, changes \fIut_time\fP, sets \fIut_line\fP, and waits
165 for connection to be established.
166 .BR login (1),
167 after a user has been
168 authenticated, changes \fIut_type\fP to \fBUSER_PROCESS\fP, changes
169 \fIut_time\fP, and sets \fIut_host\fP and \fIut_addr\fP.
170 Depending on
171 .BR mingetty (8)
173 .BR agetty (8))
175 .BR login (1),
176 records may be located by
177 \fIut_line\fP instead of the preferable \fIut_pid\fP.
179 When
180 .BR init (1)
181 finds that a process has exited, it locates its utmp entry by
182 .IR ut_pid ,
183 sets
184 .I ut_type
186 .BR DEAD_PROCESS ,
187 and clears
188 .IR ut_user ,
189 .IR ut_host ,
191 .I ut_time
192 with null bytes.
194 .BR xterm (1)
195 and other terminal emulators directly create a
196 \fBUSER_PROCESS\fP record and generate the \fIut_id\fP by using the
197 string that suffix part of the terminal name (the characters
198 following \fI/dev/[pt]ty\fP).
199 If they find a \fBDEAD_PROCESS\fP for this ID,
200 they recycle it, otherwise they create a new entry.
201 If they can, they
202 will mark it as \fBDEAD_PROCESS\fP on exiting and it is advised that
203 they null \fIut_line\fP, \fIut_time\fP, \fIut_user\fP, and \fIut_host\fP
204 as well.
206 .BR telnetd (8)
207 sets up a \fBLOGIN_PROCESS\fP entry and leaves the rest to
208 .BR login (1)
209 as usual.
210 After the telnet session ends,
211 .BR telnetd (8)
212 cleans up utmp in the described way.
214 The \fIwtmp\fP file records all logins and logouts.
215 Its format is exactly like \fIutmp\fP except that a null username
216 indicates a logout
217 on the associated terminal.
218 Furthermore, the terminal name \fB\(ti\fP
219 with username \fBshutdown\fP or \fBreboot\fP indicates a system
220 shutdown or reboot and the pair of terminal names \fB|\fP/\fB}\fP
221 logs the old/new system time when
222 .BR date (1)
223 changes it.
224 \fIwtmp\fP is maintained by
225 .BR login (1),
226 .BR init (1),
227 and some versions of
228 .BR getty (8)
229 (e.g.,
230 .BR mingetty (8)
232 .BR agetty (8)).
233 None of these programs creates the file, so if it is
234 removed, record-keeping is turned off.
235 .SH FILES
236 .I /var/run/utmp
238 .I /var/log/wtmp
239 .SH CONFORMING TO
240 POSIX.1 does not specify a
241 .I utmp
242 structure, but rather one named
243 .IR utmpx ,
244 with specifications for the fields
245 .IR ut_type ,
246 .IR ut_pid ,
247 .IR ut_line ,
248 .IR ut_id ,
249 .IR ut_user ,
251 .IR ut_tv .
252 POSIX.1 does not specify the lengths of the
253 .I ut_line
255 .I ut_user
256 fields.
258 Linux defines the
259 .I utmpx
260 structure to be the same as the
261 .I utmp
262 structure.
263 .SS Comparison with historical systems
264 Linux utmp entries conform neither to v7/BSD nor to System V; they are a
265 mix of the two.
267 v7/BSD has fewer fields; most importantly it lacks
268 \fIut_type\fP, which causes native v7/BSD-like programs to display (for
269 example) dead or login entries.
270 Further, there is no configuration file
271 which allocates slots to sessions.
272 BSD does so because it lacks \fIut_id\fP fields.
274 In Linux (as in System V), the \fIut_id\fP field of a
275 record will never change once it has been set, which reserves that slot
276 without needing a configuration file.
277 Clearing \fIut_id\fP may result
278 in race conditions leading to corrupted utmp entries and potential
279 security holes.
280 Clearing the abovementioned fields by filling them
281 with null bytes is not required by System V semantics,
282 but makes it possible to run
283 many programs which assume BSD semantics and which do not modify utmp.
284 Linux uses the BSD conventions for line contents, as documented above.
286 .\" mtk: What is the referrent of "them" in the following sentence?
287 .\" System V only uses the type field to mark them and logs
288 .\" informative messages such as \fB"new time"\fP in the line field.
289 System V has no \fIut_host\fP or \fIut_addr_v6\fP fields.
290 .SH NOTES
291 Unlike various other
292 systems, where utmp logging can be disabled by removing the file, utmp
293 must always exist on Linux.
294 If you want to disable
295 .BR who (1),
296 then do not make utmp world readable.
298 The file format is machine-dependent, so it is recommended that it be
299 processed only on the machine architecture where it was created.
301 Note that on \fIbiarch\fP platforms, that is, systems which can run both
302 32-bit and 64-bit applications (x86-64, ppc64, s390x, etc.),
303 \fIut_tv\fP is the same size in 32-bit mode as in 64-bit mode.
304 The same goes for \fIut_session\fP and \fIut_time\fP if they are present.
305 This allows data files and shared memory to be shared between
306 32-bit and 64-bit applications.
307 This is achieved by changing the type of
308 .I ut_session
310 .IR int32_t ,
311 and that of
312 .I ut_tv
313 to a struct with two
314 .I int32_t
315 fields
316 .I tv_sec
318 .IR tv_usec .
319 Since \fIut_tv\fP may not be the same as \fIstruct timeval\fP,
320 then instead of the call:
322 .in +4n
324 gettimeofday((struct timeval *) &ut.ut_tv, NULL);
328 the following method of setting this field is recommended:
330 .in +4n
332 struct utmp ut;
333 struct timeval tv;
335 gettimeofday(&tv, NULL);
336 ut.ut_tv.tv_sec = tv.tv_sec;
337 ut.ut_tv.tv_usec = tv.tv_usec;
340 .\" .PP
341 .\" Note that the \fIutmp\fP struct from libc5 has changed in libc6.
342 .\" Because of this,
343 .\" binaries using the old libc5 struct will corrupt
344 .\" .IR /var/run/utmp " and/or " /var/log/wtmp .
345 .\" .SH BUGS
346 .\" This man page is based on the libc5 one, things may work differently now.
347 .SH SEE ALSO
348 .BR ac (1),
349 .BR date (1),
350 .BR init (1),
351 .BR last (1),
352 .BR login (1),
353 .BR logname (1),
354 .BR lslogins (1),
355 .BR users (1),
356 .BR utmpdump (1),
357 .BR who (1),
358 .BR getutent (3),
359 .BR getutmp (3),
360 .BR login (3),
361 .BR logout (3),
362 .BR logwtmp (3),
363 .BR updwtmp (3)