Re: Powerdown notification
Re: Powerdown notification
- Subject: Re: Powerdown notification
- From: Ethan Bold <email@hidden>
- Date: Wed, 18 Mar 2009 11:07:39 -0700
Hi Matt-
IOKit does not provide any notifications of system shutdown. The
IORegisterForSystemPower() API call that you make below only refers to
system sleep & wake power events, not shutdown events - the argument
messageType may be kIOPMMessageCanSystemSleep,
kIOPMMessageSystemWillSleep, kIOPMMessageSystemWillNotSleep,
kIOPMMessageSystemHasPoweredOn, kIOPMMessageSystemWillPowerOn. That's
all - no messages sent on shutdown.
I'd suggest two options:
(1) explore further in the NSWorkspace API area. I don't know anything
about that and I'm not sure anything exists, but it's my next best
guess.
(2) Rely on the fact that xnu BSD code will kill your process at
shutdown time, first with a SIGTERM, and then later a SIGKILL to any
remaining processes. If you handle the SIGTERM, you can signal to your
server at that time. Of course, anyone can send a SIGTERM to your
process without shutting down the machine. However, off the top of my
head I don't know if you're guaranteed full network functionality at
this point - configd and network processes may be killed at the same
time you are. (See xnu/bsd/kern/kern_shutdown.c)
-Ethan
On Mar 16, 2009, at 6:54 AM, Matthew Mashyna wrote:
I'm sorry for having to ask a noob question. I posted this to the
Darwin user list last week but didn't get any replies. I have a
Cocoa daemon that needs to monitor system events and relay them to a
server. Using NSWorkspace notification I get sleep and wake messages
but I can't seem to get the power down notification. So, other cocoa
developers pointed me to using IOKit. I tried this from my daemon
void myPowerDownCallback(void *refcon,
io_service_t service,
uint32_t messageType,
void *messageArgument )
{
DLog(@"System shutdown message!");
[gDaemon systemWillPowerOff];
} // myPowerDownCallback
// from my initialization code
{
...
IONotificationPortRef thePortRef;
io_object_t notifier;
io_connect_t c = IORegisterForSystemPower(NULL,
&thePortRef,
myPowerDownCallback,
¬ifier );
}
I don't think the callback gets called. I suppose that it could be
interrupted before it can send its message but I really don't think
I'm getting the callback. I'm a complete noob with it comes to
IOKit. Can someone tell me where I'm going wrong ?
Thanks,
Matt
_______________________________________________
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
_______________________________________________
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