Re: Launchd daemon
Re: Launchd daemon
- Subject: Re: Launchd daemon
- From: Erwin Namal <email@hidden>
- Date: Sun, 17 Mar 2013 22:53:57 +0100
Nick Blievers, Jens Alfke,
Thank you for your reply. What kind of thing is it going to do?
The daemon will just maintain a database shared by all users of the computer, as well as hold some configuration options tied to external hardware and dialog with kexts. When no user is logged in, the daemon will be able to answer the kexts questions about the hardware's configuration. When one or many users are logged in, the daemon will allow them to access the database in a thread-secure way as well as modify the hardware config.
Does it _really_ need to be running all the time, not just during a user’s login session? It’s a lot easier and safer to make a per-user agent process. (Apple has an excellent tech note on daemons and agents, that lays out the pros and cons of each.)
It is all the time.
1. Which language can I use for my daemon? Obj-C? C? C++?
Yes, any of those.
Great. I am more comfortable with Objective-C.
3. I know I need to handle SIGTERM, but I don't know how. Are there any other requirements?
SIGTERM is what you get from a Ctrl-C in a terminal. You don’t have to handle it explicitly, if you don’t have to clean anything up on quit. But if there are things like files or sockets you need to take care of before exiting, then yes, you should handle SIGTERM.
How can I handle a sigterm in objective-C ? I saw an example in C once, didn't pay much attention… and I can't find it now… I remember it was on a sample project… 4. I think that once launched, the daemon must have an infinite loop, right? ShouldI put a sleep() call inside? If yes, for how long?
Don’t call sleep. Your daemon is going to be waiting for watching for things to happen, so just like a GUI app you’re probably going to structure your code as handlers that respond to events of some sort. How exactly depends on what you want the daemon to do. It’s often good to use kqueues, as they give you a nice event-loop mechanism that can listen to various sorts of things like signals, filesystem notifications, socket I/O, IPC messages, etc.
So, when my daemon is launched, I expose my control sockets and exit? launchd will keep my daemon resident?
- E
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden