I am testing the reboot notifier hook on Linux kernel 5.8 running on QEMU ARM64 with busybox rootfs. This is my first time using a notifier list, so I might be wrong. I have add one reboot notifier which is executed well, but I have also added a second item to the list using .next
and the handler of this notifier does not execute. Here's the snippet from my dummy driver:
static int reboot_handler_first(struct notifier_block *this, unsigned long action,
void *data)
{
printk(KERN_INFO "first reboot notifier called
");
return 0;
}
static int reboot_handler_second(struct notifier_block *this, unsigned long action,
void *data)
{
printk(KERN_INFO "second reboot notifier called
");
return 0;
}
static struct notifier_block reboot_notifier_second = {
.notifier_call = reboot_handler_second,
.next = NULL,
.priority = INT_MAX,
};
static struct notifier_block reboot_notifier_first = {
.notifier_call = reboot_handler_first,
.next = &reboot_notifier_second,
.priority = INT_MAX,
};
Here, the reboot_handler_first()
gets called but I do not see any log from reboot_handler_second()
. I was expecting that reboot_notifer_first()
will trigger reboot_notifier_second()
but that does not seem to be the case. Am I missing anything?
Below are the logs that I see with this kernel and busybox rootfs:
/ # reboot
/ # umount: devtmpfs busy - remounted read-only
swapoff: can't open '/etc/fstab': No such file or directory
The system is going down NOW!
Sent SIGTERM to all processes
Sent SIGKILL to all processes
Requesting system reboot
[ 20.158023] first reboot notifier called
[ 20.232718] reboot: Restarting system
[ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x411fd070]
EDIT
This is how my module_init(hello_init)
function looks like. I have registered only the first reboot notifier reboot_notifier_first
and then set its next to point to the reboot_notifier_second
. Please correct me. My understanding is that I need to register the first notifier with register_reboot_notifier()
and then I just need to set the .next
of current notifier_block
to add new nodes to the linked list. This way I will get a chain of notifier blocks.
static int __init hello_init(void)
{
int rc;
rc = register_reboot_notifier(&reboot_notifier_first);
printk(KERN_INFO "This is from init
");
return 0;
}
question from:
https://stackoverflow.com/questions/65650339/how-does-linux-reboot-notifier-list-work 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…