register_sys_off_handler(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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 πŸ‘‘

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