diff --git a/TODO b/TODO index 057782f381..a7672f18cb 100644 --- a/TODO +++ b/TODO @@ -27,8 +27,6 @@ Features: * systemd-run should have a way how to connect a pair of pipes to stdout/stderr/stdin of the invoked service -* StateDirectory= and friends should imply RequiresMountsFor= - * set LockPersonality= on all our services * Add AddUser= setting to unit files, similar to DynamicUser=1 which however diff --git a/man/systemd-random-seed.service.xml b/man/systemd-random-seed.service.xml index f3b5a947da..9ec01b6c34 100644 --- a/man/systemd-random-seed.service.xml +++ b/man/systemd-random-seed.service.xml @@ -48,7 +48,7 @@ systemd-random-seed.service - /usr/lib/systemd/systemd-random-seed + /usr/lib/systemd/random-seed diff --git a/man/systemd.exec.xml b/man/systemd.exec.xml index a9f1d8d74e..7a9fe83b28 100644 --- a/man/systemd.exec.xml +++ b/man/systemd.exec.xml @@ -86,10 +86,11 @@ A few execution parameters result in additional, automatic dependencies to be added. - Units with WorkingDirectory=, RootDirectory= or - RootImage= set automatically gain dependencies of type Requires= and - After= on all mount units required to access the specified paths. This is equivalent to having - them listed explicitly in RequiresMountsFor=. + Units with WorkingDirectory=, RootDirectory=, RootImage=, + RuntimeDirectory=, StateDirectory=, CacheDirectory=, + LogsDirectory= or ConfigurationDirectory= set automatically gain dependencies + of type Requires= and After= on all mount units required to access the specified paths. + This is equivalent to having them listed explicitly in RequiresMountsFor=. Similar, units with PrivateTmp= enabled automatically get mount unit dependencies for all mounts required to access /tmp and /var/tmp. They will also gain an diff --git a/src/core/unit.c b/src/core/unit.c index c6d96c69dc..2037de6d33 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -846,6 +846,8 @@ Unit* unit_follow_merge(Unit *u) { } int unit_add_exec_dependencies(Unit *u, ExecContext *c) { + ExecDirectoryType dt; + char **dp; int r; assert(u); @@ -869,6 +871,23 @@ int unit_add_exec_dependencies(Unit *u, ExecContext *c) { return r; } + for (dt = 0; dt < _EXEC_DIRECTORY_MAX; dt++) { + if (!u->manager->prefix[dt]) + continue; + + STRV_FOREACH(dp, c->directories[dt].paths) { + _cleanup_free_ char *p; + + p = strjoin(u->manager->prefix[dt], "/", *dp); + if (!p) + return -ENOMEM; + + r = unit_require_mounts_for(u, p); + if (r < 0) + return r; + } + } + if (!MANAGER_IS_SYSTEM(u->manager)) return 0; diff --git a/units/systemd-backlight@.service.in b/units/systemd-backlight@.service.in index 5e6706c11c..9aa0c7498d 100644 --- a/units/systemd-backlight@.service.in +++ b/units/systemd-backlight@.service.in @@ -9,7 +9,6 @@ Description=Load/Save Screen Backlight Brightness of %i Documentation=man:systemd-backlight@.service(8) DefaultDependencies=no -RequiresMountsFor=/var/lib/systemd/backlight Conflicts=shutdown.target After=systemd-remount-fs.service Before=sysinit.target shutdown.target @@ -20,3 +19,4 @@ RemainAfterExit=yes ExecStart=@rootlibexecdir@/systemd-backlight load %i ExecStop=@rootlibexecdir@/systemd-backlight save %i TimeoutSec=90s +StateDirectory=systemd/backlight diff --git a/units/systemd-coredump@.service.in b/units/systemd-coredump@.service.in index f6044a4d3f..c699a80f34 100644 --- a/units/systemd-coredump@.service.in +++ b/units/systemd-coredump@.service.in @@ -9,7 +9,6 @@ Description=Process Core Dump Documentation=man:systemd-coredump(8) DefaultDependencies=no -RequiresMountsFor=/var/lib/systemd/coredump Conflicts=shutdown.target After=systemd-remount-fs.service systemd-journald.socket Requires=systemd-journald.socket diff --git a/units/systemd-rfkill.service.in b/units/systemd-rfkill.service.in index 780a19b996..5cdd747d22 100644 --- a/units/systemd-rfkill.service.in +++ b/units/systemd-rfkill.service.in @@ -9,7 +9,6 @@ Description=Load/Save RF Kill Switch Status Documentation=man:systemd-rfkill.service(8) DefaultDependencies=no -RequiresMountsFor=/var/lib/systemd/rfkill BindsTo=sys-devices-virtual-misc-rfkill.device Conflicts=shutdown.target After=sys-devices-virtual-misc-rfkill.device systemd-remount-fs.service @@ -19,3 +18,4 @@ Before=shutdown.target Type=notify ExecStart=@rootlibexecdir@/systemd-rfkill TimeoutSec=30s +StateDirectory=systemd/rfkill diff --git a/units/systemd-timesyncd.service.in b/units/systemd-timesyncd.service.in index 14557a5661..a6e14d24d1 100644 --- a/units/systemd-timesyncd.service.in +++ b/units/systemd-timesyncd.service.in @@ -11,7 +11,6 @@ Documentation=man:systemd-timesyncd.service(8) ConditionCapability=CAP_SYS_TIME ConditionVirtualization=!container DefaultDependencies=no -RequiresMountsFor=/var/lib/systemd/timesync/clock After=systemd-remount-fs.service systemd-sysusers.service Before=time-sync.target sysinit.target shutdown.target Conflicts=shutdown.target