Skip to content

libsystemd: load the configuration directory of a mount point by itself (follow-up to #9) - #10

Merged
JohnAmadis merged 1 commit into
mainfrom
feat/load-mount-cfg-by-libsystemd
Oct 26, 2026
Merged

JohnAmadis merged 1 commit into
mainfrom
feat/load-mount-cfg-by-libsystemd

Conversation

@JaxCalder

Copy link
Copy Markdown
Contributor

What

Follow-up to #9, which was merged before its last commit: the version on main still has the mount class and the remove key but not the loading of a mount point's configuration directory.

libsystemd hears every mount and unmount (dmfsi's _mount_changed dif) and now loads <mount point>/cfg/services and cfg/rules by itself - no API for anyone to call (the libsystemd_add_config_dir() / remove_config_dir() of an earlier revision were dropped on purpose):

  • Mounted: the units, templates and rules are added to what libsystemd_scan() / libsystemd_load_rules() loaded (nothing is reloaded or restarted) and the units start in their dependency order. A unit or template whose name is taken stays the first one. %m = the mount point the unit comes from (exec=%m/bin/app.dmfc), so it stays bound to its own card.
  • About to be unmounted: the remove units of the rules run (waited for), then everything that came from there stops and is dropped, template instances included. The unmount waits for all of it, so the units stop while their files are still there.
  • A full reload keeps the loaded directories; the units directory of libsystemd_scan() is never loaded twice; a mount point without cfg/ is left alone.
  • Dmod_InvalidateModuleSearchPaths() first: /mnt/<label>/bin is on the (cached) module search path and automount only invalidates it after the mount returned - without it the module of a card's unit is not found.

Stack

The dif is called in the thread that mounts - automount's. Loading a directory and starting a unit from a card there peaked at 2596 bytes of its stack on the board; automount needs 4 kB (choco-technologies/dmblock#6). Documented in configuration.md.

Testing

  • Host: test_libsystemd 73/73 (6 new: a mount adds, starts and an unmount removes the units of cfg/services; a unit of two mount points stays the first one; the rules and templates of a mount point; survival of a full reload; the scanned units directory is not loaded twice; a mount without cfg/ changes nothing), test_systemd / test_service 1/1. The host loader needs Dmod_InvalidateModuleSearchPaths (dmod develop).
  • STM32F746G-DISCO (/configs -> /cfg; configuration goes where the module goes (per-mount cfg/, devscan) dmod-boot#148): after a cold boot the card is mounted and carhmi starts from <card>/cfg/services/carhmi/carhmi.ini by itself; a probe unit in /ext/cfg/services: umount /ext + mount loads it (fresh instance each cycle, %m = /ext, exactly one).

🤖 Generated with Claude Code

libsystemd already hears every mount and unmount (dmfsi's _mount_changed dif), so
the loading of <mount point>/cfg/services and cfg/rules is its own business again,
not an API for a service to call: on a mount it adds the units, templates and rules
to what is loaded and starts the units (dependency order, first definition of a
name stays, %m = the mount point), on an unmount it runs the rules' `remove` units,
then stops and drops exactly what came from there. A full reload keeps them; the
units directory of libsystemd_scan() is never loaded twice.

The module search path is invalidated before the units start: the new file system
may hold their modules (/mnt/<label>/bin), and automount only gets to it after the
mount returned.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@JohnAmadis
JohnAmadis merged commit 5918466 into main Oct 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants