linux: wait4: Fix incorrect return value comparison
Commit Message
Path 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.
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
sysdeps/unix/sysv/linux/wait4.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
Comments
On Apr 06 2020, Alistair Francis via Libc-alpha wrote:
> Path 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.
>
> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> ---
> sysdeps/unix/sysv/linux/wait4.c | 11 +++--------
> 1 file changed, 3 insertions(+), 8 deletions(-)
>
> diff --git a/sysdeps/unix/sysv/linux/wait4.c b/sysdeps/unix/sysv/linux/wait4.c
> index d14bd4da27..796691eb2b 100644
> --- a/sysdeps/unix/sysv/linux/wait4.c
> +++ b/sysdeps/unix/sysv/linux/wait4.c
> @@ -32,10 +32,7 @@ __wait4_time64 (pid_t pid, int *stat_loc, int options, struct __rusage64 *usage)
> struct __rusage32 usage32;
> pid_t ret = SYSCALL_CANCEL (wait4, pid, stat_loc, options, &usage32);
You should pass NULL if usage is NULL.
> @@ -119,10 +116,8 @@ __wait4 (pid_t pid, int *stat_loc, int options, struct rusage *usage)
>
> ret = __wait4_time64 (pid, stat_loc, options, &usage64);
Likewise.
Andreas.
* Alistair Francis via Libc-alpha:
> Path 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.
Would it make sense to add a test case?
@@ -32,10 +32,7 @@ __wait4_time64 (pid_t pid, int *stat_loc, int options, struct __rusage64 *usage)
struct __rusage32 usage32;
pid_t ret = SYSCALL_CANCEL (wait4, pid, stat_loc, options, &usage32);
- if (ret != 0)
- return ret;
-
- if (usage != NULL)
+ if (ret > 0 && usage != NULL)
rusage32_to_rusage64 (&usage32, usage);
return ret;
@@ -119,10 +116,8 @@ __wait4 (pid_t pid, int *stat_loc, int options, struct rusage *usage)
ret = __wait4_time64 (pid, stat_loc, options, &usage64);
- if (ret != 0)
- return ret;
-
- rusage64_to_rusage (&usage64, usage);
+ if (ret > 0 && usage != NULL)
+ rusage64_to_rusage (&usage64, usage);
return ret;
}