qemu-trivial
[Top][All Lists]
Advanced

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

Re: [PATCH] linux-user/syscall: Do not ignore info.si_pid == 0 in waitid


From: Serge Belyshev
Subject: Re: [PATCH] linux-user/syscall: Do not ignore info.si_pid == 0 in waitid()
Date: Sat, 29 Jan 2022 22:13:13 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Laurent Vivier <laurent@vivier.eu> writes:

> ...
>
> According to wait(2), it sounds a little bit more complicated than that.
>
>        If WNOHANG was specified in options and there were no children in a 
> waitable state, then
>        waitid() returns 0 immediately and the state of the siginfo_t  
> structure  pointed  to  by
>        infop  depends  on  the  implementation.   To (portably) distinguish 
> this case from that
>        where a child was in a waitable state, zero out the si_pid field 
> before the call and check
>        for a nonzero value in this field after the call returns.
>
>        POSIX.1-2008  Technical  Corrigendum  1 (2013) adds the requirement 
> that when WNOHANG is
>        specified in options and there were no children in a waitable state, 
> then waitid() should
>        zero out the si_pid and si_signo fields of the structure.  On Linux 
> and other implementations
>        that adhere to this requirement, it is not necessary to zero out the 
> si_pid field before
>        calling waitid().  However, not all implementations follow the POSIX.1 
>  specification  on
>        this point.
>

In glibc waitpid is implemented using wait4, and on systems where wait4
is not available (e.g. riscv32), wait4 is implemented via waitid and the
implementation expects that info.si_pid is cleared when appropriate:

(from 
https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/wait4.c#l58
 )

  siginfo_t infop;
  ...
  SYSCALL_CANCEL (waitid, idtype, pid, &infop, options, usage)
  ...
  return infop.si_pid;

so I think it is safe to follow glibc here and rely on the kernel to clear
pid/signo and other fields and just to remove the "info.si_pid != 0" check.


> Perhaps the best approach would be to copy the caller target siginfo
> to the host one, call host waitpid(), remove the "info.si_pid != 0"
> and copy back the host siginfo to target one?

Not sure what would be the gain in this case, as linux clears siginfo fiels
since the very first implementation of waitid in 2.6.9:

https://git.kernel.org/pub/scm/linux/kernel/git/history/history.git/tree/kernel/exit.c?h=v2.6.9#n1354

        /*
         * For a WNOHANG return, clear out all the fields
         * we would set so the user can easily tell the
         * difference.
         */



reply via email to

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