From owner-svn-src-all@FreeBSD.ORG Mon Jun 15 20:45:52 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5366E106566C; Mon, 15 Jun 2009 20:45:52 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 419B88FC15; Mon, 15 Jun 2009 20:45:52 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n5FKjq6F001261; Mon, 15 Jun 2009 20:45:52 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n5FKjqRa001259; Mon, 15 Jun 2009 20:45:52 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <200906152045.n5FKjqRa001259@svn.freebsd.org> From: Ed Schouten Date: Mon, 15 Jun 2009 20:45:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r194264 - head/sys/kern X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Jun 2009 20:45:52 -0000 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)) { /*