Merge pull request #6709 from yuwata/imply-requires-mounts

core: StateDirectory= and friends imply RequiresMountsFor=
This commit is contained in:
Lennart Poettering 2017-08-31 13:30:26 +02:00 committed by GitHub
commit d7542c46d6
8 changed files with 27 additions and 11 deletions

2
TODO
View File

@ -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

View File

@ -48,7 +48,7 @@
<refsynopsisdiv>
<para><filename>systemd-random-seed.service</filename></para>
<para><filename>/usr/lib/systemd/systemd-random-seed</filename></para>
<para><filename>/usr/lib/systemd/random-seed</filename></para>
</refsynopsisdiv>
<refsect1>

View File

@ -86,10 +86,11 @@
<para>A few execution parameters result in additional, automatic
dependencies to be added.</para>
<para>Units with <varname>WorkingDirectory=</varname>, <varname>RootDirectory=</varname> or
<varname>RootImage=</varname> set automatically gain dependencies of type <varname>Requires=</varname> and
<varname>After=</varname> on all mount units required to access the specified paths. This is equivalent to having
them listed explicitly in <varname>RequiresMountsFor=</varname>.</para>
<para>Units with <varname>WorkingDirectory=</varname>, <varname>RootDirectory=</varname>, <varname>RootImage=</varname>,
<varname>RuntimeDirectory=</varname>, <varname>StateDirectory=</varname>, <varname>CacheDirectory=</varname>,
<varname>LogsDirectory=</varname> or <varname>ConfigurationDirectory=</varname> set automatically gain dependencies
of type <varname>Requires=</varname> and <varname>After=</varname> on all mount units required to access the specified paths.
This is equivalent to having them listed explicitly in <varname>RequiresMountsFor=</varname>.</para>
<para>Similar, units with <varname>PrivateTmp=</varname> enabled automatically get mount unit dependencies for all
mounts required to access <filename>/tmp</filename> and <filename>/var/tmp</filename>. They will also gain an

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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