* "reboot" detection ...
@ 2012-08-26 10:04 ratheesh kannoth
2012-08-26 12:22 ` Peter Hüwe
0 siblings, 1 reply; 4+ messages in thread
From: ratheesh kannoth @ 2012-08-26 10:04 UTC (permalink / raw)
To: linux-c-programming, linux-newbie
Hi,
Is there any way to find that the machine is rebooting. ?
Say, i issued a "reboot" command in one of the Konsole shell. Is
there any way to detect this trigger in kernel space or in userspace ?
Any clue is really appreciated .
Thanks,
Ratheesh
--
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: "reboot" detection ...
2012-08-26 10:04 "reboot" detection ratheesh kannoth
@ 2012-08-26 12:22 ` Peter Hüwe
2012-08-26 16:34 ` Anatoly Sivov
0 siblings, 1 reply; 4+ messages in thread
From: Peter Hüwe @ 2012-08-26 12:22 UTC (permalink / raw)
To: ratheesh kannoth; +Cc: linux-c-programming, linux-newbie
> Is there any way to find that the machine is rebooting. ?
>
> Say, i issued a "reboot" command in one of the Konsole shell. Is
> there any way to detect this trigger in kernel space or in userspace ?
> Any clue is really appreciated .
Hi ratheesh,
in the kernel it's pretty easy.
Simply use register_reboot_notifier from kernel/sys.c and you'll get notified
(via a callback you register) when the system gets rebooted.
You can use this stub driver as a reference (not actually tested):
---
#include <linux/module.h>
#include <linux/notifier.h>
#include <linux/reboot.h>
static int my_reboot_callback(struct notifier_block *self,
unsigned long val,
void *data){
if (val == SYS_RESTART)
pr_debug("We're rebooting\n");
return NOTIFY_DONE;
}
static struct notifier_block my_reboot_notifier = {
.notifier_call = my_reboot_callback,
};
static int __init my_reboot_init(void)
{
return register_reboot_notifier(&my_reboot_notifier);
}
static void __exit my_reboot_exit(void)
{
register_reboot_notifier(&my_reboot_notifier);
}
module_init(my_reboot_init);
module_exit(my_reboot_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Peter Huewe <peterhuewe@gmx.de>");
---
regards,
Peter
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: "reboot" detection ...
2012-08-26 12:22 ` Peter Hüwe
@ 2012-08-26 16:34 ` Anatoly Sivov
2012-08-26 18:14 ` Peter Hüwe
0 siblings, 1 reply; 4+ messages in thread
From: Anatoly Sivov @ 2012-08-26 16:34 UTC (permalink / raw)
To: ratheesh kannoth, Peter Hüwe; +Cc: linux-c-programming, linux-newbie
> static void __exit my_reboot_exit(void)
> {
> register_reboot_notifier(&my_reboot_notifier);
> }
Surely, this one should call unregister_reboot_notifier.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: "reboot" detection ...
2012-08-26 16:34 ` Anatoly Sivov
@ 2012-08-26 18:14 ` Peter Hüwe
0 siblings, 0 replies; 4+ messages in thread
From: Peter Hüwe @ 2012-08-26 18:14 UTC (permalink / raw)
To: Anatoly Sivov; +Cc: ratheesh kannoth, linux-c-programming, linux-newbie
Am Sonntag, 26. August 2012, 18:34:45 schrieb Anatoly Sivov:
> > static void __exit my_reboot_exit(void)
> > {
> >
> > register_reboot_notifier(&my_reboot_notifier);
> >
> > }
>
> Surely, this one should call unregister_reboot_notifier.
Hehe, yes. This was just a test to see if you pay attention.
Peter
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-08-26 18:14 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-26 10:04 "reboot" detection ratheesh kannoth
2012-08-26 12:22 ` Peter Hüwe
2012-08-26 16:34 ` Anatoly Sivov
2012-08-26 18:14 ` Peter Hüwe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).