|
|
984f77 |
From 07829c10b8dfff3c6d0bb8d30e77b9b3193b1f0f Mon Sep 17 00:00:00 2001
|
|
|
984f77 |
From: Anita Zhang <the.anitazha@gmail.com>
|
|
|
984f77 |
Date: Mon, 4 Nov 2019 18:29:55 -0800
|
|
|
984f77 |
Subject: [PATCH] core: change top-level drop-in from -.service.d to service.d
|
|
|
984f77 |
|
|
|
984f77 |
Discussed in #13743, the -.service semantic conflicts with the
|
|
|
984f77 |
existing root mount and slice names, making this feature not
|
|
|
984f77 |
uniformly extensible to all types. Change the name to be
|
|
|
984f77 |
<type>.d instead.
|
|
|
984f77 |
|
|
|
984f77 |
Updating to this format also extends the top-level dropin to
|
|
|
984f77 |
unit types.
|
|
|
984f77 |
|
|
|
984f77 |
(cherry picked from commit 3e1db806b0c18fd6138886ce67fac2655f09caef)
|
|
|
984f77 |
|
|
|
984f77 |
Resolves: #2051520
|
|
|
984f77 |
---
|
|
|
984f77 |
man/systemd.service.xml | 13 -------------
|
|
|
984f77 |
man/systemd.special.xml | 9 ---------
|
|
|
984f77 |
man/systemd.unit.xml | 11 ++++++++---
|
|
|
984f77 |
src/basic/special.h | 4 ----
|
|
|
984f77 |
src/basic/unit-name.c | 30 ------------------------------
|
|
|
984f77 |
src/basic/unit-name.h | 2 --
|
|
|
984f77 |
src/core/service.c | 5 -----
|
|
|
984f77 |
src/shared/dropin.c | 22 ++++++++++++----------
|
|
|
984f77 |
src/test/test-unit-name.c | 19 -------------------
|
|
|
984f77 |
test/TEST-15-DROPIN/test-dropin.sh | 8 ++++----
|
|
|
984f77 |
10 files changed, 24 insertions(+), 99 deletions(-)
|
|
|
984f77 |
|
|
|
984f77 |
diff --git a/man/systemd.service.xml b/man/systemd.service.xml
|
|
|
984f77 |
index 4164402d0e..1e30a564df 100644
|
|
|
984f77 |
--- a/man/systemd.service.xml
|
|
|
984f77 |
+++ b/man/systemd.service.xml
|
|
|
984f77 |
@@ -62,19 +62,6 @@
|
|
|
984f77 |
about the incompatibilities, see the
|
|
|
984f77 |
url="https://www.freedesktop.org/wiki/Software/systemd/Incompatibilities">Incompatibilities
|
|
|
984f77 |
with SysV</ulink> document.</para>
|
|
|
984f77 |
-
|
|
|
984f77 |
- <para>In addition to the various drop-in behaviors described in
|
|
|
984f77 |
- <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
|
|
|
984f77 |
- services also support a top-level drop-in with <filename>-.service.d/</filename> that allows
|
|
|
984f77 |
- altering or adding to the settings of all services on the system.
|
|
|
984f77 |
- The formatting and precedence of applying drop-in configurations follow what is defined in
|
|
|
984f77 |
- <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
|
|
|
984f77 |
- However, configurations in <filename>-.service.d/</filename> have the lowest precedence compared to settings
|
|
|
984f77 |
- in the service specific override directories. For example, for <filename>foo-bar-baz.service</filename>,
|
|
|
984f77 |
- drop-ins in <filename>foo-bar-baz.service.d/</filename> override the ones in
|
|
|
984f77 |
- <filename>foo-bar-.service.d/</filename>, which override the ones <filename>foo-.service.d/</filename>,
|
|
|
984f77 |
- which override the ones in <filename>-.service.d/</filename>.
|
|
|
984f77 |
- </para>
|
|
|
984f77 |
</refsect1>
|
|
|
984f77 |
|
|
|
984f77 |
<refsect1>
|
|
|
984f77 |
diff --git a/man/systemd.special.xml b/man/systemd.special.xml
|
|
|
984f77 |
index 06798cd9e2..fe6324a4a0 100644
|
|
|
984f77 |
--- a/man/systemd.special.xml
|
|
|
984f77 |
+++ b/man/systemd.special.xml
|
|
|
984f77 |
@@ -117,15 +117,6 @@
|
|
|
984f77 |
</listitem>
|
|
|
984f77 |
</varlistentry>
|
|
|
984f77 |
|
|
|
984f77 |
- <varlistentry>
|
|
|
984f77 |
- <term><filename>-.service</filename></term>
|
|
|
984f77 |
- <listitem>
|
|
|
984f77 |
- <para>This is a reserved unit name used to support top-level drop-ins for services. See
|
|
|
984f77 |
- <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
|
|
|
984f77 |
- for details.</para>
|
|
|
984f77 |
- </listitem>
|
|
|
984f77 |
- </varlistentry>
|
|
|
984f77 |
-
|
|
|
984f77 |
<varlistentry>
|
|
|
984f77 |
<term><filename>basic.target</filename></term>
|
|
|
984f77 |
<listitem>
|
|
|
984f77 |
diff --git a/man/systemd.unit.xml b/man/systemd.unit.xml
|
|
|
984f77 |
index 5aa3bd1699..6f213ccd56 100644
|
|
|
984f77 |
--- a/man/systemd.unit.xml
|
|
|
984f77 |
+++ b/man/systemd.unit.xml
|
|
|
984f77 |
@@ -190,9 +190,14 @@
|
|
|
984f77 |
over unit files wherever located. Multiple drop-in files with different names are applied in
|
|
|
984f77 |
lexicographic order, regardless of which of the directories they reside in.</para>
|
|
|
984f77 |
|
|
|
984f77 |
- <para>Service units also support a top-level drop-in directory for modifying the settings of all service units. See
|
|
|
984f77 |
- <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
|
|
|
984f77 |
- for details.</para>
|
|
|
984f77 |
+ <para>Units also support a top-level drop-in with <filename><replaceable>type</replaceable>.d/</filename>,
|
|
|
984f77 |
+ where <replaceable>type</replaceable> may be e.g. <literal>service</literal> or <literal>socket</literal>,
|
|
|
984f77 |
+ that allows altering or adding to the settings of all corresponding unit files on the system.
|
|
|
984f77 |
+ The formatting and precedence of applying drop-in configurations follow what is defined above.
|
|
|
984f77 |
+ Configurations in <filename><replaceable>type</replaceable>.d/</filename> have the lowest precedence
|
|
|
984f77 |
+ compared to settings in the name specific override directories. So the contents of
|
|
|
984f77 |
+ <filename>foo-.service.d/10-override.conf</filename> would override
|
|
|
984f77 |
+ <filename>service.d/10-override.conf</filename>.</para>
|
|
|
984f77 |
|
|
|
984f77 |
|
|
|
984f77 |
people to use .d/ drop-ins instead. -->
|
|
|
984f77 |
diff --git a/src/basic/special.h b/src/basic/special.h
|
|
|
984f77 |
index 2915122929..379a3d7979 100644
|
|
|
984f77 |
--- a/src/basic/special.h
|
|
|
984f77 |
+++ b/src/basic/special.h
|
|
|
984f77 |
@@ -103,7 +103,3 @@
|
|
|
984f77 |
|
|
|
984f77 |
/* The root directory. */
|
|
|
984f77 |
#define SPECIAL_ROOT_MOUNT "-.mount"
|
|
|
984f77 |
-
|
|
|
984f77 |
-/* Used to apply settings to all services through drop-ins.
|
|
|
984f77 |
- * Should not exist as an actual service. */
|
|
|
984f77 |
-#define SPECIAL_ROOT_SERVICE "-.service"
|
|
|
984f77 |
diff --git a/src/basic/unit-name.c b/src/basic/unit-name.c
|
|
|
984f77 |
index 078628d6e8..614eb8649b 100644
|
|
|
984f77 |
--- a/src/basic/unit-name.c
|
|
|
984f77 |
+++ b/src/basic/unit-name.c
|
|
|
984f77 |
@@ -668,36 +668,6 @@ good:
|
|
|
984f77 |
return 0;
|
|
|
984f77 |
}
|
|
|
984f77 |
|
|
|
984f77 |
-bool service_unit_name_is_valid(const char *name) {
|
|
|
984f77 |
- _cleanup_free_ char *prefix = NULL, *s = NULL;
|
|
|
984f77 |
- const char *e, *service_name = name;
|
|
|
984f77 |
-
|
|
|
984f77 |
- if (!unit_name_is_valid(name, UNIT_NAME_ANY))
|
|
|
984f77 |
- return false;
|
|
|
984f77 |
-
|
|
|
984f77 |
- e = endswith(name, ".service");
|
|
|
984f77 |
- if (!e)
|
|
|
984f77 |
- return false;
|
|
|
984f77 |
-
|
|
|
984f77 |
- /* If it's a template or instance, get the prefix as a service name. */
|
|
|
984f77 |
- if (unit_name_is_valid(name, UNIT_NAME_INSTANCE|UNIT_NAME_TEMPLATE)) {
|
|
|
984f77 |
- if (unit_name_to_prefix(name, &prefix) < 0)
|
|
|
984f77 |
- return false;
|
|
|
984f77 |
-
|
|
|
984f77 |
- s = strjoin(prefix, ".service");
|
|
|
984f77 |
- if (!s)
|
|
|
984f77 |
- return false;
|
|
|
984f77 |
-
|
|
|
984f77 |
- service_name = s;
|
|
|
984f77 |
- }
|
|
|
984f77 |
-
|
|
|
984f77 |
- /* Reject reserved service name(s). */
|
|
|
984f77 |
- if (streq(service_name, SPECIAL_ROOT_SERVICE))
|
|
|
984f77 |
- return false;
|
|
|
984f77 |
-
|
|
|
984f77 |
- return true;
|
|
|
984f77 |
-}
|
|
|
984f77 |
-
|
|
|
984f77 |
int slice_build_parent_slice(const char *slice, char **ret) {
|
|
|
984f77 |
char *s, *dash;
|
|
|
984f77 |
int r;
|
|
|
984f77 |
diff --git a/src/basic/unit-name.h b/src/basic/unit-name.h
|
|
|
984f77 |
index 21729cba83..61abcd585b 100644
|
|
|
984f77 |
--- a/src/basic/unit-name.h
|
|
|
984f77 |
+++ b/src/basic/unit-name.h
|
|
|
984f77 |
@@ -60,8 +60,6 @@ static inline int unit_name_mangle(const char *name, UnitNameMangle flags, char
|
|
|
984f77 |
return unit_name_mangle_with_suffix(name, flags, ".service", ret);
|
|
|
984f77 |
}
|
|
|
984f77 |
|
|
|
984f77 |
-bool service_unit_name_is_valid(const char *name);
|
|
|
984f77 |
-
|
|
|
984f77 |
int slice_build_parent_slice(const char *slice, char **ret);
|
|
|
984f77 |
int slice_build_subslice(const char *slice, const char*name, char **subslice);
|
|
|
984f77 |
bool slice_name_is_valid(const char *name);
|
|
|
984f77 |
diff --git a/src/core/service.c b/src/core/service.c
|
|
|
984f77 |
index b3ef79228f..e8ae1a5772 100644
|
|
|
984f77 |
--- a/src/core/service.c
|
|
|
984f77 |
+++ b/src/core/service.c
|
|
|
984f77 |
@@ -556,11 +556,6 @@ static int service_verify(Service *s) {
|
|
|
984f77 |
}
|
|
|
984f77 |
}
|
|
|
984f77 |
|
|
|
984f77 |
- if (!service_unit_name_is_valid(UNIT(s)->id)) {
|
|
|
984f77 |
- log_unit_error(UNIT(s), "Service name is invalid or reserved. Refusing.");
|
|
|
984f77 |
- return -EINVAL;
|
|
|
984f77 |
- }
|
|
|
984f77 |
-
|
|
|
984f77 |
if (!s->exec_command[SERVICE_EXEC_START] && !s->exec_command[SERVICE_EXEC_STOP]
|
|
|
984f77 |
&& UNIT(s)->success_action == EMERGENCY_ACTION_NONE) {
|
|
|
984f77 |
/* FailureAction= only makes sense if one of the start or stop commands is specified.
|
|
|
984f77 |
diff --git a/src/shared/dropin.c b/src/shared/dropin.c
|
|
|
984f77 |
index 78ca7f4452..bd2a3c0feb 100644
|
|
|
984f77 |
--- a/src/shared/dropin.c
|
|
|
984f77 |
+++ b/src/shared/dropin.c
|
|
|
984f77 |
@@ -19,7 +19,6 @@
|
|
|
984f77 |
#include "mkdir.h"
|
|
|
984f77 |
#include "path-util.h"
|
|
|
984f77 |
#include "set.h"
|
|
|
984f77 |
-#include "special.h"
|
|
|
984f77 |
#include "string-util.h"
|
|
|
984f77 |
#include "strv.h"
|
|
|
984f77 |
#include "unit-name.h"
|
|
|
984f77 |
@@ -170,6 +169,10 @@ static int unit_file_find_dirs(
|
|
|
984f77 |
return r;
|
|
|
984f77 |
}
|
|
|
984f77 |
|
|
|
984f77 |
+ /* Return early for top level drop-ins. */
|
|
|
984f77 |
+ if (unit_type_from_string(name) >= 0)
|
|
|
984f77 |
+ return 0;
|
|
|
984f77 |
+
|
|
|
984f77 |
/* Let's see if there's a "-" prefix for this unit name. If so, let's invoke ourselves for it. This will then
|
|
|
984f77 |
* recursively do the same for all our prefixes. i.e. this means given "foo-bar-waldo.service" we'll also
|
|
|
984f77 |
* search "foo-bar-.service" and "foo-.service".
|
|
|
984f77 |
@@ -250,16 +253,15 @@ int unit_file_find_dropin_paths(
|
|
|
984f77 |
name);
|
|
|
984f77 |
}
|
|
|
984f77 |
|
|
|
984f77 |
- /* Special drop in for -.service. Add this first as it's the most generic
|
|
|
984f77 |
+ /* Special top level drop in for "<unit type>.<suffix>". Add this first as it's the most generic
|
|
|
984f77 |
* and should be able to be overridden by more specific drop-ins. */
|
|
|
984f77 |
- if (type == UNIT_SERVICE)
|
|
|
984f77 |
- STRV_FOREACH(p, lookup_path)
|
|
|
984f77 |
- (void) unit_file_find_dirs(original_root,
|
|
|
984f77 |
- unit_path_cache,
|
|
|
984f77 |
- *p,
|
|
|
984f77 |
- SPECIAL_ROOT_SERVICE,
|
|
|
984f77 |
- dir_suffix,
|
|
|
984f77 |
- &dirs);
|
|
|
984f77 |
+ STRV_FOREACH(p, lookup_path)
|
|
|
984f77 |
+ (void) unit_file_find_dirs(original_root,
|
|
|
984f77 |
+ unit_path_cache,
|
|
|
984f77 |
+ *p,
|
|
|
984f77 |
+ unit_type_to_string(type),
|
|
|
984f77 |
+ dir_suffix,
|
|
|
984f77 |
+ &dirs);
|
|
|
984f77 |
|
|
|
984f77 |
SET_FOREACH(name, names, i)
|
|
|
984f77 |
STRV_FOREACH(p, lookup_path)
|
|
|
984f77 |
diff --git a/src/test/test-unit-name.c b/src/test/test-unit-name.c
|
|
|
984f77 |
index b629df5aea..2b00ef8cb7 100644
|
|
|
984f77 |
--- a/src/test/test-unit-name.c
|
|
|
984f77 |
+++ b/src/test/test-unit-name.c
|
|
|
984f77 |
@@ -347,24 +347,6 @@ static void test_unit_name_build(void) {
|
|
|
984f77 |
free(t);
|
|
|
984f77 |
}
|
|
|
984f77 |
|
|
|
984f77 |
-static void test_service_unit_name_is_valid(void) {
|
|
|
984f77 |
- assert_se(service_unit_name_is_valid("foo.service"));
|
|
|
984f77 |
- assert_se(service_unit_name_is_valid("foo@bar.service"));
|
|
|
984f77 |
- assert_se(service_unit_name_is_valid("foo@bar@bar.service"));
|
|
|
984f77 |
- assert_se(service_unit_name_is_valid("--.service"));
|
|
|
984f77 |
- assert_se(service_unit_name_is_valid(".-.service"));
|
|
|
984f77 |
- assert_se(service_unit_name_is_valid("-foo-bar.service"));
|
|
|
984f77 |
- assert_se(service_unit_name_is_valid("-foo-bar-.service"));
|
|
|
984f77 |
- assert_se(service_unit_name_is_valid("foo-bar-.service"));
|
|
|
984f77 |
-
|
|
|
984f77 |
- assert_se(!service_unit_name_is_valid("-.service"));
|
|
|
984f77 |
- assert_se(!service_unit_name_is_valid(""));
|
|
|
984f77 |
- assert_se(!service_unit_name_is_valid("foo.slice"));
|
|
|
984f77 |
- assert_se(!service_unit_name_is_valid("@.service"));
|
|
|
984f77 |
- assert_se(!service_unit_name_is_valid("@bar.service"));
|
|
|
984f77 |
- assert_se(!service_unit_name_is_valid("-@.service"));
|
|
|
984f77 |
-}
|
|
|
984f77 |
-
|
|
|
984f77 |
static void test_slice_name_is_valid(void) {
|
|
|
984f77 |
assert_se( slice_name_is_valid(SPECIAL_ROOT_SLICE));
|
|
|
984f77 |
assert_se( slice_name_is_valid("foo.slice"));
|
|
|
984f77 |
@@ -851,7 +833,6 @@ int main(int argc, char* argv[]) {
|
|
|
984f77 |
test_unit_prefix_is_valid();
|
|
|
984f77 |
test_unit_name_change_suffix();
|
|
|
984f77 |
test_unit_name_build();
|
|
|
984f77 |
- test_service_unit_name_is_valid();
|
|
|
984f77 |
test_slice_name_is_valid();
|
|
|
984f77 |
test_build_subslice();
|
|
|
984f77 |
test_build_parent_slice();
|
|
|
984f77 |
diff --git a/test/TEST-15-DROPIN/test-dropin.sh b/test/TEST-15-DROPIN/test-dropin.sh
|
|
|
984f77 |
index def2e03304..7836c6535d 100755
|
|
|
984f77 |
--- a/test/TEST-15-DROPIN/test-dropin.sh
|
|
|
984f77 |
+++ b/test/TEST-15-DROPIN/test-dropin.sh
|
|
|
984f77 |
@@ -102,18 +102,18 @@ test_basic_dropins () {
|
|
|
984f77 |
check_ok b Wants c.service
|
|
|
984f77 |
systemctl stop a c
|
|
|
984f77 |
|
|
|
984f77 |
- echo "*** test -.service.d/ top level drop-in"
|
|
|
984f77 |
+ echo "*** test service.d/ top level drop-in"
|
|
|
984f77 |
create_services a b
|
|
|
984f77 |
check_ko a ExecCondition "/bin/echo a"
|
|
|
984f77 |
check_ko b ExecCondition "/bin/echo b"
|
|
|
984f77 |
- mkdir -p /usr/lib/systemd/system/-.service.d
|
|
|
984f77 |
- cat >/usr/lib/systemd/system/-.service.d/override.conf <
|
|
|
984f77 |
+ mkdir -p /usr/lib/systemd/system/service.d
|
|
|
984f77 |
+ cat >/usr/lib/systemd/system/service.d/override.conf <
|
|
|
984f77 |
[Service]
|
|
|
984f77 |
ExecCondition=/bin/echo %n
|
|
|
984f77 |
EOF
|
|
|
984f77 |
check_ok a ExecCondition "/bin/echo a"
|
|
|
984f77 |
check_ok b ExecCondition "/bin/echo b"
|
|
|
984f77 |
- rm -rf /usr/lib/systemd/system/-.service.d
|
|
|
984f77 |
+ rm -rf /usr/lib/systemd/system/service.d
|
|
|
984f77 |
|
|
|
984f77 |
clear_services a b c
|
|
|
984f77 |
}
|