The STRUCT_UTMP typedef was introduced and began being used by readutmp
in this Gnulib commit:
commit 622d2c0763777eb909a4fda5048238f524cc36f9
Author: Bruno Haible <[email protected]>
AuthorDate: Tue Aug 8 17:36:10 2023 +0200
Commit: Bruno Haible <[email protected]>
CommitDate: Tue Aug 8 18:04:53 2023 +0200
readutmp: Return entries with unbounded strings on all platforms.
I think it looks nicer than 'struct gl_utmp'. And the prototypes in
readutmp.h use them, so it is easier to find references to what the
structure is by changing it.
Will push the attatched patch in a bit.
Collin
>From 22f5a2e6428dc1f3d11ac425d45128a756e526de Mon Sep 17 00:00:00 2001
Message-ID: <22f5a2e6428dc1f3d11ac425d45128a756e526de.1755985637.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Sat, 23 Aug 2025 14:26:45 -0700
Subject: [PATCH] maint: prefer STRUCT_UTMP to struct gl_utmp
* cfg.mk (sc_prohibit-struct-gl_utmp): New rule for 'make syntax-check'.
* src/pinky.c (time_string, print_entry, scan_entries, short_pinky):
Use STRUCT_UTMP instead of struct gl_utmp.
* src/uptime.c (print_uptime, print_uptime, uptime): Likewise.
* src/users.c (list_entries_users, users): Likewise.
* src/who.c (time_string, print_user, print_boottime, print_deadprocs)
(print_login, print_initspawn, print_clockchange, print_runlevel)
list_entries_who, scan_entries, who): Likewise.
---
cfg.mk | 7 +++++++
src/pinky.c | 8 ++++----
src/uptime.c | 6 +++---
src/users.c | 4 ++--
src/who.c | 24 ++++++++++++------------
5 files changed, 28 insertions(+), 21 deletions(-)
diff --git a/cfg.mk b/cfg.mk
index 2db427012..093305c2b 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -311,6 +311,13 @@ sc_prohibit-_gl-attributes:
halt='Use ATTRIBUTE_... instead of _GL_ATTRIBUTE_...' \
$(_sc_search_regexp)
+# Prefer the STRUCT_UTMP typedef over struct gl_utmp.
+sc_prohibit-struct-gl_utmp:
+ @prohibit='struct gl_utmp' \
+ in_vc_files='\.[ch]$$' \
+ halt='Use STRUCT_UTMP, not struct gl_utmp' \
+ $(_sc_search_regexp)
+
# Prefer the const declaration form, with const following the type
sc_prohibit-const-char:
@prohibit='const char \*' \
diff --git a/src/pinky.c b/src/pinky.c
index 7fda56ba2..287b3a3f2 100644
--- a/src/pinky.c
+++ b/src/pinky.c
@@ -179,7 +179,7 @@ idle_string (time_t when)
/* Return a time string. */
static char const *
-time_string (struct gl_utmp const *utmp_ent)
+time_string (STRUCT_UTMP const *utmp_ent)
{
static char buf[INT_STRLEN_BOUND (intmax_t) + sizeof "-%m-%d %H:%M"];
struct tm *tmp = localtime (&utmp_ent->ut_ts.tv_sec);
@@ -196,7 +196,7 @@ time_string (struct gl_utmp const *utmp_ent)
/* Display a line of information about UTMP_ENT. */
static void
-print_entry (struct gl_utmp const *utmp_ent)
+print_entry (STRUCT_UTMP const *utmp_ent)
{
struct stat stats;
time_t last_change;
@@ -428,7 +428,7 @@ print_heading (void)
/* Display UTMP_BUF, which should have N entries. */
static void
-scan_entries (idx_t n, struct gl_utmp const *utmp_buf,
+scan_entries (idx_t n, STRUCT_UTMP const *utmp_buf,
const int argc_names, char *const argv_names[])
{
if (hard_locale (LC_TIME))
@@ -472,7 +472,7 @@ short_pinky (char const *filename,
const int argc_names, char *const argv_names[])
{
idx_t n_users;
- struct gl_utmp *utmp_buf;
+ STRUCT_UTMP *utmp_buf;
if (read_utmp (filename, &n_users, &utmp_buf, READ_UTMP_USER_PROCESS) != 0)
error (EXIT_FAILURE, errno, "%s", quotef (filename));
diff --git a/src/uptime.c b/src/uptime.c
index 63b355121..0faaf0662 100644
--- a/src/uptime.c
+++ b/src/uptime.c
@@ -37,7 +37,7 @@
proper_name ("Kaveh Ghazi")
static int
-print_uptime (idx_t n, struct gl_utmp const *utmp_buf)
+print_uptime (idx_t n, STRUCT_UTMP const *utmp_buf)
{
int status = EXIT_SUCCESS;
time_t boot_time = 0;
@@ -47,7 +47,7 @@ print_uptime (idx_t n, struct gl_utmp const *utmp_buf)
idx_t entries = 0;
for (idx_t i = 0; i < n; i++)
{
- struct gl_utmp const *this = &utmp_buf[i];
+ STRUCT_UTMP const *this = &utmp_buf[i];
entries += IS_USER_PROCESS (this);
if (UT_TYPE_BOOT_TIME (this))
boot_time = this->ut_ts.tv_sec;
@@ -125,7 +125,7 @@ static _Noreturn void
uptime (char const *filename, int options)
{
idx_t n_users;
- struct gl_utmp *utmp_buf;
+ STRUCT_UTMP *utmp_buf;
int read_utmp_status = (read_utmp (filename, &n_users, &utmp_buf, options) < 0
? EXIT_FAILURE : EXIT_SUCCESS);
if (read_utmp_status != EXIT_SUCCESS)
diff --git a/src/users.c b/src/users.c
index 6e730eaf1..5e298acd5 100644
--- a/src/users.c
+++ b/src/users.c
@@ -42,7 +42,7 @@ userid_compare (const void *v_a, const void *v_b)
}
static void
-list_entries_users (idx_t n, struct gl_utmp const *this)
+list_entries_users (idx_t n, STRUCT_UTMP const *this)
{
char **u = xinmalloc (n, sizeof *u);
idx_t i;
@@ -83,7 +83,7 @@ static void
users (char const *filename, int options)
{
idx_t n_users;
- struct gl_utmp *utmp_buf;
+ STRUCT_UTMP *utmp_buf;
options |= READ_UTMP_USER_PROCESS;
if (read_utmp (filename, &n_users, &utmp_buf, options) != 0)
error (EXIT_FAILURE, errno, "%s", quotef (filename));
diff --git a/src/who.c b/src/who.c
index b481dd2f8..c4205a554 100644
--- a/src/who.c
+++ b/src/who.c
@@ -205,7 +205,7 @@ idle_string (time_t when, time_t boottime)
/* Return a time string. */
static char const *
-time_string (struct gl_utmp const *utmp_ent)
+time_string (STRUCT_UTMP const *utmp_ent)
{
static char buf[INT_STRLEN_BOUND (intmax_t) + sizeof "-%m-%d %H:%M"];
struct tm *tmp = localtime (&utmp_ent->ut_ts.tv_sec);
@@ -312,7 +312,7 @@ is_tty_writable (struct stat const *pstat)
/* Send properly parsed USER_PROCESS info to print_line. The most
recent boot time is BOOTTIME. */
static void
-print_user (struct gl_utmp const *utmp_ent, time_t boottime)
+print_user (STRUCT_UTMP const *utmp_ent, time_t boottime)
{
struct stat stats;
time_t last_change;
@@ -426,14 +426,14 @@ print_user (struct gl_utmp const *utmp_ent, time_t boottime)
}
static void
-print_boottime (struct gl_utmp const *utmp_ent)
+print_boottime (STRUCT_UTMP const *utmp_ent)
{
print_line ("", ' ', _("system boot"),
time_string (utmp_ent), "", "", "", "");
}
static char *
-make_id_equals_comment (struct gl_utmp const *utmp_ent)
+make_id_equals_comment (STRUCT_UTMP const *utmp_ent)
{
char const *id = UT_ID (utmp_ent);
idx_t idlen = strlen (id);
@@ -447,7 +447,7 @@ make_id_equals_comment (struct gl_utmp const *utmp_ent)
}
static void
-print_deadprocs (struct gl_utmp const *utmp_ent)
+print_deadprocs (STRUCT_UTMP const *utmp_ent)
{
static char *exitstr;
char *comment = make_id_equals_comment (utmp_ent);
@@ -470,7 +470,7 @@ print_deadprocs (struct gl_utmp const *utmp_ent)
}
static void
-print_login (struct gl_utmp const *utmp_ent)
+print_login (STRUCT_UTMP const *utmp_ent)
{
char *comment = make_id_equals_comment (utmp_ent);
PIDSTR_DECL_AND_INIT (pidstr, utmp_ent);
@@ -483,7 +483,7 @@ print_login (struct gl_utmp const *utmp_ent)
}
static void
-print_initspawn (struct gl_utmp const *utmp_ent)
+print_initspawn (STRUCT_UTMP const *utmp_ent)
{
char *comment = make_id_equals_comment (utmp_ent);
PIDSTR_DECL_AND_INIT (pidstr, utmp_ent);
@@ -494,7 +494,7 @@ print_initspawn (struct gl_utmp const *utmp_ent)
}
static void
-print_clockchange (struct gl_utmp const *utmp_ent)
+print_clockchange (STRUCT_UTMP const *utmp_ent)
{
/* FIXME: handle NEW_TIME & OLD_TIME both */
print_line ("", ' ', _("clock change"),
@@ -502,7 +502,7 @@ print_clockchange (struct gl_utmp const *utmp_ent)
}
static void
-print_runlevel (struct gl_utmp const *utmp_ent)
+print_runlevel (STRUCT_UTMP const *utmp_ent)
{
static char *runlevline, *comment;
unsigned char last = utmp_ent->ut_pid / 256;
@@ -525,7 +525,7 @@ print_runlevel (struct gl_utmp const *utmp_ent)
/* Print the username of each valid entry and the number of valid entries
in UTMP_BUF, which should have N elements. */
static void
-list_entries_who (idx_t n, struct gl_utmp const *utmp_buf)
+list_entries_who (idx_t n, STRUCT_UTMP const *utmp_buf)
{
idx_t entries = 0;
char const *separator = "";
@@ -557,7 +557,7 @@ print_heading (void)
/* Display UTMP_BUF, which should have N entries. */
static void
-scan_entries (idx_t n, struct gl_utmp const *utmp_buf)
+scan_entries (idx_t n, STRUCT_UTMP const *utmp_buf)
{
char *ttyname_b IF_LINT ( = nullptr);
time_t boottime = TYPE_MINIMUM (time_t);
@@ -611,7 +611,7 @@ static void
who (char const *filename, int options)
{
idx_t n_users;
- struct gl_utmp *utmp_buf;
+ STRUCT_UTMP *utmp_buf;
if (short_list)
options |= READ_UTMP_USER_PROCESS;
if (read_utmp (filename, &n_users, &utmp_buf, options) != 0)
--
2.51.0