anitazha / rpms / systemd

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