• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Daemon Advice?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Daemon Advice?
      • From: Chris Hanson <email@hidden>
    • Re: Daemon Advice?
      • From: Nick Zitzmann <email@hidden>
  • Prev by Date: Re: Dumb question: How does NSScrollView know the size of the thing it's scrolling?
  • Next by Date: First Responder, NSUndoManager, and MyDocument
  • Previous by thread: Re: Dumb question: How does NSScrollView know the size of the thing it's scrolling?
  • Next by thread: Re: Daemon Advice?
  • Index(es):
    • Date
    • Thread