updwtmp / logwtmp (3) - glibc
Split from the chapter glibc: Users and Groups into the per-function layout; see the method page and the glibc ledger for coverage status.
| Field | Value |
|---|---|
| Header | utmp.h |
| Standards | BSD/SVID origin; not in POSIX.1 (manual Logging In and Out groups them with the libutil-derived functions) |
| Exported | updwtmp@@GLIBC_2.2.5 weak; logwtmp@@GLIBC_2.34 default with compat logwtmp@GLIBC_2.2.5 (nm, host glibc 2.41) |
| Thread-safety | MT-Unsafe sig:ALRM, timer; async-unsafe fd use (acsfd) – manual safety annotations in users.texi (Logging In and Out) |
| Ledger ID | GLIBC-updwtmp, GLIBC-logwtmp |
Declaration and gates
#include <utmp.h>
void updwtmp(const char *wtmp_file, const struct utmp *utmp);
void logwtmp(const char *ut_line, const char *ut_name,
const char *ut_host);
Both prototypes are unconditional in /usr/include/utmp.h (updwtmp
at lines 55-56, logwtmp at lines 51-52), directly under the
login/logout declarations.
Semantics
The wtmp log (/var/log/wtmp, _PATH_WTMP from paths.h) records
every login, logout, boot and shutdown as a struct utmp record
appended over time. updwtmp appends the given entry to the named
wtmp-like file, creating or updating it in the layout the utmp readers
expect (manual, Manipulating the Database). logwtmp is a shortcut:
it builds the record itself – ut_line, ut_name and ut_host from
the arguments, plus the current time and the calling process ID – and
appends it to the standard wtmp file (manual, Logging In and Out).
Neither function returns a value; failures to open or write the log are
silent.
Gotchas and portability
- Symbol archaeology:
login,logout,logwtmpandlogin_ttylived inlibutiluntil glibc 2.34 merged that library into libc, so binaries keep a@GLIBC_2.2.5compat version while new code links@@GLIBC_2.34;updwtmpwas always in libc and shows only@@GLIBC_2.2.5. Applications written against old glibc needed-lutil; modern ones do not. - The manual’s portability note: the BSD
struct utmphas onlyut_line,ut_name,ut_hostandut_time, and older systems lack evenut_host. - Writers must go through these wrappers rather than
open(2)-ing the log directly; the file format and locking belong to libc (manual, User Accounting Database). - musl 1.2.5:
updwtmpis declared ininclude/utmp.hbut resolves to theupdwtmpxstub (weak_aliasinsrc/legacy/utmpx.c);logwtmpdoes not exist at all.
References
- glibc manual:
users.texi, nodes Manipulating the Database (updwtmp), Logging In and Out (logwtmp) - man3:
login.3(wtmp writers context),getutent.3(file paths) - headers:
/usr/include/utmp.h,paths.h - siblings: login page, utmp page
- symbols:
nm -D --with-symbol-versions libc.so.6