getutxent / getutxid / getutxline / pututxline / setutxent / endutxent (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 | utmpx.h (six POSIX functions unconditional; utmpxname under __USE_GNU) |
| Standards | XPG4.2; included in POSIX.1 via XSI (getutent(3) CONFORMING TO, manual XPG Functions) |
| Exported | getutxent, getutxid, getutxline, pututxline, setutxent, endutxent, utmpxname all @@GLIBC_2.2.5 (nm, host glibc 2.41) |
| Thread-safety | MT-Unsafe race:utent – on glibc the x functions are aliases of the utmp.h originals (manual XPG Functions) |
| Ledger ID | GLIBC-getutxent, GLIBC-getutxid, GLIBC-getutxline, GLIBC-pututxline, GLIBC-setutxent, GLIBC-endutxent, GLIBC-utmpxname |
Declaration and gates
#include <utmpx.h>
void setutxent(void);
void endutxent(void);
struct utmpx *getutxent(void);
struct utmpx *getutxid(const struct utmpx *id);
struct utmpx *getutxline(const struct utmpx *line);
struct utmpx *pututxline(const struct utmpx *utmpx);
int utmpxname(const char *file); /* __USE_GNU */
The six XPG prototypes are unconditional (/usr/include/utmpx.h lines
53-83); utmpxname sits in the #ifdef __USE_GNU block at lines
86-93, next to updwtmpx, getutmp and getutmpx.
Semantics
Same contracts as the utmp.h family with struct utmpx records:
setutxent rewinds the database, getutxent reads the next entry,
endutxent closes it, getutxid searches by ut_type or ut_id,
getutxline by ut_line, pututxline writes an entry (rewinding or
searching first, per the ut_type of the argument). utmpxname is the
glibc-only file-name selector and is not specified by POSIX
(getutent(3)). The header’s comments mark setutxent, endutxent,
getutxent, getutxid, getutxline and pututxline as possible
cancellation points (comments above the prototypes, lines 50-83), a
detail the utmp.h declarations do not spell out.
Gotchas and portability
- On Linux, glibc keeps no parallel
utmpxfile:struct utmpxis identical tostruct utmp, and thexfunctions are plain aliases of their counterparts (getutent(3)CONFORMING TO; manual node XPG Functions). On other systemsutmpxis a superset with parallelutmpx/wtmpxfiles. - POSIX specifies no
_rforms here; usegetutmp/getutmpx(see conversion page) when structures must move between the two spellings. - The
ut_typeconstants (EMPTYthroughDEAD_PROCESS, values 0-8,bits/utmp.hlines 103-113) are shared withutmp.h(manual XPG Functions vtable). - musl 1.2.5: same story as
utmp– all six functions plusutmpxnameare stubs insrc/legacy/utmpx.creturning NULL, doing nothing, or failing withENOTSUP.
References
- glibc manual:
users.texi, nodes XPG Functions, Manipulating the Database - man3:
getutent.3(POSIX.1 synopsis lists the wholeutmpxfamily;getutxent.3is a link to it) - headers:
/usr/include/utmpx.h,bits/utmpx.h - siblings: utmp page, login page
- symbols:
nm -D --with-symbol-versions libc.so.6