[comp.unix.wizards] Closing pty slaves

gnb@melba.bby.oz (Gregory N. Bond) (02/08/89)

I have a little kludge program that I use to connect the SunOs (3.5)
print spooler to a serial printer on a terminal server.  It basically
allocates a pty, opens an internet socket and goes into a select loop
copying bytes from one to the other.  The printcap entry for the printer
specifies the pty slave as the device.

It works OK until the daemon closes the tty slave it has opened (at the
end of the print job).  At that point, the select returns with the pty
master ready for reading, but reading from the descriptor results in
EIO.

What I have done is opened the slave part of the tty in the program so
there never is a last close on the slave, and it all works fine.

Why does select return read ready?  It seems to me that if select says
read is OK, then read should work.  And a closed pty slave should result
in 0 bytes being read (or select not returning ready at all, or an
exception condition), until the slave is re-opened.

And is there a better way of using lp with a terminal server?  Is there
some kernel method for attaching a TCP stream to a pty?

Greg.
-- 
Gregory Bond, Burdett Buckeridge & Young Ltd, Melbourne, Australia
Internet: gnb@melba.bby.oz.au    non-MX: gnb%melba.bby.oz@uunet.uu.net
Uucp: {uunet,mnetor,pyramid,ubc-vision,ukc,mcvax,...}!munnari!melba.bby.oz!gnb

chris@mimsy.UUCP (Chris Torek) (02/11/89)

In article <99@melba.oz> gnb@melba.bby.oz (Gregory N. Bond) writes:
>...  At that point, the select returns with the pty master ready
>for reading, but reading from the descriptor results in EIO. ...
>Why does select return read ready?  It seems to me that if select says
>read is OK, then read should work.

It did work---or at least, it did not block: which is after all what
select is all about.

Some people think this should be an `exception' rather than a `ready'
condition, but it works well enough as is.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris