Package: procps
Version: 2:4.0.4-9
Severity: important
Tags: patch upstream
In trixie, we switched from the traditional utmp to systemd sessions mechanism
to display user sessions. However, mere presence of systemd does not mean the
logind sessions are accounted for: for this, one needs pam_systemd. So without
pam_systemd, `w' utility displays nothing useful, even if utmp database is
present:
$ w
08:37:00 up 6 days, 2:17, 1 user, load average: 0.32, 0.44, 0.45
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
$ _
As you can see, there's 1 user listed (counted in utmp), but it is not
shown.
This is because in src/w.c, we have (simplified):
if (term_mode) {
print_user_terminals(...);
#if (defined(WITH_SYSTEMD)
} else if ((sessions = sd_get_sessions (&sessions_list))
< 0 && sessions != -ENOENT) {
error(EXIT_FAILURE, -sessions, _("error getting sessions"));
} else if (sessions > 0) {
/* print systemd sessions */
} else if (!sd_booted()) {
#else
} else {
#endif
/* process utmp */
}
So, utmp is processed only if there are no systemd sessions present,
*and* if !sd_booted(). However, on a fully-booted system without
pam_systemd, sd_booted() will return true, and sd_get_sessions()
will return zero, -- and the result will be like above.
When removing this "} else if (!sd_booted()) {" condition, things
works again:
$ ./w
08:46:04 up 6 days, 2:26, 1 user, load average: 0.37, 0.44, 0.45
USER TTY LOGIN@ IDLE JCPU PCPU WHAT
mjt pts/1 08:26 1.00s 0.00s ? ./w
$ _
The following trivial patch fixes this issue. The idea is to always
process utmp if no sessions are returned from systemd, no matter if
the system finished booting or not.
--- a/src/w.c
+++ b/src/w.c
@@ -1144,8 +1144,6 @@
}
free(sessions_list);
- } else if (!sd_booted()) {
-#else
- } else {
#endif
+ } else {
#ifdef HAVE_UTMPX_H
setutxent();
The same approach has taken by the upstream in 4.0.6 version. There,
the code is slightly different in other ways, but the idea is the same.
https://gitlab.com/procps-ng/procps/-/commit/678b099c9fd12109469be234281c8b4e2a382757
It'd be very helpful if either the above simple patch, or more complete
fix, lands in trixie too. For now, we're rebuilding procps package to
include the fix from upstream.
Thanks,
/mjt