开发者

Problem with bin/sh -i in a forked process, error: 'can't access tty, job control turned off'

开发者 https://www.devze.com 2022-12-14 07:28 出处:网络
I\'m writing a cgi-bin program for my Sheevaplug (running the default Ubuntu install) that displays a shell in a browser page. It is a single C program that is placed in the cgi-bin folder and viewed

I'm writing a cgi-bin program for my Sheevaplug (running the default Ubuntu install) that displays a shell in a browser page. It is a single C program that is placed in the cgi-bin folder and viewed in a browser. It automatically launches a daemon and the daemon forks an instance of the 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. When you leave the page it automatically turns off the daemon.

It works if I launch it using "/bin开发者_JAVA百科/sh" and I send a whole command line at a time from the browser to it. 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.

When the shell starts up it displays the error "can't access TTY, job control turned off."

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'.

Any ideas what I am doing wrong?

PS: When I have it done it will be released under the 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. Consider using forkpty to start the process you launch the shell from, and talking to the streams provided by that.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号