views:

463

answers:

1

Greetings, while porting old Solaris 2.4 code to CentOS 5.3 I came across an invocation like

/usr/bin/xterm -S%s%d ...

where %s is a two-character digit sequence XX like 00, 01 and %d is a numeric file descriptor. This was apparently a way to tell xterm to use /dev/ttypXX (a pseudo terminal slave) but the code does not seem to bother with opening the corresponding master, calling pipe(2) instead and passing the write fd as the %d substitution above. On Solaris, writing to this write fd from the spawner causes output to appear in the xterm child. In a strace(1) I saw no attempt to open anything under /dev, by the way.

+1  A: 

According to the solaris manpage, the pipe system call creates two bidirectional pipes. So on solaris you can use both fds for reading and writing:

The files associated with fildes[0] and fildes[1] are streams and are both opened for reading and writing.

However according to the pipe(2) manpage on linux:

pipe() creates a pipe, a unidirectional data channel that can be used for interprocess communication.

Note also the following from pipe(7):

On some systems (but not Linux), pipes are bidirectional: data can be transmitted in both directions between the pipe ends. According to POSIX.1-2001, pipes only need to be unidirectional. Portable applications should avoid reliance on bidirectional pipe semantics.


So, on linux you can't pass pipefd[1], the write end, to xterm since it expects an fd for bidirectional communication. To make it work, you'd have to use openpty() and pass the slave fd down to xterm.

AFAIK, openpty is not available on Solaris; that seems be the reason your code doesn't use it.

Inshallah