summaryrefslogtreecommitdiff
path: root/proc
diff options
context:
space:
mode:
Diffstat (limited to 'proc')
-rw-r--r--proc/pgrp.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/proc/pgrp.c b/proc/pgrp.c
index d4ea9ee4a..a828e1799 100644
--- a/proc/pgrp.c
+++ b/proc/pgrp.c
@@ -341,8 +341,14 @@ S_proc_setpgrp (struct proc *callerp,
if (p->p_pgrp != pg)
{
+ /* If we have to create a new pgrp, we have to do this before
+ leaving the current one. p->p_pgrp is deallocated if p is
+ the last process in that group. Likewise, if p->p_pgrp was
+ the last group in p->p_pgrp->pg_session, the session is
+ deallocated. */
+ struct pgrp *new = pg ? pg : new_pgrp (pgid, p->p_pgrp->pg_session);
leave_pgrp (p);
- p->p_pgrp = pg ? pg : new_pgrp (pgid, p->p_pgrp->pg_session);
+ p->p_pgrp = new;
join_pgrp (p);
}
else