login, logout - write utmp and wtmp entries
Contents
Attributes
For an explanation of the terms used in this section, see attributes(7).
┌───────────────────┬───────────────┬───────────────────────────────────────────────────────────────────┐
│ Interface │ Attribute │ Value │
├───────────────────┼───────────────┼───────────────────────────────────────────────────────────────────┤
│ login(), logout() │ Thread safety │ MT-Unsafe race:utent sig:ALRM timer │
└───────────────────┴───────────────┴───────────────────────────────────────────────────────────────────┘
In the above table, utent in race:utent signifies that if any of the functions setutent(3), getutent(3),
or endutent(3) are used in parallel in different threads of a program, then data races could occur.
login() and logout() calls those functions, so we use race:utent to remind users.
Description
The utmp file records who is currently using the system. The wtmp file records all logins and logouts.
See utmp(5).
The function login() takes the supplied structutmp, ut, and writes it to both the utmp and the wtmp
file.
The function logout() clears the entry in the utmp file again.
GNUdetails
More precisely, login() takes the argument ut struct, fills the field ut->ut_type (if there is such a
field) with the value USER_PROCESS, and fills the field ut->ut_pid (if there is such a field) with the
process ID of the calling process. Then it tries to fill the field ut->ut_line. It takes the first of
stdin, stdout, stderr that is a terminal, and stores the corresponding pathname minus a possible leading
/dev/ into this field, and then writes the struct to the utmp file. On the other hand, if no terminal
name was found, this field is filled with "???" and the struct is not written to the utmp file. After
this, the struct is written to the wtmp file.
The logout() function searches the utmp file for an entry matching the ut_line argument. If a record is
found, it is updated by zeroing out the ut_name and ut_host fields, updating the ut_tv timestamp field
and setting ut_type (if there is such a field) to DEAD_PROCESS.
Files
/var/run/utmp user accounting database, configured through _PATH_UTMP in <paths.h>/var/log/wtmp user accounting log file, configured through _PATH_WTMP in <paths.h>
Library
System utilities library (libutil, -lutil)
Name
login, logout - write utmp and wtmp entries
Return Value
The logout() function returns 1 if the entry was successfully written to the database, or 0 if an error
occurred.
See Also
getutent(3), utmp(5) Linux man-pages 6.9.1 2024-05-02 login(3)
Standards
BSD.
Synopsis
#include<utmp.h>voidlogin(conststructutmp*ut);intlogout(constchar*ut_line);Versions
The member ut_user of structutmp is called ut_name in BSD. Therefore, ut_name is defined as an alias
for ut_user in <utmp.h>.
