Re: Powerdown notification
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com Hi Matt- -Ethan On Mar 16, 2009, at 6:54 AM, Matthew Mashyna wrote: 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 ); } Thanks, Matt _______________________________________________ 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/ebold%40apple.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... 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) 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 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 ? This email sent to ebold@apple.com This email sent to site_archiver@lists.apple.com
participants (1)
-
Ethan Bold