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