[comp.unix.internals] Device Emulation with a pty?

km@mathcs.emory.edu (Ken Mandelberg) (10/06/90)

I would like to use a pty to let a process emulate a device.  However,
it looks to me like the pty interface doesn't really provide enough
control and status on the master side. For example, I don't see how
to:

 * send a HUP to the slave side process by operating on the master
  (to emulate a device hangup)

 * cause the slave side process to block on open (for example to
   simulate waiting for DCD)

 * detect the slave side open not just its first write.

 * detect device specific slave side ioctls and reply to them from
   the master side.

Can any of this been done on the existing BSD or Sun pty driver? Has
anyone done a more general pty streams module that does more of this.
-- 
Ken Mandelberg      | km@mathcs.emory.edu          PREFERRED
Emory University    | {rutgers,gatech}!emory!km    UUCP 
Dept of Math and CS | km@emory.bitnet              NON-DOMAIN BITNET  
Atlanta, GA 30322   | Phone: (404) 727-7963

brnstnd@kramden.acf.nyu.edu (Dan Bernstein) (10/08/90)

In article <6372@emory.mathcs.emory.edu> km@mathcs.emory.edu (Ken Mandelberg) writes:
> I would like to use a pty to let a process emulate a device.  However,
> it looks to me like the pty interface doesn't really provide enough
> control and status on the master side.

A pty only acts like a device over the lifetime of one session. It isn't
meant to survive past hangup. (Though you can set the tty speed to 0 to
simulate a hangup on some systems.)

What are you really trying to do?

>  * detect device specific slave side ioctls and reply to them from
>    the master side.

Look up TIOCPKT and TIOCREMOTE.

---Dan

guy@auspex.auspex.com (Guy Harris) (10/09/90)

>>  * detect device specific slave side ioctls and reply to them from
>>    the master side.
>
>Look up TIOCPKT and TIOCREMOTE.

Which will tell you that you can only detect *some* effects from
slave-side "ioctl"s (I'm not sure what "reply to them from the master
side" means, but if it means that the process on the master side is to
be responsible for providing the return code for "ioctl"s or providing
the return data from "ioctl"s such as TIOCGETP that return data, you
can't do that, either).

brnstnd@kramden.acf.nyu.edu (Dan Bernstein) (10/09/90)

In article <4166@auspex.auspex.com> guy@auspex.auspex.com (Guy Harris) writes:
> >>  * detect device specific slave side ioctls and reply to them from
> >>    the master side.
> >Look up TIOCPKT and TIOCREMOTE.
> Which will tell you that you can only detect *some* effects from
> slave-side "ioctl"s

Well, yes, but it's also the spot where vendors put in their more
advanced pseudo-tty controls. TIOCUCNTL, for example.

> (I'm not sure what "reply to them from the master
> side" means, but if it means that the process on the master side is to
> be responsible for providing the return code for "ioctl"s or providing
> the return data from "ioctl"s such as TIOCGETP that return data, you
> can't do that, either).

On some systems (such as HP-UX) you can do exactly that. There isn't
much standardization beyond TIOCPKT, but the features do exist. Which is
why I recommended looking them up...

---Dan