[LTP] [PATCH v2 2/2] tst_cgroup: tolerate ESRCH in cgroup_drain()

Cyril Hrubis chrubis@suse.cz
Wed Jun 17 11:05:29 CEST 2026


Hi!
> A process can die between reading cgroup.procs and writing its PID
> to the destination cgroup. When this happens, the kernel returns
> ESRCH which is a normal race condition, not a test infrastructure
> failure.
> 
> Skip ESRCH errors instead of aborting with TBROK.
> 
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
>  lib/tst_cgroup.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
> index a37bf1516aabfbcb9a02fedd6fddb98e85ecc653..f548c0e01cf60803ad4c1e898e7ec2d39dc33c84 100644
> --- a/lib/tst_cgroup.c
> +++ b/lib/tst_cgroup.c
> @@ -974,8 +974,12 @@ static void cgroup_drain(const enum tst_cg_ver ver,
>  	for (tok = strtok(pid_list, "\n"); tok; tok = strtok(NULL, "\n")) {
>  		ret = dprintf(fd, "%s", tok);
>  
> -		if (ret < (ssize_t)strlen(tok))
> +		if (ret < (ssize_t)strlen(tok)) {
> +			if (ret < 0 && errno == ESRCH)
> +				continue;

Maybe we can print tst_res(TINFO, "Pid %s died during drain", tok);
here as well, so that when this happens we will have the information in
the test log.

Otherwise:

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

>  			tst_brk(TBROK | TERRNO, "Failed to drain %s", tok);
> +		}
>  	}
>  	SAFE_CLOSE(fd);
>  }
> 
> -- 
> 2.51.0
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list