tags:

views:

89

answers:

1

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.

+5  A: 

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.

moonshadow
Thanks, I changed the fork to forkpty and now the initial error message doesn't appear anymore but I still get the 'must be run from a terminal' and I try and 'su root', any more ideas?
KPexEA
Maybe you can make your CGI a setuid program?
Amigable Clark Kant
It works fine if I launch my daemon manually under root, but doesn't work if the daemon is launched automatically by the cgi-bin. So I still have some more stuff to figure out. Thanks!
KPexEA