POWERHOOK_ESTABLISH(9)

πŸ“¦ version 11.0, in nixpkgs unstable

✨ NAME ✨

powerhook_establish, powerhook_disestablish β€” add or remove a power change hook.

Okay bestie, this is the POWERHOOK_ESTABLISH(9) page from the Kernel Developer's Manual, and we’re about to get into it. No cap, these functions are a whole vibe: one adds a hook, one removes it. πŸ’…


🧚 SYNOPSIS 🧚

The signatures are literally right here, bestie:

void *
powerhook_establish(const char *name, void (*fn)(int why, void *a),
    void *arg);

void
powerhook_disestablish(void *cookie);

🌸 DESCRIPTION 🌸

First thing first: the powerhook_establish API is deprecated. Periodt. See pmf(9) for replacement functionality.

The powerhook_establish() function adds fn to the list of hooks invoked by dopowerhooks(9) at power change. When invoked, the hook function fn will be passed the new power state as the first argument and arg as its second argument. That’s the whole handoff, iykyk. 🫢

The powerhook_disestablish() function removes the hook described by the opaque pointer cookie from the list of hooks to be invoked at power change. If cookie is invalid, the result of powerhook_disestablish() is undefined β€” so yeah, don’t be messy with that cookie. 😭

Power hooks should be used to perform activities that must happen when the power situation to the computer changes. Because of the environment in which they are run, power hooks cannot rely on many system services (including file systems, and timeouts and other interrupt-driven services). The power hooks are typically executed from an interrupt context. It’s giving β€œimportant but lowkey limited,” fr fr. ⚑

The different reasons for calling the power hooks are: suspend, standby, and resume. The reason is reflected in the why argument and the values PWR_SOFTSUSPEND, PWR_SUSPEND, PWR_SOFTSTANDBY, PWR_STANDBY, PWR_SOFTRESUME, and PWR_RESUME. It calls with PWR_SOFTxxx in the normal priority level while the other callings are protected with splhigh(9). At suspend the system is going to lose (almost) all power, standby retains some power (e.g., minimal power to USB devices), and at resume power is back to normal. Main character energy for the power state machine, honestly. πŸ‘‘

Here are those why values in their exact order, bestie:

  • PWR_SOFTSUSPEND
  • PWR_SUSPEND
  • PWR_SOFTSTANDBY
  • PWR_STANDBY
  • PWR_SOFTRESUME
  • PWR_RESUME

πŸ¦‹ RETURN VALUES πŸ¦‹

If successful, powerhook_establish() returns an opaque pointer describing the newly-established power hook. Otherwise, it returns NULL. So NULL is the β€œnope, didn’t work” signal β€” noted. πŸŽ€


🌈 SEE ALSO 🌈

  • dopowerhooks(9) β€” go read this too, bestie. It’s in the lore. πŸ’–

πŸ’– Debian, December 30, 2024 β€” mwah, bestie! πŸ’–

πŸ“¦ where this page comes from