1LOGIN(3) Linux Programmer's Manual LOGIN(3)
2
3
4
6 login, logout - write utmp and wtmp entries
7
9 #include <utmp.h>
10
11 void login(const struct utmp *ut);
12 int logout(const char *ut_line);
13
14 Link with -lutil.
15
17 The utmp file records who is currently using the system. The wtmp file
18 records all logins and logouts. See utmp(5).
19
20 The function login() takes the supplied struct utmp, ut, and writes it
21 to both the utmp and the wtmp file.
22
23 The function logout() clears the entry in the utmp file again.
24
25 GNU details
26 More precisely, login() takes the argument ut struct, fills the field
27 ut->ut_type (if there is such a field) with the value USER_PROCESS, and
28 fills the field ut->ut_pid (if there is such a field) with the process
29 ID of the calling process. Then it tries to fill the field
30 ut->ut_line. It takes the first of stdin, stdout, stderr that is a
31 terminal, and stores the corresponding pathname minus a possible lead‐
32 ing /dev/ into this field, and then writes the struct to the utmp file.
33 On the other hand, if no terminal name was found, this field is filled
34 with "???" and the struct is not written to the utmp file. After
35 this, the struct is written to the wtmp file.
36
37 The logout() function searches the utmp file for an entry matching the
38 ut_line argument. If a record is found, it is updated by zeroing out
39 the ut_name and ut_host fields, updating the ut_tv timestamp field and
40 setting ut_type (if there is such a field) to DEAD_PROCESS.
41
43 The logout() function returns 1 if the entry was successfully written
44 to the database, or 0 if an error occurred.
45
47 /var/run/utmp
48 user accounting database, configured through _PATH_UTMP in
49 <paths.h>
50
51 /var/log/wtmp
52 user accounting log file, configured through _PATH_WTMP in
53 <paths.h>
54
56 For an explanation of the terms used in this section, see at‐
57 tributes(7).
58
59 ┌──────────────────┬───────────────┬───────────────────────────────────┐
60 │Interface │ Attribute │ Value │
61 ├──────────────────┼───────────────┼───────────────────────────────────┤
62 │login(), logout() │ Thread safety │ MT-Unsafe race:utent sig:ALRM │
63 │ │ │ timer │
64 └──────────────────┴───────────────┴───────────────────────────────────┘
65 In the above table, utent in race:utent signifies that if any of the
66 functions setutent(3), getutent(3), or endutent(3) are used in parallel
67 in different threads of a program, then data races could occur. lo‐
68 gin() and logout() calls those functions, so we use race:utent to re‐
69 mind users.
70
72 Not in POSIX.1. Present on the BSDs.
73
75 Note that the member ut_user of struct utmp is called ut_name in BSD.
76 Therefore, ut_name is defined as an alias for ut_user in <utmp.h>.
77
79 getutent(3), utmp(5)
80
82 This page is part of release 5.13 of the Linux man-pages project. A
83 description of the project, information about reporting bugs, and the
84 latest version of this page, can be found at
85 https://www.kernel.org/doc/man-pages/.
86
87
88
89GNU 2021-03-22 LOGIN(3)