summaryrefslogtreecommitdiff
path: root/src/basic/unit-file.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-02-14 14:38:32 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-02-14 14:49:00 +0100
commit3aa57658434e7a95c6000bebb166c31f1c6d051b (patch)
tree7d96e54044cd2c85a4800ac591c2007d530a330b /src/basic/unit-file.c
parent8db704b28b4fd4d13e376cf3495005010443937e (diff)
downloadsystemd-3aa57658434e7a95c6000bebb166c31f1c6d051b.tar.gz
basic/unit-file: when loading linked unit files, use link source as "fragment path"
The general idea is that when a unit file is "linked" (i.e. installed by symlinking from outside of the search paths), the *destination* name is irrelevant. It doesn't even have to be a valid unit name, or to match the type or instance value. The obvious collorary is that we shouldn't look at the symlink destination name to derive the unit name, instance value, or anything else at all. When building the name map, when we find a linked unit (possibly at the end of a series of alias redirects), store the *source* of the final symlink as the fragment path. This has two effects: - we stop looking at the *target* file name to derive unit info, i.e. actually implement the stuff described in the first paragraph. - we load the unit fragment through the symlink. If someone were to remove the symlink, we'll not load the unit. This seems like the right thing. Fixes #18058. Before this change, we were generally quite confused about unit alises for linked units. Fortunately most poeple use the same symlink source and target, so in practice we wouldn't hit this too often. In unit_load_fragment() a comment is added to explain what we're doing there.
Diffstat (limited to 'src/basic/unit-file.c')
-rw-r--r--src/basic/unit-file.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/basic/unit-file.c b/src/basic/unit-file.c
index 3383d1afad..236fc64a8f 100644
--- a/src/basic/unit-file.c
+++ b/src/basic/unit-file.c
@@ -354,10 +354,16 @@ int unit_file_build_name_map(
/* Check if the symlink goes outside of our search path.
* If yes, it's a linked unit file or mask, and we don't care about the target name.
- * Let's just store the link destination directly.
+ * Let's just store the link source directly.
* If not, let's verify that it's a good symlink. */
char *tail = path_startswith_strv(simplified, lp->search_path);
- if (tail) {
+ if (!tail) {
+ log_debug("%s: linked unit file: %s → %s",
+ __func__, filename, simplified);
+
+ dst = filename;
+ } else {
+
bool self_alias;
dst = basename(simplified);
@@ -380,10 +386,6 @@ int unit_file_build_name_map(
}
log_debug("%s: alias: %s/%s → %s", __func__, *dir, de->d_name, dst);
- } else {
- dst = simplified;
-
- log_debug("%s: linked unit file: %s/%s → %s", __func__, *dir, de->d_name, dst);
}
} else {