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

Li Wang li.wang@linux.dev
Tue Jun 16 10:03:14 CEST 2026


> From: Andrea Cervesato <andrea.cervesato@suse.com>
> 
> 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 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
> index a37bf1516aabfbcb9a02fedd6fddb98e85ecc653..42d07912aebc0fae423b52f22c36c6beab0ee5c6 100644
> --- a/lib/tst_cgroup.c
> +++ b/lib/tst_cgroup.c
> @@ -974,7 +974,7 @@ 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) && errno != ESRCH)

errno is only meaningful after a call that actually failed (ret < 0).
With a short but non-negative return, errno holds whatever value some
earlier libc/syscall left there.

So maybe better like this:

    if (ret < (ssize_t)strlen(tok)) {
        if (ret < 0 && errno == ESRCH)
            continue;

        tst_brk(TBROK | TERRNO, "Failed to drain %s", tok);
    }

-- 
Regards,
Li Wang


More information about the ltp mailing list