Module notifier

Notifier chain mechanism.

This library allows Lua scripts to register callback functions that are invoked when specific kernel events occur, such as keyboard input, network device status changes, or virtual terminal events.

Class notifier

notifier:stop () Stops and unregisters a notifier.

notifier

kbd Table of keyboard event types.
keyboard (callback) Registers a notifier for keyboard events.
netdev Table of network device event types.
netdevice (callback) Registers a notifier for network device events.
notify Table of notifier chain return status codes.
vt Table of virtual terminal (VT) event types.
vterm (callback) Registers a notifier for virtual terminal (vterm) events.


Class notifier

Represents a kernel notifier object. This is a userdata object returned by functions like notifier.keyboard(), notifier.netdevice(), or notifier.vterm(). It encapsulates a struct notifier_block and the associated Lua callback.
notifier:stop ()
Stops and unregisters a notifier. This method is called on a notifier object. Once stopped, the callback will no longer be invoked for kernel events.

Returns:

    nil

Raises:

Error if the notifier attempts to unregister itself from within its own callback (which would cause a deadlock).

Usage:

    my_notifier:stop()

notifier

kbd
Table of keyboard event types. Used as the event argument in notifier.keyboard callbacks.

Fields:

  • KEYCODE integer Keyboard keycode event, called before any other.
  • UNBOUND_KEYCODE integer Keyboard keycode which is not bound to any other.
  • UNICODE integer Keyboard unicode character event.
  • KEYSYM integer Keyboard keysym event.
  • POST_KEYSYM integer Event called after keyboard keysym interpretation.
keyboard (callback)
Registers a notifier for keyboard events. The provided callback function will be invoked whenever a console keyboard event occurs (e.g., a key is pressed or released).

Parameters:

  • callback function The Lua function to call on keyboard events. It receives the following arguments:

    1. event (integer): The keyboard event type (see notifier.kbd).
    2. down (boolean): true if the key is pressed, false if released.
    3. shift (boolean): true if a shift key (Shift, Alt, Ctrl) is held, false otherwise.
    4. value (integer): The key's value (keycode or keysym, depending on the event).

    The callback should return a notifier.notify status code (e.g., notifier.notify.OK).

Returns:

    notifier A new notifier object.

See also:

Usage:

    local kbd_notifier = notifier.keyboard(function(event, down, shift, value) print("Key event:", event, value); return notifier.notify.OK end)
netdev
Table of network device event types. Used as the event argument in notifier.netdevice callbacks.

Fields:

  • UP integer Network device is up.
  • DOWN integer Network device is down.
  • REBOOT integer Network device is rebooting (deprecated).
  • CHANGE integer Network device has changed state.
  • REGISTER integer Network device is being registered.
  • UNREGISTER integer Network device is being unregistered.
  • CHANGEMTU integer MTU of the network device has changed.
  • CHANGEADDR integer Hardware address of the network device has changed.
  • PRE_CHANGEADDR integer Notification before hardware address change.
  • GOING_DOWN integer Network device is being taken down.
  • CHANGENAME integer Name of the network device has changed.
  • FEAT_CHANGE integer Features of the network device have changed.
  • BONDING_FAILOVER integer Bonding master has failed over to a new slave.
  • PRE_UP integer Notification before network device is brought up.
  • PRE_TYPE_CHANGE integer Notification before network device type changes.
  • POST_TYPE_CHANGE integer Notification after network device type changes.
  • POST_INIT integer Notification after network device initialization.
  • PRE_UNINIT integer Notification before network device uninitialization (Kernel 6.2+).
  • RELEASE integer Network device is being released.
  • NOTIFY_PEERS integer Notify peers of a change.
  • JOIN integer Network device has joined a multicast group.
  • CHANGEUPPER integer Upper device state change.
  • RESEND_IGMP integer Resend IGMP joins.
  • PRECHANGEMTU integer Notification before MTU change.
  • CHANGEINFODATA integer Network device info data has changed.
  • BONDING_INFO integer Bonding information update.
  • CHANGE_TX_QUEUE_LEN integer Transmit queue length has changed.
netdevice (callback)
Registers a notifier for network device events. The provided callback function will be invoked whenever a network device event occurs (e.g., an interface goes up or down).

Parameters:

  • callback function The Lua function to call on netdevice events. It receives the following arguments:

    1. event (integer): The netdevice event type (see notifier.netdev).
    2. name (string): The name of the network device (e.g., "eth0").

    The callback should return a notifier.notify status code.

Returns:

    notifier A new notifier object.

See also:

Usage:

    local net_notif = notifier.netdevice(function(event, name) print("Netdev event:", name, event); return notifier.notify.OK end)
notify
Table of notifier chain return status codes. These values are typically returned by notifier callback functions.

Fields:

  • DONE integer Indicates the callback is done and doesn't care about further processing.
  • OK integer Indicates the callback processed the event successfully and other notifiers can proceed.
  • BAD integer Indicates the callback encountered an issue or wants to veto the action.
  • STOP integer Indicates the callback handled the event and no further notifiers in the chain should be called.
vt
Table of virtual terminal (VT) event types. Used as the event argument in notifier.vterm callbacks.

Fields:

  • VT_ALLOCATE integer Virtual terminal is being allocated.
  • VT_DEALLOCATE integer Virtual terminal is being deallocated.
  • VT_WRITE integer Character is written to virtual terminal.
  • VT_UPDATE integer Virtual terminal update event.
  • VT_PREWRITE integer Before writing character to virtual terminal.
vterm (callback)
Registers a notifier for virtual terminal (vterm) events. The provided callback function will be invoked whenever a virtual terminal event occurs (e.g., a character is written, a terminal is allocated).

Parameters:

  • callback function The Lua function to call on vterm events. It receives the following arguments:

    1. event (integer): The vterm event type (see notifier.vt).
    2. c (integer): The character related to the event (if applicable).
    3. vc_num (integer): The virtual console number associated with the event.

    The callback should return a notifier.notify status code.

Returns:

    notifier A new notifier object.

See also:

generated by LDoc 1.5.0 Last updated 2025-06-27 17:53:55