implementing relaunch in a sandboxed app
implementing relaunch in a sandboxed app
- Subject: implementing relaunch in a sandboxed app
- From: Keith Knauber <email@hidden>
- Date: Tue, 18 Dec 2012 17:27:09 +0000
- Thread-topic: implementing relaunch in a sandboxed app
Automatic relaunch of your app is such a basic software requirement, and apple has never published a clean method for accomplishing this.
There are situations when a relaunch of an app is much safer, faster, and fault tolerant than an approach which kills every background thread,
deletes all your NSDocument objects, and open a new NSDocument.
There is only one method you can google http://13bold.com/tutorials/relaunching-your-application/, which has worked for me until sandbox.
With sandboxing requirements, now this relatively simple approach becomes impossibly complex to implement and understand…
jumping through the hoops to build the final .app for submission becomes a mess of build scripts and unmaintainable cross references.
So, I tried an execv approach.
Without sandboxing, this works beautifully and much faster than the relaunch daemon approach.
With sandboxing, execv is a violation.
Is there a way to get this to work?
If not, Apple needs to make a sandbox entitlement to allow execv of your own executable.
- (void) applicationWillTerminate:(NSNotification *)notification
{
… do clean-up tasks like NSUserDefaults synchronize, etc. …
if ( ! userWantsRelaunch )
return;
const char *execPath = [[[NSBundle mainBundle] executablePath] fileSystemRepresentation];
… do sanity/security checks. I recognize this may have thread safety issues …
// FD_CLOEXEC close all files upon execv,
// takes less than 5ms.
int sz = getdtablesize();
for(int i=3; i<sz; i++) { // start at 3… we want to keep stdin, stdout, and std err.
int flags = fcntl(i, F_GETFD);
if(flags<0) continue;
fcntl(i, F_SETFD,flags| FD_CLOEXEC);
}
NSLog( @"****** expect gdb to hit breakpoint at __dyld__dyld_start *******\n" );
NSLog( @"****** main_relaunch execv() *******\n" );
execv( execPath, sArgvFromMain ); // will not return. <---- sandbox violation here
NSLog( @"****** execv() failed *******\n" );
… use relaunch daemon instead …
}
~K
_______________________________________________
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