For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > November 2004 > Is PTY's slave side open?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Is PTY's slave side open?
Gerhard Rieger

2004-11-29, 4:07 pm

Hi,

I am developing a GPL'ed utility (http://www.dest-unreach.org/socat/)
that creates a PTY and holds its master side. When another process opens
the slave side, the utility transfers data between the PTY and some
other bidirectional channel.

My problem is that the utility can generally not determine if the PTY's
slave side is in use and data transfer should start. This can block
resources on the other channel (German readers, check out Heise c't
2004/13, p.200), or, even worse, result in a permanent error when the
utility writes to the PTY's master side before the slave side is opened
(e.g. on Solaris).

On some of the platforms that implement the non-standard openpty()
mechanism instead of /dev/ptmx, this problem can be handled with polling
the HUP status of the PTY using poll(): The code opens the slave side
and closes it immediately, causing a HUP condition. It then polls the
HUP condition of the PTY in regular intervalls. When the HUP condition
ends, this indicates that the slave side has been opened. But this is
ugly and not generally usable.

Any ideas?

Gerhard Rieger <rieger@dest-unreach.org>
Antoine Mathys

2004-11-29, 4:07 pm

> My problem is that the utility can generally not determine if the PTY's
> slave side is in use and data transfer should start. This can block
> resources on the other channel (German readers, check out Heise c't
> 2004/13, p.200), or, even worse, result in a permanent error when the
> utility writes to the PTY's master side before the slave side is opened
> (e.g. on Solaris).


Have you tried to set O_ASYNC on the master side? it should gives you a
SIGIO whenever input or output is possible.

Antoine Mathys
Gerhard Rieger

2004-11-29, 4:07 pm

I don't think that sigio does much different from the status that
select() gives, and that indicates immediately "ready for writing".


Antoine Mathys wrote:
>
>
> Have you tried to set O_ASYNC on the master side? it should gives you a
> SIGIO whenever input or output is possible.
>
> Antoine Mathys

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com