Subject: Re: tty dialin/dialout [PROPOSAL]
To: Paul A Vixie <paul@vix.com>
From: Charles M. Hannum <mycroft@mit.edu>
List: tech-kern
Date: 03/21/1998 07:52:23
Hmph.  Actually, SunOS appears to allow multiple simultaneous dialout
opens.  It also appears to use O_NONBLOCK and carrier for both dialin
and dialout devices, although I'm not sure why you'd ever want that
for dialout.  Here's what I think is a SunOS-compatible version of
ttyopen():

int
ttyopen(tp, dialout, nonblock)
	struct tty *tp;
	int dialout, nonblock;
{
	int s;

	s = spltty();

        if (dialout && ISSET(tp->t_state, TS_DIALIN)) {
		splx(s);
		return (EBUSY);
	}

	/*
	 * If we're opening for dialin use, wait for any dialout users
	 * to close the tty, and then wait for carrier.
	 */
	 if (!nonblock) {
		while ((!dialout && ISSET(tp->t_state, TS_DIALOUT)) ||
		       (!ISSET(tp->t_state, TS_CARR_ON) && 
			!ISSET(tp->t_cflag, CLOCAL | MDMBUF))) {
			tp->t_wopen++;
			error = ttysleep(tp, &tp->t_rawq, TTIPRI | PCATCH,
			    ttopen, 0);
			tp->t_wopen--;
			if (error) {
				splx(s);
				return (error);
			}
		}
	} else {
	        if (!dialout && ISSET(tp->t_state, TS_DIALOUT)) {
			splx(s);
			return (EBUSY);
		}
	}

	if (dialout)
		SET(tp->t_state, TS_DIALOUT);
	else
		SET(tp->t_state, TS_DIALIN);

	splx(s);
	return (0);
}

... and that's enough of this garbage for tonight!