site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com Thread-index: AcaLx4CpvwP9nPe6EdqTeQAWy4i6sA== Thread-topic: Question on using launchd from a C program User-agent: Microsoft-Entourage/11.2.3.060209 It's probably a real sin to suggest this, but since you are waiting for lepoard anyway.... Add this, and the associated observeNotices to your background app: [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(observeNotices:) name:nil object:nil suspensionBehavior:NSNotificationSuspensionBehaviorDeliverImmediately ]; In observeNotices, print out the NSNotification name and object values. You will get everything, since the above addObserver call didn't specify. Look at what gets printed out. Here are some event names you might be interested in: com.apple.userWillLogOut - the object will be a string containing the user id com.apple.sessionDidMoveOffConsole - for fast user switching com.apple.sessionDidMoveOnConsole - for fast user switching Once you figure out what notifications you like, replace the addObserver with specific calls to register for specific notifications. I've used these calls from a "faceless background app". They work fine. If you don't like objective C, then figure out how to make similar calls from CoreFoundation. Of course, these will just get you by until Apple fully documents how to do this kind of thing in Leapord.... Paul Nelson Thursby Software Systems, Inc.
From: Mike Kobb <mjkobb@alum.mit.edu> Date: Thu, 8 Jun 2006 19:09:38 -0700 To: <darwin-dev@lists.apple.com> Subject: Re: Question on using launchd from a C program
Thanks for that! I did consider the login/logout hooks, and I think they could well work, but to install them you need administrator privileges, and ideally I would not like to have to have the user have to authenticate to set up the login behavior.
I think what I'm going to do instead is write a very simple faceless app that will be set as a login item. It will launch my server when it launches at login (if the user chose login-time launch), and at logout it'll find the server and tell it to quit. Should be very straightforward, and has the advantage (compared to launchd) of working on older OSes as well.
Appreciate the suggestion. --Mike
On Jun 8, 2006, at 6:38 PM, Andre LaBranche wrote:
On Jun 8, 2006, at 6:04 PM, Mike Kobb wrote:
Unfortunately, I need this to work, well, today if possible. ;-)
I'm sorry if I mis-typed. It's login and logout that I care about. Not boot or shutdown (except insofar as shutdown implies logout). I want them to be able to choose to launch it at login, or do it manually. Then, if it's running when they log out (whichever of those two methods they chose), I want it to quit. ...
Perhaps a loginhook / logouthook would work for the interim?
http://developer.apple.com/documentation/MacOSX/Conceptual/ BPSystemStartup/Articles/CustomLogin.html
Cheers, -Andre
On Jun 8, 2006, at 4:37 PM, Dave Zarzycki wrote:
Will you be attending WWDC?
Can you wait for Leopard?
Why the asymmetric requirement of launching at boot, but exiting at logout (as opposed to at boot/shutdown or login/logout)?
davez
On Jun 8, 2006, at 3:55 PM, Mike Kobb wrote:
Greetings,
I'm working on a MacOS preference pane that is used to configure the options of a faceless background process (a music server).
This process is a BSD process for historical reasons, but will run under the privileges of a particular user, and not as root.
I want to have a pop-up in the prefs pane that allows the user to choose to manually launch the server (by clicking a "Start" button in the pane, or to have the server launch at startup. Either way, I want to be sure that the server quits when they log out.
It seems like launchd is likely to be what I want, but there are a few things I could use some help with.
I have figured out how to create the appropriate plist to make the server launch at login and quit at shutdown, and that seems to work fine.
So, I have two questions:
1) Is it possible to set up launchd to not launch the process at login, but to shut it down at logout?
2) I want this all to be controlled by my preference pane. Obviously, it's no trouble to get it to write out the required plist file, but the part I'm not sure about is how to do the equivalent of a "launchctl load" or "launchctl unload" operation. I could exec this, I guess, but I prefer to use a proper C API rather than the exec mechanism whenever I can. I couldn't make heads or tails out of launch.h, I'm afraid.
Thanks in advance, --Mike
_______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/nelson%40thursby.com
This email sent to nelson@thursby.com
_______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... This email sent to site_archiver@lists.apple.com