SMJobSubmit
Xcodeで作成したUnix実行可能ファイルを通常のデスクトップアプリ内から起動するために使用しようとしています。(GUI部分は、コマンドラインヘルパーツールを呼び出すことになっています。)
これが私が仕事を提出しようとするのに使うコードです。
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[authView setString:kSMRightModifySystemDaemons];
[authView setAutoupdate:YES];
[authView setDelegate:self];
}
- (IBAction)pressedButton:(id)sender
{
/*
authView is an instance of SFAuthorizationView. At this point, the user
already clicked the padlock and entered his password.
*/
authRef = [[authView authorization] authorizationRef];
//toolPath points to the file in the app's Resource folder.
NSArray* call = [NSArray arrayWithObject:toolPath];
NSDictionary* jobSpec = [NSDictionary dictionaryWithObjectsAndKeys:
call, @"ProgramArguments",
jobLabel, @"Label",
[NSNumber numberWithBool:YES], @"RunAtLoad",
nil];
CFErrorRef submitError = nil;
BOOL submitResult = SMJobSubmit(kSMDomainSystemLaunchd,
(__bridge CFDictionaryRef)(jobSpec),
authRef,
&submitError);
if(!submitResult)
{
NSLog(@"Job submit failed. %@", submitError);
return;
}
}
submitResult
常にであることが判明しましたがtrue
、私のプログラムは実行されていないようです。ターミナルから手動でプログラムを実行しましたが、完全に機能します。ヘルパーツールは、ファイルシステム上の場所にファイルを書き込むことになっており、引数を取りません。ただし、デーモンを起動するために送信しても、何も起こりません。実行可能としてマークされています。パスも確認しました。あたりです。
では、launchデーモンが特定の種類のファイルしか実行できないのではないかと疑問に思っています。コードで何かを台無しにしない限り。