naccyde / rpms / systemd

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