/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/sysmacros.h>
&pid0, /* s_sidp */
{0}, /* s_lock */
1, /* s_ref */
B_FALSE, /* s_sighuped */
B_FALSE, /* s_exit */
0, /* s_exit_cv */
0, /* s_cnt */
0, /* s_cnt_cv */
NODEV, /* s_dev */
NULL, /* s_vp */
NULL /* s_cred */
};
void
{
}
void
{
return;
}
/*
* It's ok to free this session structure now because we know
* that no one else can have a pointer to it. We know this
* to be true because the only time that s_ref can possibly
* be incremented is when pidlock or p_splock is held AND there
* is a proc_t that points to that session structure. In that
* case we are guaranteed that the s_ref is at least 1 since there
* is a proc_t that points to it. So when s_ref finally drops to
* zero then no one else has a reference (and hence pointer) to
* this session structure and there is no valid proc_t pointing
* to this session structure anymore so, no one can acquire a
* reference (and pointer) to this session structure so it's
* ok to free it here.
*/
panic("sp == &session0");
/* make sure there are no outstanding holds */
/* make sure there is no exit in progress */
/* make sure someone already freed any ctty */
if (!pidlock_held)
if (!pidlock_held)
}
sess_t *
tty_hold(void)
{
/* make sure the caller isn't holding locks they shouldn't */
for (;;) {
/* make sure the caller isn't holding locks they shouldn't */
/*
* If the session leader process is not exiting (and hence
* not trying to release the session's ctty) then we can
* safely grab a hold on the current session structure
* and return it. If on the other hand the session leader
* process is exiting and clearing the ctty then we'll
* wait till it's done before we loop around and grab a
* hold on the session structure.
*/
break;
/* need to hold the session so it can't be freed */
mutex_exit(&p->p_splock);
/* Wait till the session leader is done */
/*
* Now we need to drop our hold on the session structure,
* but we can't hold any locks when we do this because
* sess_rele() may need to acquire pidlock.
*/
if (got_sig)
return (NULL);
}
/* whew, we finally got a hold */
mutex_exit(&p->p_splock);
return (sp);
}
void
{
/* make sure the caller isn't holding locks they shouldn't */
}
void
sess_create(void)
{
/*
* we need to grap p_lock to protect p_pgidp because
* /proc looks at p_pgidp while holding only p_lock.
*
* we don't need to hold p->p_sessp->s_lock or get a hold on the
* session structure since we're not actually updating any of
* the contents of the old session structure.
*/
mutex_enter(&p->p_lock);
mutex_enter(&p->p_splock);
pgexit(p);
mutex_exit(&p->p_splock);
mutex_exit(&p->p_lock);
}
/*
* Note that sess_ctty_clear() resets all the fields in the session
* structure but doesn't release any holds or free any objects
* that the session structure might currently point to. it is the
* callers responsibility to do this.
*/
static void
{
/*
* Assert that we hold all the necessary locks. We also need
* to be holding proc_t->p_splock for the process associated
* with this session, but since we don't have a proc pointer
* passed in we can't assert this here.
*/
/* reset the session structure members to defaults */
/* reset the stream session and group pointers */
}
static void
{
/* Assert that we hold all the necessary locks. */
/* get holds on structures */
mutex_enter(&p->p_crlock);
mutex_exit(&p->p_crlock);
/* update the session structure members */
/* update the stream emebers */
}
int
{
/*
* We are going to try to make stp the default ctty for the session
* associated with curproc. Not only does this require holding a
* bunch of locks but it also requires waiting for any outstanding
* holds on the session structure (acquired via tty_hold()) to be
* released. Hence, we have the following for(;;) loop that will
* acquire our locks, do some sanity checks, and wait for the hold
* count on the session structure to hit zero. If we get a signal
* while waiting for outstanding holds to be released then we abort
* the operation and return.
*/
for (;;) {
mutex_exit(&p->p_splock);
return (ENOTTY);
}
/* sanity check. we can't be exiting right now */
/*
* If no one else has a hold on this session structure
* then we now have exclusive access to it, so break out
* of this loop and update the session structure.
*/
break;
/* need to hold the session so it can't be freed */
/* ain't locking order fun? */
mutex_exit(&p->p_splock);
if (got_sig)
return (EINTR);
}
/* set the session ctty bindings */
mutex_exit(&p->p_splock);
return (0);
}
/*
* freectty_lock() attempts to acquire the army of locks required to free
* the ctty associated with a given session leader process. If it returns
* successfully the following locks will be held:
* sd_lock, pidlock, p_splock, s_lock
*
* as a secondary bit of convenience, freectty_lock() will also return
* pointers to the session, ctty, and ctty stream associated with the
* specified session leader process.
*/
static boolean_t
{
mutex_exit(&p->p_splock);
return (B_FALSE);
}
if (at_exit) {
/* stop anyone else calling tty_hold() */
} else {
/*
* due to locking order we have to grab stp->sd_lock before
* drop all our current locks it's possible that someone
* could come in and change our current session or close
* the current ctty (vp) there by making sp or stp invalid.
* (a VN_HOLD on vp won't protect stp because that only
* prevents the vnode from being freed not closed.) so
* to prevent this we bump s_ref and s_cnt here.
*
* course this doesn't matter if we're the last thread in
* an exiting process that is the session leader, since no
* one else can change our session or free our ctty.
*/
}
/* drop our session locks */
mutex_exit(&p->p_splock);
/* grab locks in the right order */
/* if the session has changed, abort mission */
/*
* this can't happen during process exit since we're the
* only thread in the process and we sure didn't change
* our own session at this point.
*/
/* release our locks and holds */
mutex_exit(&p->p_splock);
return (B_FALSE);
}
/*
* sanity checks. none of this should have changed since we had
* holds on the current ctty.
*/
/* release our holds */
if (!at_exit) {
}
/* return our pointers */
return (B_TRUE);
}
/*
* Returns B_FALSE if no signal is sent to the process group associated with
* this ctty. Returns B_TRUE if a signal is sent to the process group.
* If it return B_TRUE it also means that all the locks we were holding
* were dropped so that we could send the signal.
*/
static boolean_t
{
/* Assert that we hold all the necessary locks. */
/* check if we already signaled this group */
if (sp->s_sighuped)
return (B_FALSE);
if (!at_exit) {
/*
* once again, we're about to drop our army of locks and we
* don't want sp or stp to be freed. (see the comment in
* freectty_lock())
*/
}
/* can't hold these locks while calling pgsignal() */
mutex_exit(&p->p_splock);
/* signal anyone in the foreground process group */
/* signal anyone blocked in poll on this stream */
/* release our holds */
if (!at_exit)
return (B_TRUE);
}
int
{
/*
* If the current process is a session leader we are going to
* try to release the ctty associated our current session. To
* do this we need to acquire a bunch of locks, signal any
* processes in the forground that are associated with the ctty,
* and make sure no one has any outstanding holds on the current
* session * structure (acquired via tty_hold()). Hence, we have
* the following for(;;) loop that will do all this work for
* us and break out when the hold count on the session structure
* hits zero.
*/
for (;;) {
return (EIO);
/* loop around to re-acquire locks */
continue;
}
/*
* Only a session leader process can free a ctty. So if
* we've made it here we know we're a session leader and
* if we're not actively exiting it impossible for another
* thread in this process to be exiting. (Because that
* thread would have already stopped all other threads
* in the current process.)
*/
/*
* If no one else has a hold on this session structure
* then we now have exclusive access to it, so break out
* of this loop and update the session structure.
*/
break;
if (!at_exit) {
/* need to hold the session so it can't be freed */
}
/* ain't locking order fun? */
mutex_exit(&p->p_splock);
if (at_exit) {
/*
* if we're exiting then we can't allow this operation
* to fail so we do a cw_wait() instead of a
* cv_wait_sig(). if there are threads with active
* holds on this ctty that are blocked, then
* they should only be blocked in a cv_wait_sig()
* and hopefully they were in the foreground process
* group and recieved the SIGHUP we sent above. of
* course it's possible that they weren't in the
* foreground process group and didn't get our
* signal (or they could be stopped by job control
* in which case our signal wouldn't matter until
* they are restarted). in this case we won't
* exit until someone else sends them a signal.
*/
continue;
}
}
if (got_sig)
return (EINTR);
}
/* save some pointers for later */
/* clear the session ctty bindings */
/* wake up anyone blocked in tty_hold() */
if (at_exit) {
}
/* we can drop these locks now */
mutex_exit(&p->p_splock);
/* This is the only remaining thread with access to this vnode */
/* release our holds on assorted structures and return */
return (1);
}
/*
* ++++++++++++++++++++++++
* ++ SunOS4.1 Buyback ++
* ++++++++++++++++++++++++
*
* vhangup: Revoke access of the current tty by all processes
* Used by privileged users to give a "clean" terminal at login
*/
int
vhangup(void)
{
/*
* This routine used to call freectty() under a condition that
* could never happen. So this code has never actually done
* anything, and evidently nobody has ever noticed.
*/
return (0);
}
{
#ifdef DEBUG
else
#endif /* DEBUG */
return (dev);
}
void
ctty_clear_sighuped(void)
{
}