valeriyvdovin / rpms / systemd

Forked from rpms/systemd 4 years ago
Clone

Blame SOURCES/0720-shared-install-allow-enable-on-linked-unit-files.patch

Pablo Greco 48fc63
From 81e311e36abca2f433fa6ac3d86100fcc9d50403 Mon Sep 17 00:00:00 2001
Pablo Greco 48fc63
From: Kyle Walker <kwalker@redhat.com>
Pablo Greco 48fc63
Date: Thu, 15 Nov 2018 11:50:39 -0500
Pablo Greco 48fc63
Subject: [PATCH] shared/install: allow "enable" on linked unit files
Pablo Greco 48fc63
Pablo Greco 48fc63
User expectations are broken when "systemctl enable /some/path/service.service"
Pablo Greco 48fc63
behaves differently to "systemctl link ..." followed by "systemctl enable".
Pablo Greco 48fc63
From user's POV, "enable" with the full path just combines the two steps into
Pablo Greco 48fc63
one.
Pablo Greco 48fc63
Pablo Greco 48fc63
(cherry picked from commit f777b4345e8c57e739bda746f78757d0fb136ac7)
Pablo Greco 48fc63
Pablo Greco 48fc63
Resolves: #1628575
Pablo Greco 48fc63
---
Pablo Greco 48fc63
 src/shared/install.c         | 2 +-
Pablo Greco 48fc63
 src/test/test-install-root.c | 7 ++++++-
Pablo Greco 48fc63
 2 files changed, 7 insertions(+), 2 deletions(-)
Pablo Greco 48fc63
Pablo Greco 48fc63
diff --git a/src/shared/install.c b/src/shared/install.c
Pablo Greco 48fc63
index e73f0c95bd..ea01e4dcc2 100644
Pablo Greco 48fc63
--- a/src/shared/install.c
Pablo Greco 48fc63
+++ b/src/shared/install.c
Pablo Greco 48fc63
@@ -1878,7 +1878,7 @@ int unit_file_enable(
Pablo Greco 48fc63
                 return r;
Pablo Greco 48fc63
 
Pablo Greco 48fc63
         STRV_FOREACH(f, files) {
Pablo Greco 48fc63
-                r = install_info_discover(scope, &c, root_dir, &paths, *f, SEARCH_LOAD, &i);
Pablo Greco 48fc63
+                r = install_info_discover(scope, &c, root_dir, &paths, *f, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS, &i);
Pablo Greco 48fc63
                 if (r < 0)
Pablo Greco 48fc63
                         return r;
Pablo Greco 48fc63
                 if (i->type == UNIT_FILE_TYPE_MASKED)
Pablo Greco 48fc63
diff --git a/src/test/test-install-root.c b/src/test/test-install-root.c
Pablo Greco 48fc63
index cb417d4c19..9f6fa625ac 100644
Pablo Greco 48fc63
--- a/src/test/test-install-root.c
Pablo Greco 48fc63
+++ b/src/test/test-install-root.c
Pablo Greco 48fc63
@@ -299,7 +299,12 @@ static void test_linked_units(const char *root) {
Pablo Greco 48fc63
         unit_file_changes_free(changes, n_changes);
Pablo Greco 48fc63
         changes = NULL; n_changes = 0;
Pablo Greco 48fc63
 
Pablo Greco 48fc63
-        assert_se(unit_file_enable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("linked3.service"), &changes, &n_changes) == -ELOOP);
Pablo Greco 48fc63
+        assert_se(unit_file_enable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("linked3.service"), &changes, &n_changes) >= 0);
Pablo Greco 48fc63
+        assert_se(n_changes == 1);
Pablo Greco 48fc63
+        assert_se(changes[0].type == UNIT_FILE_SYMLINK);
Pablo Greco 48fc63
+        assert_se(startswith(changes[0].path, root));
Pablo Greco 48fc63
+        assert_se(endswith(changes[0].path, "linked3.service"));
Pablo Greco 48fc63
+        assert_se(streq(changes[0].source, "/opt/linked3.service"));
Pablo Greco 48fc63
         unit_file_changes_free(changes, n_changes);
Pablo Greco 48fc63
         changes = NULL; n_changes = 0;
Pablo Greco 48fc63
 }