[英]Problem with bin/sh -i in a forked process, error: 'can't access tty, job control turned off'
I'm writing a cgi-bin program for my Sheevaplug (running the default Ubuntu install) that displays a shell in a browser page. 我正在为Sheevaplug(运行默认的Ubuntu安装)编写一个cgi-bin程序,该程序在浏览器页面中显示一个外壳。 It is a single C program that is placed in the cgi-bin folder and viewed in a browser. 它是一个单个C程序,放置在cgi-bin文件夹中并在浏览器中查看。 It automatically launches a daemon and the daemon forks an instance of the shell. 它会自动启动一个守护程序,并且该守护程序会派生一个shell实例。 The cgi-bin communicates with the daemon via shared memory block, and the daemon communicates with the shell by redirecting its stdin/stdout to the shell's stdout/stdin. cgi-bin通过共享内存块与守护程序通信,并且守护程序通过将其stdin / stdout重定向到shell的stdout / stdin与Shell通信。 When you leave the page it automatically turns off the daemon. 当您离开页面时,它将自动关闭守护程序。
It works if I launch it using "/bin/sh" and I send a whole command line at a time from the browser to it. 如果我使用“ / bin / sh”启动它,并且一次从浏览器向其发送整个命令行,则它可以工作。 But using that design it's not interactive. 但是使用这种设计不是交互式的。
So I changed it to send a character at a time to "/bin/sh" and added "-i" so the shell runs in interactive mode. 因此,我将其更改为一次发送一个字符到“ / bin / sh”,并添加了“ -i”,以便外壳以交互模式运行。
When the shell starts up it displays the error "can't access TTY, job control turned off." 当外壳启动时,它显示错误“无法访问TTY,作业控制已关闭”。
It then displays the '$' when it is ready for input and seems to work, but sending delete characters to it just confuses it and it doesn't properly handle deleting. 当准备好输入并可以正常工作时,它会显示“ $”,但是向其发送删除字符只会使它感到困惑,并且不能正确处理删除操作。 I'm not really sure if it is in interactive mode or not. 我不确定它是否处于交互模式。 When I type 'su root' I get the error "must be run from a terminal'. 当我输入'su root'时,出现错误“必须从终端运行”。
Any ideas what I am doing wrong? 有什么想法我做错了吗?
PS: When I have it done it will be released under the GPL. PS:完成后,它将根据GPL发布。
For interactive mode, sh wants to be talking to a terminal or something that emulates one (a pseudo-terminal ), not just direct IO pipes. 对于交互模式,sh想要与终端或模拟一个终端 ( 伪终端 )的东西交谈,而不仅仅是直接IO管道。 Consider using forkpty to start the process you launch the shell from, and talking to the streams provided by that. 考虑使用forkpty启动启动外壳程序的过程,并与该程序提供的流进行对话。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.