Dear all, the module readutmp is broken for the standard use
read_utmp(..., READ_UTMP_USER_PROCESS | READ_UTMP_CHECK_PIDS) for all releases of FreeBSD until 8.3, and all OpenBSD ever released. The reason is that those systems do not provide `utmp.ut_pid', thus making the macro UT_PID(u) identical to naught, and then turning the predicate UT_PID (u) <= 0 found in desirable_utmp_entry(), into a permanent true clause. This makes desirable_utmp_entry() discard every legitimate user's UTMP entry for said BSD releases. NetBSD and DragonflyBSD are not touched by this malfunction. Below are two suggestions that work equally well on Debian Squeeze and on OpenBSD 4.6. Best regards, Mats Erik Andersson >From 36e7aa46f858fb7ae96fa7047ff161da8a57607a Mon Sep 17 00:00:00 2001 From: Mats Erik Andersson <g...@gisladisker.se> Date: Wed, 5 Sep 2012 00:03:32 +0200 Subject: [PATCH] readutmp.c: Non-portable use of UT_PID. * lib/readutmp.c [HAVE_STRUCT_XTMP_UT_PID]: Check OPTIONS with READ_UTMP_CHECK_PIDS only if `utmp.ut_pid' exists. --- lib/readutmp.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/lib/readutmp.c b/lib/readutmp.c index f89dd68..8266e40 100644 --- a/lib/readutmp.c +++ b/lib/readutmp.c @@ -67,11 +67,13 @@ desirable_utmp_entry (STRUCT_UTMP const *u, int options) bool user_proc = IS_USER_PROCESS (u); if ((options & READ_UTMP_USER_PROCESS) && !user_proc) return false; +#if HAVE_STRUCT_XTMP_UT_PID if ((options & READ_UTMP_CHECK_PIDS) && user_proc && (UT_PID (u) <= 0 || (kill (UT_PID (u), 0) < 0 && errno == ESRCH))) return false; +#endif return true; } -- 1.7.2.5 >From 60fcbc2763d6b657c62b921ed263fbd5a0794df6 Mon Sep 17 00:00:00 2001 From: Mats Erik Andersson <g...@gisladisker.se> Date: Wed, 5 Sep 2012 21:51:39 +0200 Subject: [PATCH] readutmp.c: Portability improved UT_PID use. * lib/readutmp.c (desirable_utmp_entry) <READ_UTMP_CHECK_PIDS>: Use `UT_PID (u) > 0' as absolute condition. --- lib/readutmp.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/readutmp.c b/lib/readutmp.c index f89dd68..2ac803b 100644 --- a/lib/readutmp.c +++ b/lib/readutmp.c @@ -69,8 +69,8 @@ desirable_utmp_entry (STRUCT_UTMP const *u, int options) return false; if ((options & READ_UTMP_CHECK_PIDS) && user_proc - && (UT_PID (u) <= 0 - || (kill (UT_PID (u), 0) < 0 && errno == ESRCH))) + && UT_PID (u) > 0 + && (kill (UT_PID (u), 0) < 0 && errno == ESRCH)) return false; return true; } -- 1.7.2.5