mdevd
Software
skarnet.org
The mdevd program
mdevd is a uevent manager. It connects to the netlink and reads
a series of uevents; for every uevent it reads, it performs
actions according to its configuration file. Actions can
be inserting a kernel module, creating or modifying device
entries in /dev, etc.
mdevd's configuration file uses the exact same
format as
mdev.
The differences between mdevd and mdev are:
- mdev needs to be registered as a hotplug manager and the
kernel spawns an instance of mdev per uevent; for every uevent,
mdev has to parse its configuration file. By contrast, mdevd is
a daemon: it's long-lived, and there is only one instance,
reading a series of uevents and
performing actions without forking; the configuration file is
read and parsed only once.
Interface
mdevd [ -v verbosity ] [ -D notif ] [ -b kbufsz ] [ -f conffile ] [ -n ] [ -s slashsys ] [ -d slashdev ] [ -F fwbase ]
- mdevd reads and parses its configuration file /etc/mdev.conf.
- It then connects to the netlink and reads from it, waiting for uevents.
- It exits 0 on a SIGTERM.
Exit codes
- 0: SIGTERM received, clean exit
- 1: received an invalid event
- 2: syntax error in the configuration file
- 100: wrong usage
- 111: system call failed
Signals
mdevd reacts to the following signals:
- SIGHUP: re-read the configuration file
- SIGTERM: exit as soon as possible
Options
- -v verbosity : be more or less verbose.
Default verbosity is 1. 0 will only print fatal error messages, 3 or more
is seriously verbose debugging.
- -D notif : when ready
(actually listening to the netlink),
write a newline to file descriptor notif then close it.
This allows mdevd 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.
- -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 196608
(192 kB, which is on the large side for average systems).
- -n : dry run. mdevd will not create or delete
device nodes, and it will not spawn commands. Instead, it will print to stdout
the actions it would have performed.
- -f conffile : read the configuration
file from conffile. Default is /etc/mdev.conf.
conffile must be an absolute path.
- -s slashsys : assume the sysfs
pseudo-filesystem is mounted on slashsys. Default is /sys.
slashsys must be an absolute path.
- -d slashdev : assume the device nodes
are to be found in slashdev. Default is /dev.
slashdev must be an absolute path.
- -F fwbase : assume the firmware files, if any,
are to be found in fwbase. Default is /lib/firmware.
fwbase must be an absolute path.
Configuration file
mdevd uses mdev's configuration file format.
A good mdev.conf example is available
here.
If mdevd cannot find its configuration file, it will use a simple, basic default
configuration where it can create device nodes as root or delete them, and does
nothing else.
Notes
- The examples/ subdirectory of the mdevd package contains
examples on how to run mdevd under various init systems / supervisors. These
examples do not show how to run mdevd as a logged service, because mdevd
should normally be run early in the system's boot up sequence, before
mounting the disks - so the presence of a mounted partition suitable for
logging is not guaranteed. In normal use, mdevd is quite terse, so it
runs smoothly without a dedicated logger, with its error messages
going to the catch-all logger.