notifierModule
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. A callback returns a linux.notify code. No value, a callback that raises, which is logged, and an event that reaches a runtime not ready to take it, or that the runtime’s own code raises from under its lock, count asnotify.DONE, and so does any other value, which is logged as invalid notify
code.
Class notifier
| notifier:stop () | Stops event delivery to the Lua callback. |
notifier
| keyboard (callback) | Registers a keyboard-event notifier. |
| netdevice (callback) | Registers a network-device notifier. |
| vt (callback) | Registers a virtual-terminal notifier. |
Class notifier in detail
Represents a kernel notifier object.
This is a userdata object returned by functions like
notifier.keyboard(),
notifier.netdevice(), or notifier.vt(). It encapsulates a
struct notifier_block and the associated Lua callback.
- notifier:stop ()
-
Stops event delivery to the Lua callback.
After
stop(), the underlyingnotifier_blockremains registered in the kernel chain until the owning runtime is torn down, but firings become silent no-ops. This keepsstop()safe in any context (including hardirq) since it performs no sleeping operations; the real unregistration happens inrelease, which always runs in process context. A to-be-closed variable holding the notifier stops it the same way.Returns
-
nil
Usage
my_notifier:stop()
notifier in detail
- keyboard (callback)
-
Registers a keyboard-event notifier. Must be called from a
hardirqruntime.Parameters
- callback
function
invoked as
callback(event, down, shift, value)—eventis a linux.kbd code,downis a boolean (key pressed),shiftis a boolean (modifier held), andvalueis the keycode or keysym depending onevent. Returns a linux.notify status code.
Returns
-
notifier
the notifier, which this call keeps for its runtime: dropping it
stops nothing, and the callback runs until stop or the end of the runtime
Raises
EOPNOTSUPPon a kernel built withoutCONFIG_VT; if called from a percpu runtime;runtime context mismatchoutside a hardirq runtime;not allowed while the runtime closesfrom a finalizer that runs at its close; the kernel’s errno when it refuses the registration - callback
function
invoked as
- netdevice (callback)
-
Registers a network-device notifier. Must be called from a
softirqruntime,lunatik run --context=softirq <script>: the callback runs under RTNL, where nothing it reaches may wait on RTNL, and a softirq runtime takes no call that sleeps once it is armed. The devices of every network namespace are reported, each with the inode number of its namespace: linux.ifindex resolves a name in the initial namespace only, so a script keeps the devices that name resolves by comparing that number withlinux.netns().Parameters
- callback
function
invoked as
callback(event, name, netns)—eventis a linux.netdev.cmd code,nameis the device name (e.g."eth0") andnetnsthe inode number of its network namespace, as linux.netns gives it. The registration itself delivers, inside this call, aREGISTERfor each device every namespace already has, and anUPfor each of those that is up; a script that means the devices appearing afterwards tells them apart with a flag it clears once this call returns, since no live event reaches the callback before the script body ends. Returns a linux.notify status code.notify.STOPandnotify.BADend the chain, so the kernel’s own blocks after this one never see the event: a callback returns them only for an event whose result the kernel reads to refuse a change, as it readsPRE_UP’s, and never forUNREGISTER, whose device then waits for good on what 8021q and the other blocks after it would have released.
Returns
-
notifier
the notifier, which this call keeps for its runtime: dropping it
stops nothing, and the callback runs until stop or the end of the runtime
Raises
if called from a percpu runtime, or under RTNL: from a netdevice callback, the replay this call delivers included, and from any coroutine the callback runs;runtime context mismatchoutside a softirq runtime;not allowed once the runtime is armedpast the script body, since the registration sleeps;not allowed while the runtime closesfrom a finalizer that runs at its close; the kernel’s errno when it refuses the registration,EPERMwhen the callback returnsnotify.BADfor a replayedREGISTER - callback
function
invoked as
- vt (callback)
-
Registers a virtual-terminal notifier. Must be called from a
hardirqruntime.Parameters
- callback
function
invoked as
callback(event, c, vc_num)—eventis a linux.vt.event code,cis the character value aWRITEorPREWRITEcarries and nil for any other event, andvc_numis the virtual console number. Returns a linux.notify status code.
Returns
-
notifier
the notifier, which this call keeps for its runtime: dropping it
stops nothing, and the callback runs until stop or the end of the runtime
Raises
EOPNOTSUPPon a kernel built withoutCONFIG_VT; if called from a percpu runtime;runtime context mismatchoutside a hardirq runtime;not allowed while the runtime closesfrom a finalizer that runs at its close; the kernel’s errno when it refuses the registration - callback
function
invoked as