PDA

View Full Version : QProcess::execute() within service not using inherited PATH



RolandHughes
15th June 2015, 05:52
It's late and I could just be thick.

32-bit Ubuntu 12.4.5
latest Qt 5.x

Have a service with a .conf file. It launches a shell script which runs a watchdog program. The watchdog program does many setup verification things then it does a Qt execute() of another shell file. This shell file runs the actual application.

Here is the interesting thing. The shell script makes calls to logger which show it really does inherit the PATH value from the parent process. It doesn't actually use it though.

If I run the program with just programName it dies with an exit code 2, program not found. If I hardcode the full path of /home/userName/bin/programName it dies with an exit code of 134.

I can use a sudo command from my own directory (which, should, in theory, be the same the service conf start on login-session-start) everything works. It is like execute() doesn't pass a complete environment in this instance.

The .conf for the service does chdir to the actual directory for the program.

Anyone else encounter this?

jefftee
15th June 2015, 06:18
Look at QProcessEnvironment. You can modify the path, then set your QProcess to use the new environmental variables using QProcess::setEnvironment.

RolandHughes
15th June 2015, 18:36
Look at QProcessEnvironment. You can modify the path, then set your QProcess to use the new environmental variables using QProcess::setEnvironment.

Thank you for the attempt. We are going to have to bail on creating this as a service. Going back to the old fashioned never ending automatically restarting cron job approach. First level works perfectly, but second does not. I assume there is some undocumented (or sparsely documented) "feature" with service which forces forks instead of letting the executing watchdog create a totally different process which it monitors.

jefftee
15th June 2015, 20:38
Not sure why you need to bail on your attempt to create a service. Do you have other issues/challenges besides the PATH environmental variable?

ChrisW67
15th June 2015, 22:51
Here is the interesting thing. The shell script makes calls to logger which show it really does inherit the PATH value from the parent process.


If I run the program with just programName it dies with an exit code 2, program not found. If I hardcode the full path of /home/userName/bin/programName it dies with an exit code of 134.

So you have demonstrated:

QProcess started the shell script with the expected PATH
The shell script with the expected PATH fails to launch your program because the program is not on the PATH or for some other reason.
When you eliminate the PATH search the shell script executes your program which promptly fails for some other reason.

Point 2 and 3 demonstrate that the problem is not related to Qt. The exit codes returned by QProcess::execute() are those of the shell running your shell script and only meaningful in that context.