2

我尝试通过 linux os 上的一对伪 tty 打开网络连接。

# slattach -v /dev/ptmx
cslip started on /dev/ptmx interface sl0

好的,这是伪 tty 的“创造面”。

我可以查看 /dev/pts 并在那里找到新的 pty。如果我现在尝试在这边也使用 slattach,我得到:

slattach -v /dev/pts/3
slattach: tty_open(/dev/pts/3, RW): Input/output error

我用 strace 追踪:

28 5505  write(1, "slattach: tty_open: trying to op"..., 46) = 46
29 5505  open("/dev/pts/3", O_RDWR|O_NONBLOCK) = -1 EIO (Input/output error)
30 5505  write(2, "slattach: tty_open(/dev/pts/3, R"..., 55) = 55
31 5505  exit_group(3)

所有这一切都发生在 ubuntu 的不同发行版上,在 10.04 和 11.04 上进行了测试,但都失败了。

我做错了什么?

4

1 回答 1

1

您可能需要查看手册页pty(7)

基本上,/dev/ptmx 使用 Unix 98 伪终端接口,并要求您的程序使用 grantpt(3) 和 unlockpt(3)。在这里,slattach(打开 /dev/ptmx 的那个,而不是另一个)不会这样做,并且任何尝试打开与主节点关联的从伪终端的程序都会失败,正如您所经历的那样。

您可以通过使用外部例程重载 open() 调用来强制 slattach 执行 grantpt() 和 unlockpt(),请参阅此示例

于 2011-12-29T16:02:54.613 回答