NSTask Explodes. Clueless.
NSTask Explodes. Clueless.
- Subject: NSTask Explodes. Clueless.
- From: Seth Willits <email@hidden>
- Date: Mon, 04 Feb 2013 11:26:04 -0800
In my app I have to launch background processes (bundled within my app's Resources folder) to do some things, and I launch them with NSTask. Every now and then I get a crash report which shows NSTask throws some fatal exception which is not caught by a wrapping @try block.
For example:
@try {
NSString * taskPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"mytask"];
task = [[NSTask alloc] init];
task.launchPath = taskPath;
task.arguments = @[aUUIDString];
[task launch];
}
@catch (NSException * e) {
...
}
And it crashes:
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000002, 0x0000000000000000
*** NSTask: Task create for path '/Applications/App.app/Contents/Resources/mytask' failed: 22, "Invalid argument". Terminating temporary process.
*** multi-threaded process forked ***
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 com.apple.Foundation 0x978142d8 ___NEW_PROCESS_COULD_NOT_BE_EXECD___ + 7
1 com.apple.Foundation 0x976d2e16 -[NSConcreteTask launchWithDictionary:] + 4698
2 com.apple.Foundation 0x97744447 -[NSConcreteTask launch] + 40
What I can't figure out is what the error message means. I imagine it's coming from a call to exec(), but which argument is invalid is beyond me. The path to the task is correct. If the task wasn't in the app bundle, it'd be seriously broken, but also if I try to replicate it by using a bad path, it does crash this way, it simply throws a normal exception which is caught. The arguments I pass to the task are always simple trivial strings, nothing wacky.
Looking around the open source code for exec(), it appears EINVAL (22) can be returned if the task was exec()'d when not called from a vfork()'d process, with the comment /* If we're not in vfork, don't permit a mutithreaded task to exec */ which seems to line up with the *** multi-threaded process forked *** line in the crash log… trouble is I have no idea what this ultimately means to me. Seems like an OS bug?
So:
- It crashes instead of throwing an exception — not exactly friendly.
- It crashes *very rarely* (I've never seen it personally.)
- It's not just one task, it can happen with any of the tasks in the bundle.
- Seems to only have happened on 10.8.2 so far.
Any ideas?
--
Seth Willits
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden