Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-dev/email@hidden

This email sent to email@hidden
References: 
 >Question on using launchd from a C program (From: Mike Kobb <email@hidden>)
 >Re: Question on using launchd from a C program (From: Dave Zarzycki <email@hidden>)
 >Re: Question on using launchd from a C program (From: Mike Kobb <email@hidden>)
 >Re: Question on using launchd from a C program (From: Andre LaBranche <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.