On 24/02/2025 09:36, Lukáš Zaoral wrote:
* who.c (scan_entries): Account for guessed tty names (e.g.
'sshd pts/1') from the readutmp module when using the systemd backend.
* bootstrap.conf (gnulib_modules): Add str_endswith.
---
  bootstrap.conf | 1 +
  src/who.c      | 2 +-
  2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/bootstrap.conf b/bootstrap.conf
index 380fa1120..c99838e95 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -253,6 +253,7 @@ gnulib_modules="
    stdckdint-h
    stdlib-safer
    stpcpy
+  str_endswith
    strdup-posix
    strnlen
    strnumcmp
diff --git a/src/who.c b/src/who.c
index b56a1ace6..13e1b76d4 100644
--- a/src/who.c
+++ b/src/who.c
@@ -577,7 +577,7 @@ scan_entries (idx_t n, struct gl_utmp const *utmp_buf)
    while (n--)
      {
        if (!my_line_only
-          || STREQ (ttyname_b, utmp_buf->ut_line))
+          || str_endswith(utmp_buf->ut_line, ttyname_b))
          {
            if (need_users && IS_USER_PROCESS (utmp_buf))
              print_user (utmp_buf, boottime);


It's always good to provide as much context as possible.
I see this comes from https://bugzilla.redhat.com/2343998

The change looks good, as the tty names should
be distinct enough that this should be quite general.

I'm not sure how complete this is though, as on Fedora 41 I see
no output from `who am i`:

  $ src/who
  padraig  seat0        2025-02-18 18:01 (login screen)
  padraig  tty2         2025-02-18 18:01 (tty2)

  $ src/who -m | wc -c
  0

I've attached an updated patch adding the extra context which I'll apply later.

thanks,
Pádraig
From 0c78343fd51aaaf98954fa9170b08844e1483a1a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Zaoral?= <lzao...@redhat.com>
Date: Mon, 24 Feb 2025 10:36:35 +0100
Subject: [PATCH] who: fix -m with guessed tty names

* who.c (scan_entries): Account for guessed tty names (e.g.
'sshd pts/1') from the readutmp module when using the systemd backend.
* bootstrap.conf (gnulib_modules): Add str_endswith.
* News: Mention the bug fix.
Addresses https://bugzilla.redhat.com/2343998
---
 NEWS           | 4 ++++
 bootstrap.conf | 1 +
 src/who.c      | 2 +-
 3 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index 981ffa7b4..e7bc3884c 100644
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   'ls -Z dir' would crash.
   [bug introduced in coreutils-9.6]
 
+  'who -m' now outputs entries for remote logins.  Previously login
+  entries prefixed with the service (like "sshd") were not matched.
+  [bug introduced in coreutils-9.4]
+
 
 * Noteworthy changes in release 9.6 (2025-01-17) [stable]
 
diff --git a/bootstrap.conf b/bootstrap.conf
index 380fa1120..c99838e95 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -253,6 +253,7 @@ gnulib_modules="
   stdckdint-h
   stdlib-safer
   stpcpy
+  str_endswith
   strdup-posix
   strnlen
   strnumcmp
diff --git a/src/who.c b/src/who.c
index b56a1ace6..13e1b76d4 100644
--- a/src/who.c
+++ b/src/who.c
@@ -577,7 +577,7 @@ scan_entries (idx_t n, struct gl_utmp const *utmp_buf)
   while (n--)
     {
       if (!my_line_only
-          || STREQ (ttyname_b, utmp_buf->ut_line))
+          || str_endswith(utmp_buf->ut_line, ttyname_b))
         {
           if (need_users && IS_USER_PROCESS (utmp_buf))
             print_user (utmp_buf, boottime);
-- 
2.48.1

Reply via email to