]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: prefer STRUCT_UTMP to struct gl_utmp
authorCollin Funk <collin.funk1@gmail.com>
Sat, 23 Aug 2025 21:26:45 +0000 (14:26 -0700)
committerCollin Funk <collin.funk1@gmail.com>
Sun, 24 Aug 2025 01:10:07 +0000 (18:10 -0700)
* 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
src/pinky.c
src/uptime.c
src/users.c
src/who.c

diff --git a/cfg.mk b/cfg.mk
index 2db427012f1f81fc47d0a8ec0cccf290bb906625..093305c2b41dfc04266f667265092d2cd8614083 100644 (file)
--- 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 \*'                               \
index 7fda56ba2caba09df5a019973a91347fbe4fdc4a..287b3a3f2bb3333c31cf64541898230c13eca483 100644 (file)
@@ -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));
 
index 63b355121fa7ce2c344ca821d54b755ba91470f5..0faaf0662f60231bff6fe65ae2b4d7e008a280bb 100644 (file)
@@ -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)
index 6e730eaf11296d05091b40022c9140ddd2d301c6..5e298acd572393ea8bc60b112e313b8dcb4c8c61 100644 (file)
@@ -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));
index b481dd2f82a1bb137dff2dd4898e49ab87983b1a..c4205a554b698fc90a1c6145d106ed600ad733c6 100644 (file)
--- 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)