简体   繁体   English

分叉进程中的bin / sh -i问题,错误:“无法访问tty,作业控制已关闭”

[英]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.

相关问题 在 C 中调用 execv(“/bin/sh”, NULL) 时,如何与子进程通信(例如,通过写入运行命令)? - how can I communicate (eg. run commands via write) with a child process when execv(“/bin/sh”, NULL) was called in C? bin/sh 错误和 mekefile 错误 127 但我在脚本中编写了 bin/bash? - bin/sh error and mekefile error 127 but i write bin/bash in my script? execv用“/bin/sh -c”启动一个进程,会不会有新进程 - execv lauches a process using "/bin/sh -c",will there be a new process 我可以将父进程的stderr重定向到分叉进程上的套接字文件描述符吗? - Can I redirect a parent process's stderr to a socket file descriptor on a forked process? 从execv启动终端(sh)返回错误:/ bin / sh:/ bin / sh:无法执行二进制文件 - start terminal (sh) from execv return error : /bin/sh: /bin/sh: cannot execute binary file 为什么不解决分叉过程中的变化? - Why doesn't address change in forked process? 分叉的过程没有在C中调用函数 - Forked process isn't calling function in C 我应该使用exit()终止分叉的子进程吗? - Should I be terminating a forked child process with exit()? 你怎么能在按键时杀死一个分叉的进程? - How can you kill a forked process on key press? 为什么无法在pthread中访问可可控件? - Why can't access cocoa control in a pthread?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM