PDA

View Full Version : QProcess::start() failed when application runs from sudo



alenyashka
20th June 2010, 20:13
Hi all,

I wrote a console application, which during work runs the external application. For this purpose I use QProcess.

When my application is being run by any user - everything works fine. But if my application runs from "sudo", then QProcess start failed with error QProcess::FailedToStart.

Does anyone know why this happens?

Thanks in advance.

ChrisW67
20th June 2010, 22:31
Have you checked that you can manually run your external application from the root account (or whatever account you run the main app in)? Possibly a difference in the environment: executable path, library path etc.

alenyashka
21st June 2010, 06:02
Oh, it's very good idea.

I've tested it. When I run application from user or root it work nice. If I run it from "sudo" it faild with "command not found" error. But if I use "sudo -i" it work nice too.

So, I think it is not problem in QProcess.

Thanks for help.

ChrisW67
22nd June 2010, 06:35
When I run application from user or root it work nice. If I run it from "sudo" it faild with "command not found" error. But if I use "sudo -i" it work nice too.
From the sudo man page

The -i (simulate initial login) option runs the shell specified in the passwd(5) entry of the target user as a login shell. This means that login-specific resource files such as .profile or .login will be read by the shell.
It works with "-i" and not without because the system default environment, specifically PATH, is being augmented by whatever is in the root user's login scripts (depends on the shell). When run without the "-i" you will get the system default environment which is usually very basic. Try something like:


$ sudo /usr/bin/env
$ sudo -i /usr/bin/env
to see the difference