如何让 HPUX 采用 TTY 作为控制

How to get HPUX to adopt a TTY as controlling

通过 sshpass mailing list (and also on stack overflow 遇到的一个问题。 Sshpass 不适用于 HP-UX。

查看桁架输出,我看到以下内容:

-u [/tmp/sshpass][14066]{3783827} fork() ................... (returning as child ...) ......... = 14064 {3783821}

子进程为14066

-u [/tmp/sshpass][14066]{3783827} setpgrp3(2)................................................. [entry]
-u [/tmp/sshpass][14066]{3783827} setpgrp3(2)................................................. = 14066

开始一个新的会话,与之前的 TTY 断开连接

-u [/tmp/sshpass][14066]{3783827} open(0x400132d0, O_RDWR, 01210)............................. [entry]
-u [/tmp/sshpass][14066]{3783827} open("/dev/pts/5", O_RDWR, 01210)........................... = 6

使用标记 O_RDWR 打开 /dev/pts/5。根据Posix,此时 pts/5 应该成为新的控制终端 过程。显然,这不会发生。

打开的 HP-UX 手册页建议打开 /dev/pts/5 应该使该进程采用它作为其新的控制 TTY。我不知道为什么没有发生这种情况,也不知道访问 HP-UX 系统进行实验。

其系统的人实际上不得不去 HP 的支持以获得答案,但既然我们现在有了答案,我会 post 在这里。

来自 HPUX termios(7) 手册页:

The controlling terminal is inherited by a child process during a fork() (see fork(2)). A process relinquishes its controlling terminal if it creates a new session with setsid() or setpgrp() (see setsid(2) and setpgrp(2)), or when all file descriptors associated with the controlling terminal have been closed.

(强调已添加)。

据我所知,粗体部分是 HPUX 特性,不属于 Posix 或其他 Unix 平台。

问题是 sshpass 打开相关的 tty,并立即关闭文件描述符,因为它假定它已经设置为进程的控制 TTY。

由于 HPUX 特性,这意味着 TTY 成为进程的控制 TTY,并在关闭后立即停止。