register_sys_off_handler(9)
π register_sys_off_handler(9) π
okay bestie, welcome to the Kernel API Manual β this is the page where we learn how to get a callback to fire when the system powers off or restarts. yes, that kind of handler. very main character energy for your machine's final moments. π«Ά
β¨ NAME β¨
register_sys_off_handler β literally just "Register sys-off handler" π
πΈ SYNOPSIS πΈ
struct sys_off_handler * register_sys_off_handler (enum sys_off_mode
mode , int priority , int (*callback)(struct sys_off_data *data) , void
*cb_data );
like. that's the whole signature. four args. slay. β¨
π¦ ARGUMENTS π¦
modeβ the Sys-off mode, i.e. which step of the shutdown/restart saga your handler gets to show up at πpriorityβ Handler priority. where you stand in line, basically. no cutting, gorgeous πcallbackβ Callback function. this is the little function that actually does the thing when it's your turn π₯cb_dataβ Callback argument. the little gift bag you hand to your callback π
π DESCRIPTION π
so here's the tea β: this registers a system power-off or restart handler, and it gets invoked at the step corresponding to the given sys-off mode. matching vibes, matching moment. π«
your handler's callback should return NOTIFY_DONE to permit execution of the next handler in the call chain β yes, the chain keeps going, be a team player β or NOTIFY_STOP to break the chain (in error case for example). dramatic exit, honestly iconic. π
multiple handlers can be registered at the default priority level. the more the merrier, fr fr π«Ά
but. only one handler can be registered at the non-default priority level, otherwise ERR_PTR(-EBUSY) is returned. so likeβ¦ pick one. not me showing up twice to the non-default priority party π
Returns a new instance of struct sys_off_handler on success, or an ERR_PTR-encoded error code otherwise. π
π SEE ALSO π
- Kernel file
./kernel/reboot.c emergency_restart(9)register_reboot_notifier(9)unregister_reboot_notifier(9)register_restart_handler(9)unregister_restart_handler(9)do_kernel_restart(9)kernel_restart(9)kernel_halt(9)unregister_sys_off_handler(9)devm_register_sys_off_handler(9)devm_register_power_off_handler(9)devm_register_restart_handler(9)register_platform_power_off(9)unregister_platform_power_off(9)do_kernel_power_off(9)kernel_can_power_off(9)kernel_power_off(9)orderly_poweroff(9)orderly_reboot(9)hw_failure_emergency_action_func(9)hw_failure_emergency_schedule(9)__hw_protection_trigger(9)
like, read them. all of them. iykyk π
okay that's the page!! it lives in ./kernel, the version vibes are October 2026, and yes the header and footer both say register_sys_off_handler(9) because symmetry is cute. go register something responsibly bestie π§ββοΈπ
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms