[Mono-list] Deamonize. Running a Mono app. in the background

Jonathan Pryor jonpryor@vt.edu
Wed, 16 Mar 2005 06:33:41 -0500


On Tue, 2005-03-15 at 16:24 -0700, Jesse Pasichnyk wrote:
> Are the execv, setuid and setgid methods working?
> 
> I wrote some stuff using those, and it did the execv fine, but didn't seem
> to want to change the identity the application was running under.
> 
> The exe had permissions 6755.
> 
> Is this not possible since the application is run by the mono executable?

Calling execv is probably a bad idea, as it would prevent mono from
properly cleaning up after itself (properly shutting down the Wapi
layer, etc.).

setuid and setgid should work fine; the problem likely is that you don't
have permissions.  For example, I'm able to do this:

	int r = Syscall.setgid (Syscall.getgid());

And it works properly.  If I try any other group, it fails (r == -1 and
Syscall.GetLastError() == EPERM), which I'd expect after reading the man
page.

The solution is to run the application as root, which allows you to
change your process user and group ids.

The actual problem is likely the 6755 permissions -- you applied them to
the .exe.  The .exe isn't the program executed, though, mono is.  It's
rather akin to a shell script invoked as "bash my-script.sh": if
permissions 6755 are applied to my-script.sh, it won't actually change
the permissions, as my-script.sh isn't being executed, "bash" is.  The
same occurs with "mono my-program.exe".

It is unlikely that this could be any different, unless you add
binfmt_misc support to your kernel and execute the .exe "directly".

 - Jon