User-Space Helpers
There are cases where it makes sense for the kernel to invoke a user-space application to handle events. Two such helpers are particularly important:
- /sbin/modprobe
Invoked when the kernel needs to load a module. This helper is part of the module-init-tools package.
- /sbin/hotplug
Invoked when the kernel detects that a new device has been plugged or unplugged from the system. Its main job is to load the correct device driver (module) based on the device identifier. Devices are identified by the bus they are plugged into (e.g., PCI) and the associated ID defined by the bus specification.[†] This helper is part of the hotplug package.
The kernel provides a function named call_usermodehelper to execute such user-space helpers. The function allows the
caller to pass the application a variable number of both arguments in arg[] and environment variables in env[]. For example, the first argument arg[0] tells call_usermodehelper what
user-space helper to launch, and arg[1] can be used to
tell the helper itself what configuration script to use (often called the user-space
agent). We will see an example in the later section "/sbin/hotplug."
Figure 5-3 shows how two kernel
routines, request_module and kobject_hotplug, invoke call_usermodehelper to invoke /sbin/modprobe and /sbin/hotplug,
respectively. It also shows examples of how arg[] and
envp[] are initialized in the two cases. The following subsections go into a little more detail on each of those two user-space helpers. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access