Re: Can't exec from a Cocoa app?
Re: Can't exec from a Cocoa app?
- Subject: Re: Can't exec from a Cocoa app?
- From: Andrew Farmer <email@hidden>
- Date: Thu, 24 Aug 2006 08:58:06 -0700
On 24 Aug 06, at 02:56, Uli Kusterer wrote:
Am 24.08.2006 um 00:46 schrieb Tom Harrington:
I have an app which at some point wants to call execle(). However
the
call fails, returning -1 with errno set to ENOTSUP, "Operation not
supported".
The execle() call is pointing to a valid mach-O binary (itself, as it
happens, and yeah it's the binary and not the bundle). The reason I
bring this up here is that if I copy and paste the execle() call into
a plain old C command-line app (a basic sanity check done since "man
execle" doesn't even allow that ENOTSUP can happen), it works exactly
as I'd expect. So... something about running as a Cocoa app makes
this not work? Is there something extra I need to do to make it work
from my Cocoa app?
Now, I'm wildly guessing here, but AFAIR exec and stuff like that
basically create a copy of the current application (or am I mixing
that up with fork?), where some things (like file descriptors to
stdin and stdout) may still be shared. So maybe that also applies
to a window server connection and that's why your app fails?
Fork creates a new process identical to the current one. Exec
replaces the current process with another one. The fork/exec
combination is often used to create a subtask.
I just tried the same thing in a minimal Cocoa app and got the same
result, oddly enough. Using a fork/exec worked fine, though. So what
I'd suggest would be something along the lines of:
int r = fork();
if(r < 0):
throw an error and return (probably ran out of processes, argh)
if(r > 0):
exit (parent process)
if(r == 0):
execle
exit (exec failed - there's not much we can do about it now)
I'd have to dig into the kernel source to see why this is happening,
and I'd definitely recommend filing a documentation bug. I suspect it
does have something to do with Mach resources, though.
Attachment:
PGP.sig
Description: This is a digitally signed message part
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden