Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 27 Jul 2000 19:27:26 -0400 (EDT)
From:      Brian Dean <brdean@unx.sas.com>
To:        Luoqi Chen <luoqi@watermarkgroup.com>
Cc:        bde@zeta.org.au, freebsd-arch@FreeBSD.ORG
Subject:   Re: isatty() reports false results
Message-ID:  <Pine.BSF.4.21.0007271911001.78156-100000@tribble.unx.sas.com>
In-Reply-To: <200007272036.e6RKaBR18831@lor.watermarkgroup.com>

next in thread | previous in thread | raw e-mail | index | archive | help

On Thu, 27 Jul 2000, Luoqi Chen wrote:

> > I suppose, at worst, we could move the TIOCGETA handling to precede
> > the check for the slave being open.  Would that be valid?
> >
> The master is not in the normal sense a tty, I think we could just change
> the return code from EAGAIN to ENOTTY to conform to the POSIX standard.
> As for isatty(), I don't think we need to change anything, it is a pilot
> error to call isatty() on the master side of the pty.

The way this section of code gained my attention was when I was
setting up a VPN using ppp over ssh.  For example, my setup gets
instantiated using something like this:

  % /usr/local/bin/pty-redir \
       /usr/bin/ssh -t -e none -o 'Batchmode yes' \
                     -i $key -l $user $host > ~/vpndev
  % /usr/sbin/pppd `cat ~/vpndev` $localip:$remoteip

In the above, pty-redir allocates a pty, opens the master side of it,
prints out the name of the slave side, dup2()'s the master side as
stdin and stdout, forks off ssh, then exits.  This leaves ssh using
the master side as stdin/stdout.  On the remote host, the login shell
for $user is just /usr/sbin/pppd.

The local invocation of pppd uses the slave side of the pty which
talks to the remote side and establishes the connection.

[This, btw, shows some of the true elegance of Unix - the ability to
chain together several seemingly unrelated processes in order
instantiate a construct that the original authors of the individual
pieces did not necesarily intend or conceive.]

Where the pty ioctl() code gets involved is with the '-t' option to
ssh.  This options causes ssh to request that the remote sshd allocate
a pty for the remote pppd which it seems to need.  Ssh wants to
validate that stdin is really a tty before making the request to the
remote side.  To do this it calls 'isatty()', which ends up being
called on the master side of a pty pair in this case.

Perhaps ssh is trying to be smarter than it should be?  So based on
your statement above, about pilot error, should the validation check
be removed from 'ssh'?  I have no problem with that, assuming we can
maintain this diff or get the contributors to make the same change.

Then again, this also seems like a simple matter of timing.  If I
modify pty-redir slightly to add a delay after the parent exits, but
before the child execs ssh, that will give the local pppd a chance to
open the slave side before ssh tries to call isatty().  Kind've
kludgy, but it works (most of the time - under high system load it may
not work).

The only problem is that, if we don't change either 'isatty()', or
'ssh', or the pty driver, then others are going to run into this same
problem if, like me, they come across the Linux VPN HOW-TO and use it
for ideas in setting up a VPN on FreeBSD :(.  Our pty driver seems to
behave differently in this respect to Linux and NetBSD (and probably
others as well).

-Brian



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0007271911001.78156-100000>