Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 15 Jun 2009 20:45:52 +0000 (UTC)
From:      Ed Schouten <ed@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r194264 - head/sys/kern
Message-ID:  <200906152045.n5FKjqRa001259@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ed
Date: Mon Jun 15 20:45:51 2009
New Revision: 194264
URL: http://svn.freebsd.org/changeset/base/194264

Log:
  Perform some more cleanups to in-kernel session handling.
  
  The code that was in place in exit1() was mainly based on code from the
  old TTY layer. The main reason behind this, was because at one moment I
  ran a system that had two TTY layers in place at the same time. It is
  now sufficient to do the following:
  
  - Remove references from the session structure to the TTY vnode and the
    session leader.
  
  - If we have a controlling TTY and the session used by the TTY is equal
    to our session, send the SIGHUP.
  
  - If we have a vnode to the controlling TTY which has not been revoked,
    revoke it.
  
  While there, change sys/kern/tty.c to use s_ttyp in the comparison
  instead of s_ttyvp. It should not make any difference, because s_ttyvp
  can only become null when the session leader already left, but it's
  nicer to compare against the proper value.

Modified:
  head/sys/kern/kern_exit.c
  head/sys/kern/tty.c

Modified: head/sys/kern/kern_exit.c
==============================================================================
--- head/sys/kern/kern_exit.c	Mon Jun 15 20:40:23 2009	(r194263)
+++ head/sys/kern/kern_exit.c	Mon Jun 15 20:45:51 2009	(r194264)
@@ -300,52 +300,47 @@ exit1(struct thread *td, int rv)
 
 	sx_xlock(&proctree_lock);
 	if (SESS_LEADER(p)) {
-		struct session *sp;
-
-		sp = p->p_session;
+		struct session *sp = p->p_session;
+		struct tty *tp;
 
+		/*
+		 * s_ttyp is not zero'd; we use this to indicate that
+		 * the session once had a controlling terminal. (for
+		 * logging and informational purposes)
+		 */
 		SESS_LOCK(sp);
 		ttyvp = sp->s_ttyvp;
+		tp = sp->s_ttyp;
 		sp->s_ttyvp = NULL;
+		sp->s_leader = NULL;
 		SESS_UNLOCK(sp);
 
-		if (ttyvp != NULL && ttyvp->v_type != VBAD) {
-			/*
-			 * Controlling process.
-			 * Signal foreground pgrp and revoke access to
-			 * controlling terminal.
-			 *
-			 * There is no need to drain the terminal here,
-			 * because this will be done on revocation.
-			 */
-			if (sp->s_ttyp != NULL) {
-				struct tty *tp = sp->s_ttyp;
+		/*
+		 * Signal foreground pgrp and revoke access to
+		 * controlling terminal if it has not been revoked
+		 * already.
+		 *
+		 * Because the TTY may have been revoked in the mean
+		 * time and could already have a new session associated
+		 * with it, make sure we don't send a SIGHUP to a
+		 * foreground process group that does not belong to this
+		 * session.
+		 */
 
-				tty_lock(tp);
+		if (tp != NULL) {
+			tty_lock(tp);
+			if (tp->t_session == sp)
 				tty_signal_pgrp(tp, SIGHUP);
-				tty_unlock(tp);
+			tty_unlock(tp);
+		}
 
-				/*
-				 * The tty could have been revoked
-				 * if we blocked.
-				 */
-				if (ttyvp->v_type != VBAD) {
-					sx_xunlock(&proctree_lock);
-					VOP_LOCK(ttyvp, LK_EXCLUSIVE);
-					VOP_REVOKE(ttyvp, REVOKEALL);
-					VOP_UNLOCK(ttyvp, 0);
-					sx_xlock(&proctree_lock);
-				}
-			}
-			/*
-			 * s_ttyp is not zero'd; we use this to indicate that
-			 * the session once had a controlling terminal.
-			 * (for logging and informational purposes)
-			 */
+		if (ttyvp != NULL && ttyvp->v_type != VBAD) {
+			sx_xunlock(&proctree_lock);
+			VOP_LOCK(ttyvp, LK_EXCLUSIVE);
+			VOP_REVOKE(ttyvp, REVOKEALL);
+			VOP_UNLOCK(ttyvp, 0);
+			sx_xlock(&proctree_lock);
 		}
-		SESS_LOCK(p->p_session);
-		sp->s_leader = NULL;
-		SESS_UNLOCK(p->p_session);
 	}
 	fixjobc(p, p->p_pgrp, 0);
 	sx_xunlock(&proctree_lock);

Modified: head/sys/kern/tty.c
==============================================================================
--- head/sys/kern/tty.c	Mon Jun 15 20:40:23 2009	(r194263)
+++ head/sys/kern/tty.c	Mon Jun 15 20:45:51 2009	(r194264)
@@ -1486,7 +1486,7 @@ tty_generic_ioctl(struct tty *tp, u_long
 			return (0);
 		}
 
-		if (p->p_session->s_ttyvp != NULL ||
+		if (p->p_session->s_ttyp != NULL ||
 		    (tp->t_session != NULL && tp->t_session->s_ttyvp != NULL &&
 		    tp->t_session->s_ttyvp->v_type != VBAD)) {
 			/*



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200906152045.n5FKjqRa001259>