【发布时间】:2014-04-26 07:21:21
【问题描述】:
我编写了一个嵌入式应用程序(一个 vt52 终端仿真器),运行在一个基于 linux rom 的系统上,没有内置 ptys;和 Unix98 坏了。但是由于我必须有 ptys 才能使终端工作......我手动将旧式 BSD pty 编译为内核模块。 但由于某些奇怪的原因,我无法使用 BSD ptys 成功发送 SIGINT (ctrl-c) ...
VT52 程序是一个守护进程,而不是我想向其发送信号的程序的父进程——但这不重要,不是吗?我的意思是,有一个 pty slave 参与其中......
VT52 通过创建一个 BSD pty 对(/dev/terminal with major=3,minor=0 permissions=crwxrwxrwx,以及 /dev/ptyp0 as major 2,minor 0 permissions=crwxrwxrwx)进行通信并打开它们以供阅读和写作。终端向 ptyp0 发送击键,包括偶尔的 ctrl-c \003,它还从 ptyp0 读取返回的数据。
程序在作为会话负责人启动后通过 /dev/terminal 连接到 vt52 守护进程,并获得 pty 作为控制终端。通常,我使用以下代码作为会话负责人运行 busybox sh (?ash?) 程序:
// snippet from session.c
child=fork();
...
session=setsid();
...
// Child alone gets here.
close(0); close(1); close(2); // Close all IO to allow for a new CTTY.
open( argv[1], O_RDONLY ); // stdin
open( argv[1], O_WRONLY ); // stdout
open( argv[1], O_WRONLY ); // stderr
ioctl( 0, TIOCSCTTY, 0 ); // Set the controlling TTY based on stdin
return execvp( cmd, args ); // run whatever program the user requested.
而且我知道它有效,因为我在 vt52 上运行了“ps a”,得到:
PID TTY STAT TIME COMMAND
476 ttymxc0 Ss+ 0:00 /sbin/getty -L 115200 ttymxc0 vt102
631 ? Ds+ 34:13 ./vt52 /dev/ttyGS0
706 terminal Ss 0:00 /bin/sh -i
711 terminal R+ 0:00 ps a
所以,session.c 工作了,CTTY 是正确的......因此,当我发送 ctrl-c; shell 应该终止进程组/子进程——但它没有。 例如,如果我运行“sleep 20”,然后按 ctrl-c,则 20 秒内没有任何反应...
我检查以确保 vt52 确实将 \x03 写入 /dev/ptyp0,它确实...
所以,然后我通过“stty -a”检查了伪终端设置:
speed 38400 baud; rows 84; columns 75;
intr - ^C; quit = "^\; erase = ^?; kill = ^U; eof = ^D;
eol = <undef>; eol2 = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; inext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread clocal -crtscts
-ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff iuclc -ixany -imaxbel
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke
一切看起来都很好... 所以——我不明白为什么 SIGINT 没有被发送给 shell 的孩子。 我错过了什么?
如果 shell 在命令提示符下,并且我按下 ctrl-c,它会转到下一行……虽然我不知道它是否这样做,因为它捕获了一个信号,或者接收到一个字符代码 - - 我不知道如何弄清楚......但无论如何,shell 没有基于 SIGINT / control-C 进行作业控制。
帮助... :) 我如何打开它?
【问题讨论】: