From ada5e27657ca3e901022ae06edd350130a62a0a2 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 31 Aug 2017 18:19:35 +0900 Subject: [PATCH 1/5] core: StateDirectory= and friends imply RequiresMountsFor= --- man/systemd.exec.xml | 9 +++++---- src/core/unit.c | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) 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; From 96f9f6aca759f8bbad29c111f2bf4c902b527380 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 31 Aug 2017 18:29:41 +0900 Subject: [PATCH 2/5] unit: drop redundant options --- units/systemd-coredump@.service.in | 1 - units/systemd-timesyncd.service.in | 1 - 2 files changed, 2 deletions(-) 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-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 From 181b4f56e7b5b201311e0056e99d0d1312f6fcc1 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 31 Aug 2017 18:37:11 +0900 Subject: [PATCH 3/5] unit: use StateDirectory= instead of RequiresMountsFor= --- units/systemd-backlight@.service.in | 2 +- units/systemd-rfkill.service.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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-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 From d7bdedae873b0ca84c7a4083b7312a268a17be93 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 31 Aug 2017 18:37:22 +0900 Subject: [PATCH 4/5] TODO: update --- TODO | 2 -- 1 file changed, 2 deletions(-) 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 From 621a2c804ce91763221799cde9d412423fcf8b51 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 31 Aug 2017 18:31:08 +0900 Subject: [PATCH 5/5] man: fix path for storing random seed --- man/systemd-random-seed.service.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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