Move cleanup job control bits to their own function.
authormpi <mpi@openbsd.org>
Sat, 10 Feb 2018 10:32:51 +0000 (10:32 +0000)
committermpi <mpi@openbsd.org>
Sat, 10 Feb 2018 10:32:51 +0000 (10:32 +0000)
Part of the larger 'proctreelk' diff from guenther@

No functional change, ok benno@, tedu@

sys/kern/kern_exit.c
sys/kern/kern_proc.c
sys/sys/proc.h

index a104c29..dfd4e38 100644 (file)
@@ -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
index e156fa6..7ca1432 100644 (file)
@@ -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 <sys/tty.h>
 #include <sys/signalvar.h>
 #include <sys/pool.h>
+#include <sys/vnode.h>
 
 #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,
index d73e6aa..e79adb5 100644 (file)
@@ -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);