Skip to contentSkip to conversation

Fix sporadic failures in pids shell tests

PATCH Superseded Andrea Cervesato 3 participants 6 messages Jun 15 – Jun 16 Library code

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Fix sporadic failures in pids shell tests

---
Andrea Cervesato (2):
pids: fix cleanup of orphaned pids_task1 children
tst_cgroup: tolerate ESRCH in cgroup_drain()

 lib/tst_cgroup.c                          | 2 +-
 testcases/kernel/controllers/pids/pids.sh | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

---
base-commit: b4d31ea5d5c16628b9c45932fc98b929ca2ceece
change-id: 20260615-fix_pids_errors-19399419c8ee

Best regards,

Signature · 5 lines
Andrea Cervesato <[email protected]>


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

PATCH 1/2 pids: fix cleanup of orphaned pids_task1 children

From: Andrea Cervesato <[email protected]>

pids_task1 forks a child that calls pause(), then the parent exits. The orphaned child remains in the cgroup but gets reparented to init, so it is not a child of the test shell.

stop_pids_tasks_path() reads cgroup.procs which includes this orphan. kill -9 succeeds but wait fails with 'not a child of this shell'. Using ROD for kill also unnecessarily aborts if the process is already dead.

Fix by suppressing errors from both kill and wait, and add killall for pids_task1 in cleanup() to catch any remaining orphans.

---
 testcases/kernel/controllers/pids/pids.sh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
testcases/kernel/controllers/pids/pids.sh +3 -2
index 26a0c6a221ea63e683016ebfea33f2744800aaea..dd27b5616f0c4b55c625ca57efa2507325949b07 100755
@@ -35,6 +35,7 @@ EOF
 cleanup()
 {
 	killall -9 pids_task2 >/dev/null 2>&1
+	killall -9 pids_task1 >/dev/null 2>&1
 
 	cgroup_cleanup
 }
@@ -79,8 +80,8 @@ stop_pids_tasks_path()
 	path=$1
 
 	for i in $(cat "$path/$task_list"); do
-		ROD kill -9 $i
-		wait $i
+		kill -9 $i 2>/dev/null
+		wait $i 2>/dev/null
 	done
 }
 
Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Re: [LTP] pids: fix cleanup of orphaned pids_task1 children

Hi Andrea,

Quoted 1 line · Andrea Cervesato

pids: fix cleanup of orphaned pids_task1 children

Verdict - Reviewed

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v1 1/2
#3 lore raw

Re: [LTP] [PATCH 1/2] pids: fix cleanup of orphaned pids_task1 children

In reply to Andrea Cervesato
Quoted 11 lines

From: Andrea Cervesato <[email protected]>

pids_task1 forks a child that calls pause(), then the parent exits. The orphaned child remains in the cgroup but gets reparented to init, so it is not a child of the test shell.

stop_pids_tasks_path() reads cgroup.procs which includes this orphan. kill -9 succeeds but wait fails with 'not a child of this shell'. Using ROD for kill also unnecessarily aborts if the process is already dead.

Quoted 4 lines

Fix by suppressing errors from both kill and wait, and add killall for pids_task1 in cleanup() to catch any remaining orphans.

Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

PATCH 2/2 tst_cgroup: tolerate ESRCH in cgroup_drain()

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

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.

---
 lib/tst_cgroup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/tst_cgroup.c +1 -1
index a37bf1516aabfbcb9a02fedd6fddb98e85ecc653..42d07912aebc0fae423b52f22c36c6beab0ee5c6 100644
@@ -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)
 			tst_brk(TBROK | TERRNO, "Failed to drain %s", tok);
 	}
 	SAFE_CLOSE(fd);
Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

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

Quoted 19 lines

From: Andrea Cervesato <[email protected]>

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.

---
 lib/tst_cgroup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/tst_cgroup.c +0 -0
index a37bf1516aabfbcb9a02fedd6fddb98e85ecc653..42d07912aebc0fae423b52f22c36c6beab0ee5c6 100644

lib/tst_cgroup.c static void cgroup_drain(const enum tst_cg_ver ver, · line 977

Quoted 5 lines
lib/tst_cgroup.c +1 -1
@@ -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);
    }
Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp