PDA

View Full Version : Running shell script with as super user in N900



spylvas
30th April 2010, 00:55
Hey,

I am implementing a little application that needs to run a script that needs root privileges and I am wondering how to do that with QT in Meamo.

Right now I am using QProcess to run my script.

proc->start("sh", QStringList() << "script.sh" );

which is ok for running the script, but obviously it fails to execute and gives an error.

changing it to proc->start("sh", QStringList() << "sudo script.sh" ); doesn't seem to help either as it doesn't prompt a password for me. Not sure how do that, but is not functionality I am looking for either.

So any help would be appreciated.

Cheers,
Simo

wysota
30th April 2010, 01:05
In Linux sh scripts can't gain super-user priviledges - I mean the script itself can be ran suid root but each subprogram ran from it will not inherit that priviledge. There is a way around this but I won't suggest it here. I can only say it boils down to using a helper application that will gain the priviledges first, dealing with uid and euid (effective user id) and run the script then. Otherwise your only choice is to run the script from sh that already has superuser access rights but I guess that's not what you want (unless you want to run the whole N900 environment as root).