diff --git a/man/systemd.exec.xml b/man/systemd.exec.xml
index a9f1d8d74e1..7a9fe83b28c 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 c6d96c69dc2..2037de6d332 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;