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 the utmp file. Then after all of this, the struct is written to the wtmp file. 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_name and ut_host fields
  • updating the ut_tv timestamp field
  • setting ut_type (if there is such a field) to DEAD_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_UTMP in <paths.h>
  • /var/log/wtmp β€” the user accounting log file, configured through _PATH_WTMP in <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 πŸ”₯

getutent(3), utmp(5)


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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms