[LTP] [PATCH v2] setpgid02: use 1 instead of getpgid(1)
Teo Couprie Diaz
teo.coupriediaz@arm.com
Fri Apr 7 12:18:38 CEST 2023
Hi Edward, LTP folks,
On 31/03/2023 01:07, Edward Liaw via ltp wrote:
> On Android, init does not setpgid, so getpgid(1) returns 0 and the third
> case of setting pgid to a different session's process group does not
> behave as expected: setpgid treats 0 as setting the pgid to the pid.
>
> Instead, replace SAFE_GETPGID(1) with the expected value of 1.
>
> Signed-off-by: Edward Liaw <edliaw@google.com>
> ---
> testcases/kernel/syscalls/setpgid/setpgid02.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/testcases/kernel/syscalls/setpgid/setpgid02.c b/testcases/kernel/syscalls/setpgid/setpgid02.c
> index 4b63afee8..bf7b3176b 100644
> --- a/testcases/kernel/syscalls/setpgid/setpgid02.c
> +++ b/testcases/kernel/syscalls/setpgid/setpgid02.c
> @@ -44,7 +44,7 @@ static void setup(void)
> * Getting pgid of init/systemd process to use it as a
> * process group from a different session for EPERM test
> */
> - init_pgid = SAFE_GETPGID(1);
> + init_pgid = 1;
> }
>
> static void run(unsigned int n)
The change looks good and makes sense:
Reviewed-by: Teo Couprie Diaz <teo.coupriediaz@arm.com>
However, I have encountered an issue on the same check of this test,
unrelated to Edward's issue.
Indeed, on systems that run the shell as PID 1 (for example a basic
busybox rootfs) the EPERM check wouldn't work.
This is because LTP would run within the same session ID as init, which
would allow the test to change the PGID and not trigger the EPERM.
I am working on a patch and wanted to get some input. My current idea
would be to fork a child that would create a new session and try to
setpgid() the child.
This would also allow to use the main process' PGID, as it would be in
another session from the child anyway. This would remove the need to
getpgid() init, which hopefully should fix your issue on Android as well.
However, this adds a lot more complexity in the test: needing to fork
and synchronize with the child as the main process needs to wait for the
child to change its session ID, otherwise the test would fail.
Do you think this idea makes sense ? I would send it for review once I
ironed out the patch.
Another solution would be for LTP to change its session ID by default,
which would prevent the need for a change to setpgid02 on top of Edward's.
However, I don't fully understand the possible consequences of having
LTP change its SID for all tests.
Happy to discuss or send an RFC patch.
Thanks very much in advance,
Téo-CD
More information about the ltp
mailing list