public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-alpha@sourceware.org
Subject: Re: [PATCH v3 1/2] linux: wait4: Fix incorrect return value comparison
Date: Thu, 9 Apr 2020 17:52:27 -0300	[thread overview]
Message-ID: <2eb84732-c474-0613-887f-cbcd1c595e04@linaro.org> (raw)
In-Reply-To: <20200409201154.3365671-1-alistair.francis@wdc.com>



On 09/04/2020 17:11, Alistair Francis via Libc-alpha wrote:
> Patch 600f00b "linux: Use long time_t for wait4/getrusage" introduced
> two bugs:
>  - The usage32 struct was set if the wait4 syscall had an error.
>  - For 32-bit systems the usage struct was set even if it was specified
>    as NULL.
> 
> This patch fixes the two issues.

Ok with the changes below.

> ---
>  sysdeps/unix/sysv/linux/wait4.c | 32 ++++++++++++++++++++------------
>  1 file changed, 20 insertions(+), 12 deletions(-)
> 
> diff --git a/sysdeps/unix/sysv/linux/wait4.c b/sysdeps/unix/sysv/linux/wait4.c
> index d14bd4da27..21eb154b72 100644
> --- a/sysdeps/unix/sysv/linux/wait4.c
> +++ b/sysdeps/unix/sysv/linux/wait4.c
> @@ -29,14 +29,18 @@ __wait4_time64 (pid_t pid, int *stat_loc, int options, struct __rusage64 *usage)
>  # if __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64
>    return SYSCALL_CANCEL (wait4, pid, stat_loc, options, usage);
>  # else
> -  struct __rusage32 usage32;
> -  pid_t ret = SYSCALL_CANCEL (wait4, pid, stat_loc, options, &usage32);
> -
> -  if (ret != 0)
> -    return ret;
> +  pid_t ret;
>  
>    if (usage != NULL)
> -    rusage32_to_rusage64 (&usage32, usage);
> +    {
> +      struct __rusage32 usage32;
> +        ret = SYSCALL_CANCEL (wait4, pid, stat_loc, options, &usage32);

Indentation seems off.

> +
> +      if (ret > 0)
> +        rusage32_to_rusage64 (&usage32, usage);> +    }
> +  else
> +    ret = SYSCALL_CANCEL (wait4, pid, stat_loc, options, NULL);

I think there is no much gain in optimizing stack usage here,
I would prefer to simplify to just:

  struct __rusage32 usage32;
  ret = SYSCALL_CANCEL (wait4, pid, stat_loc, options,
                        usage != NULL ? &usage32 : NULL);
  if (ret > 0 && usage != NULL)
    rusage32_to_rusage64 (&usage32, usage);


>  
>    return ret;
>  # endif
> @@ -114,15 +118,19 @@ libc_hidden_def (__wait4_time64)
>  pid_t
>  __wait4 (pid_t pid, int *stat_loc, int options, struct rusage *usage)
>  {
> -  pid_t ret ;
> -  struct __rusage64 usage64;
> +  pid_t ret;
>  
> -  ret = __wait4_time64 (pid, stat_loc, options, &usage64);
> +  if (usage != NULL)
> +    {
> +      struct __rusage64 usage64;
>  
> -  if (ret != 0)
> -    return ret;
> +      ret = __wait4_time64 (pid, stat_loc, options, &usage64);
>  
> -  rusage64_to_rusage (&usage64, usage);
> +      if (ret > 0)
> +        rusage64_to_rusage (&usage64, usage);
> +    }
> +  else
> +    ret = __wait4_time64 (pid, stat_loc, options, NULL);
>  
>    return ret;
>  }
> 

Same as before:

  struct __rusage64 usage64;
  ret = __wait4_time64 (pid, stat_loc, options,
                        usage != NULL ? &usage64 : NULL);
  if (ret > 0 && usage != 0)
    rusage64_to_rusage (&usage64, usage);

      parent reply	other threads:[~2020-04-09 20:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-09 20:11 Alistair Francis
2020-04-09 20:11 ` [PATCH v3 2/2] linux: Add wait4 test case Alistair Francis
2020-04-09 21:46   ` Adhemerval Zanella
2020-04-09 20:52 ` Adhemerval Zanella [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2eb84732-c474-0613-887f-cbcd1c595e04@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).