mdevd
Software
skarnet.org
The mdevd-netlink program
mdevd-netlink listens to the netlink interface for uevents
(also called "hotplug" or "udev" events), and writes those uevents to
its standard output, using a simple format.
mdevd expects uevents in the same
format mdevd-netlink writes them. So the
mdevd-netlink | mdevd command line will function as
a daemon reading uevents from the netlink and handling them.
Interface
mdevd-netlink [ -d notif ] [ -v verbosity ] [ -b kbufsz ]
- mdevd-netlink binds to the netlink interface and listens for
hotplug events, as the udevd program does.
- It writes event information to its stdout. The output contains
null characters, so a terminal will not display them correctly. To
properly use mdevd-netlink, it should be piped into a handler
program such as mdevd.
- mdevd-netlink is a long-lived program.
When it receives a SIGTERM, it stops listening to hotplug events;
it will exit as soon as it has flushed its event queue to stdout.
Options
- -d notif : when ready (actually
listening to the netlink), write a newline to file descriptor notif
then close it. This allows mdevd-netlink to use the
s6 mechanism to
notify readiness. notif cannot be lesser than 3. If this
option is not given, no readiness notification is sent.
- -v verbosity : be more or less verbose.
Default verbosity is 1. 0 will only print fatal error messages, 3 will
print warnings every time the netlink interface sends something
unexpected.
- -b kbufsz : try and reserve a kernel buffer of
kbufsz bytes for the netlink queue. Too large a buffer wastes kernel memory;
too small a buffer risks losing events. The default is 65536 (which is on
the large side).
Protocol
Notes
- mdevd-netlink is a daemon; it should be run under a proper supervision system such
as s6.
- If you are running mdevd-netlink, the program you pipe its
output into should be the only program handling uevents; that means
that /proc/sys/kernel/hotplug should be empty.
- The mdevd-netlink | mdevd command line is a quick
way of running a uevent manager, but there are ways to improve it:
- Using the
execline scripting
language, the pipeline { mdevd-netlink } mdevd command
line will avoid leaving a shell around.
- The best way to use mdevd-netlink and mdevd is with a
supervision system:
under s6 or
s6-rc, write a service
pipeline where mdevd-netlink is a producer and
mdevd is a consumer. This setup has the advantage, among
others, that you can restart the netlink listener and the event handler
separately.