# skarnet/mdevd architecture

> Architecture diagram of the GitHub repository skarnet/mdevd, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/skarnet/mdevd
- Repository: https://github.com/skarnet/mdevd

## Overview

##### Project type and purpose
- mdevd is a system‐level daemon (written in C) that listens on the Linux kernel netlink socket for hotplug (uevent) notifications and handles them according to mdev-style rules.
- It replaces BusyBox’s per-event‐forking mdev with a single long‐running process that parses a static configuration file and dispatches actions.

##### File structure
- Top-level:
- src/mdevd – core C sources: netlink setup, uevent reader, parser, internal headers, coldplug mode
- tools/ – build & release scripts (configure template, dependency generators, test runner)
- examples/ – sample s6-rc service definitions showing integration with runit-like supervisors
- doc/ – HTML documentation and upgrade guide
- package/ – distribution packaging snippets
- configure, Makefile, autoconf scripts – build system
- Key architectural hints:
- Separation between event ingestion (netlink init, uevent read/getvar) and event handling (parser + action executor)
- Two “executables” built: mdevd (main daemon) and mdevd-coldplug (batch‐mode for existing devices at boot)
- No client API or UI; single process with internal modules

##### README for additional insights
- Confirms that mdevd:
- Listens to the kernel’s netlink interface instead of being invoked per event
- Uses the same config format as mdev (mdev.conf)
- Provides both “coldplug” startup sweep and “hotplug” continuous listener

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Core Daemon Pipeline
    subgraph "mdevd Daemon"
        direction TB
        NL["Netlink Listener<br/>(mdevd_netlink_init.c)"]:::module
        UR["Uevent Reader<br/>(mdevd_uevent_read.c)"]:::module
        VE["Variable Extraction Module<br/>(mdevd_uevent_getvar.c)"]:::module
        Rules["Rule definitions<br/>(PARSING.txt)"]:::config
        PR["Parser/Matcher<br/>(mdevd.c)"]:::module
        AE["Action Executor<br/>(mdevd.c)"]:::module
        CP["Coldplug Module<br/>(mdevd-coldplug.c)"]:::module
    end

    %% External Sources
    Kernel["Kernel Netlink Socket"]:::kernel
    Sysfs["Sysfs Scan"]:::kernel
    ConfigFile["mdev.conf"]:::config
    Scripts["External Actions/Scripts"]:::external

    %% Supporting Files
    subgraph "Supporting Files"
        direction TB
        Tools["Build & Release Scripts<br/>(tools/)"]:::support
        Docs["Documentation<br/>(doc/)"]:::support
        Examples["Examples<br/>(examples/)"]:::support
        Package["Packaging Snippets<br/>(package/)"]:::support
    end

    %% Data Flows
    Kernel --> NL --> UR --> VE --> Rules --> PR --> AE --> Scripts
    ConfigFile --> PR
    Sysfs --> CP --> UR

    %% Click Events
    click NL "https://github.com/skarnet/mdevd/blob/main/src/mdevd/mdevd_netlink_init.c"
    click UR "https://github.com/skarnet/mdevd/blob/main/src/mdevd/mdevd_uevent_read.c"
    click VE "https://github.com/skarnet/mdevd/blob/main/src/mdevd/mdevd_uevent_getvar.c"
    click Rules "https://github.com/skarnet/mdevd/blob/main/src/mdevd/PARSING.txt"
    click PR "https://github.com/skarnet/mdevd/blob/main/src/mdevd/mdevd.c"
    click AE "https://github.com/skarnet/mdevd/blob/main/src/mdevd/mdevd.c"
    click CP "https://github.com/skarnet/mdevd/blob/main/src/mdevd/mdevd-coldplug.c"
    click Tools "https://github.com/skarnet/mdevd/tree/main/tools/"
    click Docs "https://github.com/skarnet/mdevd/blob/main/doc/index.html"
    click Examples "https://github.com/skarnet/mdevd/tree/main/examples/s6-rc/"
    click Package "https://github.com/skarnet/mdevd/tree/main/package/"

    %% Styles
    classDef kernel fill:#d3d3d3,stroke:#333,stroke-width:1px;
    classDef module fill:#aed6f1,stroke:#1f78b4,stroke-width:1px;
    classDef config fill:#a9dfbf,stroke:#27ae60,stroke-width:1px;
    classDef external fill:#f9e79f,stroke:#b7950b,stroke-width:1px;
    classDef support fill:#e8daef,stroke:#8e44ad,stroke-width:1px;
```
