sched: fix parent process check using wrong pid field

Compare ctcb->group->tg_ppid against rtcb->group->tg_pid (the group
leader PID) instead of rtcb->pid in waitid() and in the
!CONFIG_SCHED_CHILD_STATUS path of waitpid(). Commit ece224a7e3
("handle waitpid waitting tcb->group is NULL") rewrote the
comparisons this way when adding the ctcb->group NULL guard,
regressing what 90be95bb89 had correct: a non-group-leader thread
calling waitid(P_PID) or waitpid() on a child always gets ECHILD.

Assisted-by: OpenAI Codex
Signed-off-by: yushuailong <yyyusl@qq.com>
This commit is contained in:
yushuailong
2026-09-11 03:00:15 +08:00
committed by Xiang Xiao
parent d645609254
commit 91b4b0a91e
2 changed files with 5 additions and 3 deletions
+3 -2
View File
@@ -400,7 +400,7 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options)
{
/* Make sure that the thread it is our child. */
if (ctcb->group->tg_ppid != rtcb->pid)
if (ctcb->group->tg_ppid != rtcb->group->tg_pid)
{
errcode = ECHILD;
}
@@ -437,7 +437,8 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options)
ctcb = nxsched_get_tcb((pid_t)id);
if (!ctcb || !ctcb->group || ctcb->group->tg_ppid != rtcb->pid)
if (!ctcb || !ctcb->group ||
ctcb->group->tg_ppid != rtcb->group->tg_pid)
{
errcode = ECHILD;
}
+2 -1
View File
@@ -373,7 +373,8 @@ pid_t nxsched_waitpid(pid_t pid, FAR int *stat_loc, int options)
*/
ctcb = nxsched_get_tcb(pid);
if (!ctcb || !ctcb->group || ctcb->group->tg_ppid != rtcb->pid ||
if (!ctcb || !ctcb->group ||
ctcb->group->tg_ppid != rtcb->group->tg_pid ||
(ctcb->flags & TCB_FLAG_EXIT_PROCESSING) != 0)
{
ret = -ECHILD;