teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame SOURCES/0406-shared-install-ignore-unit-symlinks-when-doing-prese.patch

923a60
From 412044ee341c574e5163bf2be32e5da9618f2640 Mon Sep 17 00:00:00 2001
923a60
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
923a60
Date: Sat, 13 Aug 2016 01:20:29 -0400
923a60
Subject: [PATCH] shared/install: ignore unit symlinks when doing preset-all
923a60
923a60
Before, when interating over unit files during preset-all, behaviour was the
923a60
following:
923a60
923a60
- if we hit the real unit name first, presets were queried for that name, and
923a60
  that unit was enabled or disabled accordingly,
923a60
923a60
- if we hit an alias first (one of the symlinks chaining to the real unit), we
923a60
  checked the presets using the symlink name, and then proceeded to enable or
923a60
  disable the real unit.
923a60
923a60
E.g. for systemd-networkd.service we have the alias dbus-org.freedesktop.network1.service
923a60
(/usr/lib/systemd/system/dbus-org.freedesktop.network1.service), but the preset
923a60
is only for the systemd-networkd.service name. The service would be enabled or
923a60
disabled pseudorandomly depending on the order of iteration.
923a60
923a60
For "preset", behaviour was analogous: preset on the alias name disabled the
923a60
service (following the default disable policy), preset on the "real" name
923a60
applied the presets.
923a60
923a60
With the patch, for "preset" and "preset-all" we silently skip symlinks. This
923a60
gives mostly the right behaviour, with the limitation that presets on aliases
923a60
are ignored.  I think that presets on aliases are not that common (at least my
923a60
preset files on Fedora don't exhibit any such usage), and should not be
923a60
necessary, since whoever installs the preset can just refer to the real unit
923a60
file. It would be possible to overcome this limitation by gathering a list of
923a60
names of a unit first, and then checking whether *any* of the names matches the
923a60
presets list. That would require a significant redesign of the code, and be
923a60
a lot slower (since we would have to fully read all unit directories to preset
923a60
one unit) to so I'm not doing that for now.
923a60
923a60
With this patch, two properties are satisfied:
923a60
- preset-all and preset are idempotent, and the second and subsequent invocations
923a60
  do not produce any changes,
923a60
- preset-all and preset for a specific name produce the same state for that unit.
923a60
923a60
Fixes #3616.
923a60
923a60
Cherry-picked from: 11e11fd57a837ea1cb142009c3048882392f3ed3
923a60
Related: #1375097
923a60
---
923a60
 src/shared/install.c | 12 ++++++++++--
923a60
 1 file changed, 10 insertions(+), 2 deletions(-)
923a60
923a60
diff --git a/src/shared/install.c b/src/shared/install.c
923a60
index b0a29ddd7e..f01a212620 100644
923a60
--- a/src/shared/install.c
923a60
+++ b/src/shared/install.c
923a60
@@ -2270,12 +2270,20 @@ static int preset_prepare_one(
923a60
                 const char *name) {
923a60
 
923a60
         InstallInfo *i;
923a60
+        _cleanup_(install_context_done) InstallContext tmp = {};
923a60
         int r;
923a60
 
923a60
-        if (install_info_find(plus, name) ||
923a60
-            install_info_find(minus, name))
923a60
+        if (install_info_find(plus, name) || install_info_find(minus, name))
923a60
                 return 0;
923a60
 
923a60
+        r = install_info_discover(scope, &tmp, root_dir, paths, name, SEARCH_FOLLOW_CONFIG_SYMLINKS, &i);
923a60
+        if (r < 0)
923a60
+                return r;
923a60
+        if (!streq(name, i->name)) {
923a60
+                log_debug("Skipping %s because is an alias for %s", name, i->name);
923a60
+                return 0;
923a60
+        }
923a60
+
923a60
         r = unit_file_query_preset(scope, root_dir, name);
923a60
         if (r < 0)
923a60
                 return r;