Picture of Silvio 2739
Registered 9 years 27 days
Silvio 2739 Monday, 28 February 2022, 09:06 AM
Spawning a process

I want to start a process using IProcess->Spawn(). But whatever I try I always get a return value of 0 and the same error message in the log:

IProcess::Spawn filename:/apps/appname/filename argc:0
IProcess::Spawn failed, status:13 (13 : Permission denied)

I tried

  • /apps/appname/filename
  • /mnt/sda2/apps/appname/filename
  • /home/appname/filename
  • /mnt/sda2/home/appname/filename
  • filename
  • ./filename
  • /bin/ls

but no luck. I even get this message for files that don't exist. All files and the directories on the way to them have at least rx set for owner, group, and others (for the test only, in production I'll restict permissions to the minimum). Owner and group are set to the app's owner and group.

What could the problem be here?

And a second question: The documentation for the argv parameter says "Note that the first argument is the process filename itself again." What does it mean for me? Should I add it as first parameter, or is this only a reminder that it is the usual behavior of the system when it provides the argv to the program?

Picture of Daniel Deterding (innovaphone)
Moderator Registered 15 years 121 days
Daniel Deterding (innovaphone) Monday, 28 February 2022, 09:46 AM
Re: Spawning a process
Here a small example which works:

char* argv[3];
argv[0] = (char*)"/apps/reporting/reporting";
argv[1] = (char*)"-arg1";
argv[2] = (char*)"valueOfArg1";

int pid = IProcess::Spawn(argv[0], 3, argv, logInstance);

So yes, the first argument must be the absolute path of the binary.
The binary must have the x flag set and must be available for the spawning user.

Note that the AP Manager creates a unix user for every app service and the whole app service directory is owned by this user.
This unix user just has access to this directory and to unix binaries which are available for all users.

Greetings,
Daniel
Picture of Silvio 2739
Registered 9 years 27 days
Silvio 2739 Monday, 28 February 2022, 11:00 AM
Re: Spawning a process
I did like in your example, but I get still the same error message.
Btw, can you please add your example to the documentation?

The unix user and group is named like the app service, e.g. demo. When I "su demo" in a SSH session I can start the binary without any problem. Its user and group is set to "demo". When I run the app and ask IProcess->GetOwnPID() and "ps -f <this_pid>" the UID is demo too. And I see no difference when I start the app from Visual Studio or the AP Manager.

When you say the app has access "to unix binaries which are available for all users", why even a "/bin/ls" results in "permission denied"?

Picture of Daniel Deterding (innovaphone)
Moderator Registered 15 years 121 days
Daniel Deterding (innovaphone) Thursday, 3 March 2022, 10:54 AM
Re: Spawning a process
Hi Silvio,

I was able to reproduce your issue now and I checked in a fix for the upcoming 13r2 service release (might be published in two weeks).

You should be aware though, that you cannot get STDOUT/STDERR of a process spawned like this.

If you're interested in this output, you may think about using the ICommand interface instead.

Greetings,
Daniel
Picture of Silvio 2739
Registered 9 years 27 days
Silvio 2739 Thursday, 3 March 2022, 05:46 PM
Re: Spawning a process
Thanks for fixing the bug. In my case the process doesn't communicate via STDIN/OUT/ERR. Starting it via Commands API is much more overhead without an advantage.
← You can define your color theme preference here