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.
This commit is contained in:
ed 2009-06-15 20:45:51 +00:00
parent 28b41377e3
commit fa3d9801cc
2 changed files with 33 additions and 38 deletions

View File

@ -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);
/*
* 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)
*/
tty_unlock(tp);
}
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);

View File

@ -1486,7 +1486,7 @@ tty_generic_ioctl(struct tty *tp, u_long cmd, void *data, struct thread *td)
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)) {
/*