bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: readutmp: Non-portable UT_PID use.


From: Eric Blake
Subject: Re: readutmp: Non-portable UT_PID use.
Date: Wed, 05 Sep 2012 14:43:41 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120828 Thunderbird/15.0

On 09/05/2012 02:08 PM, Mats Erik Andersson wrote:
> 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.

Thanks for the report.

> 
>>From 60fcbc2763d6b657c62b921ed263fbd5a0794df6 Mon Sep 17 00:00:00 2001
> From: Mats Erik Andersson <address@hidden>
> 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.

I like this version better, as we like avoiding in-function #ifdef when
possible.  I'll push it shortly, with one tweak...

> ---
>  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

Jim likes favoring < over >, so I'm swapping this to '0 < UT_PID (u)'.

-- 
Eric Blake   address@hidden    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]