login(3)
β¨ login(3) β bestie edition β¨
okay so this is the login page from section 3 of the manual (library functions, iykyk), and it's genuinely so important because it's all about who's logged into ur machine rn π
π NAME π
login, logout β write utmp and wtmp entries
π LIBRARY π
System utilities library β that's libutil, and you link it with -lutil πΈ
π SYNOPSIS π
#include <utmp.h>
void login(const struct utmp *ut);
int logout(const char *ut_line);
π¦ DESCRIPTION π¦
So the utmp file is the receipts file β it records who is currently using the system, like right this second. The wtmp file is the full lore archive β it records all logins and logouts, ever. Peep utmp(5) if u wanna know more, bestie.
The login() function takes the struct utmp u hand it, called ut, and writes it to both the utmp file AND the wtmp file. Two files, one function call. Iconic behavior fr fr β¨
The logout() function clears the entry in the utmp file again. Cleanup queen π
π GNU details π
okay now the real tea, this is the precise version π
login() takes that ut struct argument, and fills the field ut->ut_type (if there is such a field) with the value USER_PROCESS. Then it 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.
For that 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.
But lowkey watch out β if no terminal name was found, this field is filled with"???"and the struct is not written to theutmpfile. Then after all of this, the struct is written to thewtmpfile. no cap, that's the flow π
The logout() function searches the utmp file for an entry matching the ut_line argument. If a record is found, it gets updated by:
- zeroing out the
ut_nameandut_hostfields - updating the
ut_tvtimestamp field - setting
ut_type(if there is such a field) toDEAD_PROCESS
π« RETURN VALUE π«
The logout() function returns 1 if the entry was successfully written to the database, or 0 if an error occurred. That's it, that's the whole vibe check π«Ά
π FILES π
/var/run/utmpβ the user accounting database, configured through_PATH_UTMPin<paths.h>/var/log/wtmpβ the user accounting log file, configured through_PATH_WTMPin<paths.h>
π ATTRIBUTES π
For an explanation of the terms used in this section, see attributes(7).
- Interface:
login(),logout() - Attribute: Thread safety
- Value:
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() call those functions, so we use race:utent to remind users. so likeβ¦ be careful with threads bestie, this one's not thread-safe π
πΈ VERSIONS πΈ
The member ut_user of struct utmp is called ut_name in BSD. Therefore, ut_name is defined as an alias for ut_user in <utmp.h>. same thing, different name, it's giving rebrand β¨
β STANDARDS β
BSD.
π₯ SEE ALSO π₯
mwah π that's the whole page β go log somebody in (responsibly). this was pulled from the Linux man-pages, version 6.20, dated 2026-02-08. take care of urself bestie, drink water, and always close ur file descriptors π«Άβ¨
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: GPL-2.0-or-later
- Copyright 2002, Martin Schulze <joey@debian.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms