From c33efb0726281535972115f69ef65cd8bc3854d2 Mon Sep 17 00:00:00 2001 From: mpi Date: Sat, 10 Feb 2018 10:32:51 +0000 Subject: [PATCH] Move cleanup job control bits to their own function. Part of the larger 'proctreelk' diff from guenther@ No functional change, ok benno@, tedu@ --- sys/kern/kern_exit.c | 44 +++---------------------------------------- sys/kern/kern_proc.c | 45 +++++++++++++++++++++++++++++++++++++++++++- sys/sys/proc.h | 3 ++- 3 files changed, 49 insertions(+), 43 deletions(-) diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index a104c292386..dfd4e38078f 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_exit.c,v 1.163 2017/12/30 20:47:00 guenther Exp $ */ +/* $OpenBSD: kern_exit.c,v 1.164 2018/02/10 10:32:51 mpi Exp $ */ /* $NetBSD: kern_exit.c,v 1.39 1996/04/22 01:38:25 christos Exp $ */ /* @@ -117,8 +117,7 @@ exit1(struct proc *p, int rv, int flags) { struct process *pr, *qr, *nqr; struct rusage *rup; - struct vnode *ovp; - + atomic_setbits_int(&p->p_flag, P_WEXIT); pr = p->p_p; @@ -184,44 +183,7 @@ exit1(struct proc *p, int rv, int flags) #ifdef SYSVSEM semexit(pr); #endif - if (SESS_LEADER(pr)) { - struct session *sp = pr->ps_session; - - if (sp->s_ttyvp) { - /* - * Controlling process. - * Signal foreground pgrp, - * drain controlling terminal - * and revoke access to controlling terminal. - */ - if (sp->s_ttyp->t_session == sp) { - if (sp->s_ttyp->t_pgrp) - pgsignal(sp->s_ttyp->t_pgrp, - SIGHUP, 1); - ttywait(sp->s_ttyp); - /* - * The tty could have been revoked - * if we blocked. - */ - if (sp->s_ttyvp) - VOP_REVOKE(sp->s_ttyvp, - REVOKEALL); - } - ovp = sp->s_ttyvp; - sp->s_ttyvp = NULL; - if (ovp) - vrele(ovp); - /* - * s_ttyp is not zero'd; we use this to - * indicate that the session once had a - * controlling terminal. (for logging and - * informational purposes) - */ - } - sp->s_leader = NULL; - } - fixjobc(pr, pr->ps_pgrp, 0); - + killjobc(pr); #ifdef ACCOUNTING acct_process(p); #endif diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index e156fa6629a..7ca14325220 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_proc.c,v 1.79 2017/12/30 20:47:00 guenther Exp $ */ +/* $OpenBSD: kern_proc.c,v 1.80 2018/02/10 10:32:51 mpi Exp $ */ /* $NetBSD: kern_proc.c,v 1.14 1996/02/09 18:59:41 christos Exp $ */ /* @@ -47,6 +47,7 @@ #include #include #include +#include #define UIHASH(uid) (&uihashtbl[(uid) & uihash]) LIST_HEAD(uihashhead, uidinfo) *uihashtbl; @@ -382,6 +383,48 @@ fixjobc(struct process *pr, struct pgrp *pgrp, int entering) } } +void +killjobc(struct process *pr) +{ + if (SESS_LEADER(pr)) { + struct session *sp = pr->ps_session; + + if (sp->s_ttyvp) { + struct vnode *ovp; + + /* + * Controlling process. + * Signal foreground pgrp, + * drain controlling terminal + * and revoke access to controlling terminal. + */ + if (sp->s_ttyp->t_session == sp) { + if (sp->s_ttyp->t_pgrp) + pgsignal(sp->s_ttyp->t_pgrp, SIGHUP, 1); + ttywait(sp->s_ttyp); + /* + * The tty could have been revoked + * if we blocked. + */ + if (sp->s_ttyvp) + VOP_REVOKE(sp->s_ttyvp, REVOKEALL); + } + ovp = sp->s_ttyvp; + sp->s_ttyvp = NULL; + if (ovp) + vrele(ovp); + /* + * s_ttyp is not zero'd; we use this to + * indicate that the session once had a + * controlling terminal. (for logging and + * informational purposes) + */ + } + sp->s_leader = NULL; + } + fixjobc(pr, pr->ps_pgrp, 0); +} + /* * A process group has become orphaned; * if there are any stopped processes in the group, diff --git a/sys/sys/proc.h b/sys/sys/proc.h index d73e6aaa60a..e79adb5972e 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.h,v 1.244 2017/12/19 10:04:59 stefan Exp $ */ +/* $OpenBSD: proc.h,v 1.245 2018/02/10 10:32:51 mpi Exp $ */ /* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */ /*- @@ -500,6 +500,7 @@ int enterpgrp(struct process *, pid_t, struct pgrp *, struct session *); void fixjobc(struct process *, struct pgrp *, int); int inferior(struct process *, struct process *); void leavepgrp(struct process *); +void killjobc(struct process *); void preempt(void); void pgdelete(struct pgrp *); void procinit(void); -- 2.20.1