Daemon Advice?
Daemon Advice?
- Subject: Daemon Advice?
- From: Karl Moskowski <email@hidden>
- Date: Wed, 23 Jul 2008 16:09:57 -0400
I'm working on a Foundation tool to be used as a launchd daemon. It's
a Leopard-only GC app that uses FSEvents to watch for changed files.
I'm using something similar to the below code, and it seems to work
correctly when under launchd control. However, information on creating
Foundation-based Objective-C daemons is hard to find and I'm worried
I'm missing something, or (worse) on the wrong track entirely.
Can anyone offer any tips or guidance? Thanks.
----
Karl Moskowski <email@hidden>
Voodoo Ergonomics Inc. <http://voodooergonomics.com/>
// daemon.m
#import <Foundation/Foundation.h>
#import <signal.h>
#import "AnObject.h"
#import "MyObserver.h"
void handleSignal (int signal) {
NSLog(@"Shutting daemon down");
AnObject * anObject = [[AnObject alloc] init];
[anObject doCleanup];
[[NSDistributedNotificationCenter defaultCenter]
postNotificationName:@"DaemonHasShutDown" object:nil userInfo:nil
options:NSNotificationPostToAllSessions];
exit(EXIT_SUCCESS);
}
int main (int argc, const char * argv[]) {
signal (SIGTERM, handleSignal);
signal (SIGINT, handleSignal);
AnObject * anObject = [[AnObject alloc] init];
if (![AnObject doSetup])
exit(EXIT_FAILURE);
NSLog(@"Daemon running");
[[NSDistributedNotificationCenter defaultCenter]
postNotificationName:@"DaemonIsRunning" object:nil userInfo:nil
options:NSNotificationPostToAllSessions];
[[MyObserver sharedInstance] beginObserving];
[[NSRunLoop currentRunLoop] run];
return EXIT_SUCCESS;
}
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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