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

Tags: c linux shell fork
By : KPexEA
Source: Stackoverflow.com
Question!

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

By : KPexEA


Answers

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.



This video can help you solving your question :)
By: admin