Greetings, while porting old Solaris 2.4 code to CentOS 5.3 I came across an invocation like
问候,在将旧的Solaris 2.4代码移植到CentOS 5.3时,我遇到了类似的调用
/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.
其中%s是两个字符的数字序列XX,如00,01,%d是数字文件描述符。这显然是一种告诉xterm使用/ dev / ttypXX(一个伪终端从属)的方法,但代码似乎没有打开相应的master,调用管道(2)而是将write fd作为%d替换传递以上。在Solaris上,从spawner写入此写入fd会导致输出显示在xterm子级中。在一个strace(1)中,顺便说一句,我看到没有尝试在/ dev下打开任何东西。
1 个解决方案
#1
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:
根据solaris联机帮助页,管道系统调用会创建两个双向管道。所以在solaris上你可以使用fds进行读写:
The files associated with fildes[0] and fildes1 are streams and are both opened for reading and writing.
与fildes [0]和fildes1相关联的文件是流,并且都打开以进行读取和写入。
However according to the pipe(2) manpage on linux:
但是根据linux上的pipe(2)手册页:
pipe() creates a pipe, a unidirectional data channel that can be used for interprocess communication.
pipe()创建一个管道,一个可用于进程间通信的单向数据通道。
Note also the following from pipe(7):
还要注意管道(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.
在某些系统(但不是Linux)上,管道是双向的:数据可以在管道端之间双向传输。根据POSIX.1-2001,管道只需要是单向的。便携式应用程序应避免依赖双向管道语义。
So, on linux you can't pass pipefd1, 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.
因此,在linux上你不能将writefd1(写端)传递给xterm,因为它期望fd用于双向通信。为了使它工作,你必须使用openpty()并将slave fd传递给xterm。
AFAIK, openpty is not available on Solaris; that seems be the reason your code doesn't use it.
Solaris上没有AFAIK,openpty;这似乎是你的代码不使用它的原因。
#1
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:
根据solaris联机帮助页,管道系统调用会创建两个双向管道。所以在solaris上你可以使用fds进行读写:
The files associated with fildes[0] and fildes1 are streams and are both opened for reading and writing.
与fildes [0]和fildes1相关联的文件是流,并且都打开以进行读取和写入。
However according to the pipe(2) manpage on linux:
但是根据linux上的pipe(2)手册页:
pipe() creates a pipe, a unidirectional data channel that can be used for interprocess communication.
pipe()创建一个管道,一个可用于进程间通信的单向数据通道。
Note also the following from pipe(7):
还要注意管道(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.
在某些系统(但不是Linux)上,管道是双向的:数据可以在管道端之间双向传输。根据POSIX.1-2001,管道只需要是单向的。便携式应用程序应避免依赖双向管道语义。
So, on linux you can't pass pipefd1, 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.
因此,在linux上你不能将writefd1(写端)传递给xterm,因为它期望fd用于双向通信。为了使它工作,你必须使用openpty()并将slave fd传递给xterm。
AFAIK, openpty is not available on Solaris; that seems be the reason your code doesn't use it.
Solaris上没有AFAIK,openpty;这似乎是你的代码不使用它的原因。