[Toybox] [PATCH] Fix pgrep -s 0 when running in session ID 0

Rob Landley rob at landley.net
Fri Oct 6 21:33:30 PDT 2023


On 10/6/23 17:10, Colin Cross via Toybox wrote:
> I came across an issue when running the pgrep -s 0 test in Android's
> CI infrastructure that uses a PID namespace, causing the test to run
> session ID 0:
> 
> $ sudo unshare -fp ./toybox pgrep -s 0
> pgrep: bad -s '0'
> 
> The attached patch fixes the argument parsing to support getsid returning 0.

Ah, I read "man 2 getsid" to indicate that sid 0 was special, but it's passing
in _pid_ 0 that's special. Which is why, right before your patch, this part
renders what you did moot:

    // For pkill, -s 0 represents pkill's session id.
    if (pl==&TT.ss && ll[pl->len]==0) ll[pl->len] = getsid(0);

Ah, no wait, that _is_ in the pkill man page:

       -s, --session sid,...
              Only match processes whose process session ID is  listed.   Ses‐
              sion ID 0 is translated into pgrep's or pkill's own session ID.

...so you want pgrep to accept -s 0, and it'll it will coincidentally work for
pkill if your session ID _is_ 0 then getsid() will return 0 anyway? And pkill
should work differently from pgrep?

Rob


More information about the Toybox mailing list