Re: How to tell if system shutdown is in process
Re: How to tell if system shutdown is in process
- Subject: Re: How to tell if system shutdown is in process
- From: Brian Bergstrand <email@hidden>
- Date: Wed, 23 Mar 2011 23:55:31 -0500
Use IOKit, specifically, IORegisterForSystemPower(). In the callback you provide check for kIOMessageSystemWillPowerOff and kIOMessageSystemWillRestart.
p.s. Remember to register the notification port you get back with a run loop or your callback will never get called.
On Mar 23, 2011, at 8:51 PM, Antoine Missout wrote:
> While AppKit shouldn't be used in a global context daemon, you can always have a user-context agent and use something to communicate between the agent and the daemon (nsmachport...).
>
> But that's a really ugly solution to the problem.
>
> What is the mechanism used by NSWorkspace exactly ?
>
> What is the proper answer to the original question, ie getting the shutdown event in a global context daemon ?
>
> - Antoine
>
>
>
> On 2011-03-23, at 17:11, Quinn The Eskimo! wrote:
>
>>
>> On 23 Mar 2011, at 18:03, Jerry Krinock wrote:
>>
>>> The suggestion there is to use NSWorkspaceWillPowerOffNotification.
>>
>> NSWorkspace is not the droid you're looking for. AppKit sends it in response to a 'quit' Apple event that has the 'why?' attribute, implying that the app is being quit by loginwindow in preparation for restart or shutdown. This doesn't really help you.
>>
>> When you say "started automatically by launchd", do you mean the global system launchd (that is, pid 1) or some per-user launchd? If you're started by the global launchd, you're running in a daemon context and you should not be linking with AppKit (per the rules outlined in Technote 2083 "Daemons and Agents").
>>
>> <http://developer.apple.com/library/mac/#technotes/tn2005/tn2083.html>
>>
>> S+E
>> --
>> Quinn "The Eskimo!" <http://www.apple.com/developer/>
>> Apple Developer Relations, Developer Technical Support, Core OS/Hardware
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden