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: Jerry Krinock <email@hidden>
- Date: Thu, 24 Mar 2011 10:27:49 -0700
On 2011 Mar 23, at 14:11, Quinn The Eskimo! wrote:
> When you say "started automatically by launchd", do you mean the global system launchd (that is, pid 1) or some per-user launchd?
I mean a the current user's launchd (typically pid 130), directed by a plist file which my app installs in ~/Library/LaunchAgents/.
> 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").
I think I'm OK with that.
On 2011 Mar 23, at 21:55, Brian Bergstrand wrote:
> Use IOKit, specifically, IORegisterForSystemPower(). In the callback you provide check for kIOMessageSystemWillPowerOff and kIOMessageSystemWillRestart.
Well, the documentation for IORegisterForSystemPower() states that it is "for the purpose of receiving sleep & wake notifications for the system. Does not provide system shutdown and restart notifications."
But I tried Brian's suggestion anyhow, incorporating the sample code given in QA1340 noted by Quinn,
http://developer.apple.com/library/mac/#qa/qa1340/_index.html
and in the callback, I added case kIOMessageSystemWillPowerOff and case kIOMessageSystemWillRestart.
Result: Unfortunately, the documentation is correct. I get callbacks for sleep and wake, but not for shut down.
On 2011 Mar 24, at 02:16, Quinn The Eskimo! wrote:
> On 24 Mar 2011, at 01:51, Antoine Missout wrote:
>
>> What is the proper answer to the original question, ie getting the shutdown event in a global context daemon ?
>
> I don't have a good answer.
Well, I think my original question is to getting the shutdown event in a *user* context daemon.
The only notification I've been able to receive is SIGTERM. And further testing shows that whatever sends the SIGTERMs to processes during shutdown will *block* sending further SIGTERMs when an app doesn't terminate. I say this because, in my most recent test, this happened:
min:sec
00:00 Confirmed by clicking the "Shut Down" button
00:03 Got the first "dirty document" warning from an app. I did not respond.
00:30-00:40 Clicked "Don't Save" in this dialog, and in two others which appeared from two other apps
00:51 My process received SIGTERM ("Finally!!")
01:11 My process was killed
So, this is quite worse than I had thought. Let me restate my question, in case this helps:
I want my non-GUI command-line program which is launched by user-level launchd to know as early as possible when shutdown is occuring, preferably (for example, if initiated by the console user) immediately when the user clicks the "Shut Down" button in the confirmation dialog, and, at least, before SIGTERMs start getting sent to processes. NSWorkspaceWillPowerOffNotification doesn't work, and IORegisterForSystemPower() doesn't work. Alternatively, I'd like an API to which I could ask before beginning a long task, "Is shutdown in progress?"
Thanks,
Jerry
_______________________________________________
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