1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-24 21:34:08 +03:00

core: implicitly order units with PrivateTmp= after systemd-tmpfiles-setup.service

Preparation for fixing #4401.
This commit is contained in:
Lennart Poettering 2016-12-27 23:25:24 +01:00
parent 27e2e3231f
commit d71f050599
3 changed files with 18 additions and 10 deletions

View File

@ -93,10 +93,10 @@
the specified paths. This is equivalent to having them listed the specified paths. This is equivalent to having them listed
explicitly in <varname>RequiresMountsFor=</varname>.</para> explicitly in <varname>RequiresMountsFor=</varname>.</para>
<para>Similar, units with <varname>PrivateTmp=</varname> enabled <para>Similar, units with <varname>PrivateTmp=</varname> enabled automatically get mount unit dependencies for all
automatically get mount unit dependencies for all mounts mounts required to access <filename>/tmp</filename> and <filename>/var/tmp</filename>. They will also gain an
required to access <filename>/tmp</filename> and automatic <varname>After=</varname> dependency on
<filename>/var/tmp</filename>.</para> <citerefentry><refentrytitle>systemd-tmpfiles-setup.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.</para>
<para>Units whose standard output or error output is connected to <option>journal</option>, <option>syslog</option> <para>Units whose standard output or error output is connected to <option>journal</option>, <option>syslog</option>
or <option>kmsg</option> (or their combinations with console output, see below) automatically acquire dependencies or <option>kmsg</option> (or their combinations with console output, see below) automatically acquire dependencies
@ -1006,8 +1006,11 @@
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry> for <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
details. This setting is implied if <varname>DynamicUser=</varname> is set. For this setting the same details. This setting is implied if <varname>DynamicUser=</varname> is set. For this setting the same
restrictions regarding mount propagation and privileges apply as for <varname>ReadOnlyPaths=</varname> and restrictions regarding mount propagation and privileges apply as for <varname>ReadOnlyPaths=</varname> and
related calls, see above.</para></listitem> related calls, see above. Enabling this setting has the side effect of adding <varname>Requires=</varname> and
<varname>After=</varname> dependencies on all mount units necessary to access <filename>/tmp</filename> and
<filename>/var/tmp</filename>. Moreover an implicitly <varname>After=</varname> ordering on
<citerefentry><refentrytitle>systemd-tmpfiles-setup.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
is added.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>

View File

@ -103,6 +103,7 @@
#define SPECIAL_DBUS_SOCKET "dbus.socket" #define SPECIAL_DBUS_SOCKET "dbus.socket"
#define SPECIAL_JOURNALD_SOCKET "systemd-journald.socket" #define SPECIAL_JOURNALD_SOCKET "systemd-journald.socket"
#define SPECIAL_JOURNALD_SERVICE "systemd-journald.service" #define SPECIAL_JOURNALD_SERVICE "systemd-journald.service"
#define SPECIAL_TMPFILES_SETUP_SERVICE "systemd-tmpfiles-setup.service"
/* Magic init signals */ /* Magic init signals */
#define SPECIAL_KBREQUEST_TARGET "kbrequest.target" #define SPECIAL_KBREQUEST_TARGET "kbrequest.target"

View File

@ -866,11 +866,15 @@ int unit_add_exec_dependencies(Unit *u, ExecContext *c) {
return 0; return 0;
if (c->private_tmp) { if (c->private_tmp) {
r = unit_require_mounts_for(u, "/tmp"); const char *p;
if (r < 0)
return r;
r = unit_require_mounts_for(u, "/var/tmp"); FOREACH_STRING(p, "/tmp", "/var/tmp") {
r = unit_require_mounts_for(u, p);
if (r < 0)
return r;
}
r = unit_add_dependency_by_name(u, UNIT_AFTER, SPECIAL_TMPFILES_SETUP_SERVICE, NULL, true);
if (r < 0) if (r < 0)
return r; return r;
} }