All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Peter Hüwe" <PeterHuewe@gmx.de>
To: ratheesh kannoth <ratheesh.ksz@gmail.com>
Cc: linux-c-programming@vger.kernel.org,
	linux-newbie <linux-newbie@vger.kernel.org>
Subject: Re: "reboot" detection ...
Date: Sun, 26 Aug 2012 14:22:58 +0200	[thread overview]
Message-ID: <201208261422.58413.PeterHuewe@gmx.de> (raw)
In-Reply-To: <CAGZFCEFLx9nu4Dcm2iX5bTC+R5GcF63Kp+TW4XUvg8EcGoM5PQ@mail.gmail.com>

> 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


  reply	other threads:[~2012-08-26 12:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-26 10:04 "reboot" detection ratheesh kannoth
2012-08-26 12:22 ` Peter Hüwe [this message]
2012-08-26 16:34   ` Anatoly Sivov
2012-08-26 18:14     ` Peter Hüwe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201208261422.58413.PeterHuewe@gmx.de \
    --to=peterhuewe@gmx.de \
    --cc=linux-c-programming@vger.kernel.org \
    --cc=linux-newbie@vger.kernel.org \
    --cc=ratheesh.ksz@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.