mirror of
https://github.com/apache/nuttx.git
synced 2026-09-21 21:47:28 +08:00
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(). Commitece224a7e3("handle waitpid waitting tcb->group is NULL") rewrote the comparisons this way when adding the ctcb->group NULL guard, regressing what90be95bb89had 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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user