From b50e205a613e812da5aa47ff0c6cddde49bcd9fb Mon Sep 17 00:00:00 2001 From: Masamichi Takagi Date: Mon, 8 Sep 2014 22:40:56 +0900 Subject: [PATCH] Support pid of zero when calling waitpid Make waitpid wait any process with the same pgid of the caller when setting zero to the pid argument. --- arch/x86/kernel/syscall.c | 5 +++++ kernel/include/process.h | 1 + kernel/syscall.c | 4 +++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/syscall.c b/arch/x86/kernel/syscall.c index 281620c6..b9b85d5e 100644 --- a/arch/x86/kernel/syscall.c +++ b/arch/x86/kernel/syscall.c @@ -183,6 +183,11 @@ do_setpgid(int pid, int pgid) continue; if(p->pid == pid){ p->pgid = pgid; + + /* Update pgid in fork_tree because it's used in wait4 */ + ihk_mc_spinlock_lock_noirq(&p->ftn->lock); + p->ftn->pgid = pgid; + ihk_mc_spinlock_unlock_noirq(&p->ftn->lock); } } ihk_mc_spinlock_unlock(&(v->runq_lock), irqstate); diff --git a/kernel/include/process.h b/kernel/include/process.h index da029f9b..04fbf8c8 100644 --- a/kernel/include/process.h +++ b/kernel/include/process.h @@ -144,6 +144,7 @@ struct fork_tree_node { struct process *owner; int pid; + int pgid; struct fork_tree_node *parent; struct list_head children; diff --git a/kernel/syscall.c b/kernel/syscall.c index 6b5db85b..fd5f66f1 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -305,6 +305,7 @@ SYSCALL_DECLARE(wait4) struct process *proc = cpu_local_var(current); struct fork_tree_node *child, *child_iter; int pid = (int)ihk_mc_syscall_arg0(ctx); + int pgid = proc->pgid; int *status = (int *)ihk_mc_syscall_arg1(ctx); int options = (int)ihk_mc_syscall_arg2(ctx); int ret; @@ -326,7 +327,7 @@ rescan: ihk_mc_spinlock_lock_noirq(&child_iter->lock); - if (pid == -1 || pid == child_iter->pid) { + if (pid == -1 || (pid == 0 && pgid == child_iter->pgid) || pid == child_iter->pid) { child = child_iter; break; } @@ -1395,6 +1396,7 @@ unsigned long do_fork(int clone_flags, unsigned long newsp, } new->ftn->pid = new->pid; + new->ftn->pgid = new->pgid; if (clone_flags & CLONE_PARENT_SETTID) { dkprintf("clone_flags & CLONE_PARENT_SETTID: 0x%lX\n",