svn commit: r194256 - head/sys/kern

Ed Schouten ed at FreeBSD.org
Mon Jun 15 19:17:54 UTC 2009


Author: ed
Date: Mon Jun 15 19:17:52 2009
New Revision: 194256
URL: http://svn.freebsd.org/changeset/base/194256

Log:
  Make tcsetsid(3) work on revoked TTYs.
  
  Right now the only way to make tcsetsid(3)/TIOCSCTTY work, is by
  ensuring the session leader is dead. This means that an application that
  catches SIGHUPs and performs a sleep prevents us from assigning a new
  session leader.
  
  Change the code to make it work on revoked TTYs as well. This allows us
  to change init(8) to make the shutdown script run in a more clean
  environment.

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 19:16:43 2009	(r194255)
+++ head/sys/kern/kern_exit.c	Mon Jun 15 19:17:52 2009	(r194256)
@@ -309,7 +309,7 @@ exit1(struct thread *td, int rv)
 		sp->s_ttyvp = NULL;
 		SESS_UNLOCK(sp);
 
-		if (ttyvp != NULL) {
+		if (ttyvp != NULL && ttyvp->v_type != VBAD) {
 			/*
 			 * Controlling process.
 			 * Signal foreground pgrp and revoke access to

Modified: head/sys/kern/tty.c
==============================================================================
--- head/sys/kern/tty.c	Mon Jun 15 19:16:43 2009	(r194255)
+++ head/sys/kern/tty.c	Mon Jun 15 19:17:52 2009	(r194256)
@@ -1487,15 +1487,18 @@ tty_generic_ioctl(struct tty *tp, u_long
 		}
 
 		if (p->p_session->s_ttyvp != NULL ||
-		    (tp->t_session != NULL && tp->t_session->s_ttyvp != NULL)) {
+		    (tp->t_session != NULL && tp->t_session->s_ttyvp != NULL &&
+		    tp->t_session->s_ttyvp->v_type != VBAD)) {
 			/*
 			 * There is already a relation between a TTY and
 			 * a session, or the caller is not the session
 			 * leader.
 			 *
 			 * Allow the TTY to be stolen when the vnode is
-			 * NULL, but the reference to the TTY is still
-			 * active.
+			 * invalid, but the reference to the TTY is
+			 * still active.  This allows immediate reuse of
+			 * TTYs of which the session leader has been
+			 * killed or the TTY revoked.
 			 */
 			sx_xunlock(&proctree_lock);
 			return (EPERM);


More information about the svn-src-all mailing list