dcavalca / rpms / systemd

Forked from rpms/systemd 4 months ago
Clone
594167
From 9b655d805e78a314a24b8493c6c116a4d943beb9 Mon Sep 17 00:00:00 2001
594167
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
594167
Date: Fri, 11 Mar 2022 14:27:46 +0100
594167
Subject: [PATCH] install: when linking a file, create the link first or abort
594167
594167
We'd create aliases and other symlinks first, and only then try to create
594167
the main link. Since that can fail, let's do things in opposite order, and
594167
abort immediately if we can't link the file itself.
594167
594167
(cherry picked from commit 20d68b3aec62110351bdc695fd1a55adcf3a6ee5)
594167
594167
Related: #2082131
594167
---
594167
 src/shared/install.c          | 12 +++++++-----
594167
 test/test-systemctl-enable.sh |  9 +++------
594167
 2 files changed, 10 insertions(+), 11 deletions(-)
594167
594167
diff --git a/src/shared/install.c b/src/shared/install.c
594167
index 785ef55dbd..fadd2be248 100644
594167
--- a/src/shared/install.c
594167
+++ b/src/shared/install.c
594167
@@ -1985,6 +1985,13 @@ static int install_info_apply(
594167
 
594167
         bool force = file_flags & UNIT_FILE_FORCE;
594167
 
594167
+        r = install_info_symlink_link(info, lp, config_path, force, changes, n_changes);
594167
+        /* Do not count links to the unit file towards the "carries_install_info" count */
594167
+        if (r < 0)
594167
+                /* If linking of the file failed, do not try to create other symlinks,
594167
+                 * because they might would pointing to a non-existent or wrong unit. */
594167
+                return r;
594167
+
594167
         r = install_info_symlink_alias(scope, info, lp, config_path, force, changes, n_changes);
594167
 
594167
         q = install_info_symlink_wants(scope, file_flags, info, lp, config_path, info->wanted_by, ".wants/", changes, n_changes);
594167
@@ -1995,11 +2002,6 @@ static int install_info_apply(
594167
         if (r == 0)
594167
                 r = q;
594167
 
594167
-        q = install_info_symlink_link(info, lp, config_path, force, changes, n_changes);
594167
-        /* Do not count links to the unit file towards the "carries_install_info" count */
594167
-        if (r == 0 && q < 0)
594167
-                r = q;
594167
-
594167
         return r;
594167
 }
594167
 
594167
diff --git a/test/test-systemctl-enable.sh b/test/test-systemctl-enable.sh
594167
index 3aa61222a8..c1fb9626ab 100644
594167
--- a/test/test-systemctl-enable.sh
594167
+++ b/test/test-systemctl-enable.sh
594167
@@ -173,12 +173,9 @@ islink "$root/etc/systemd/system/link1.path" "/link1.path"
594167
 islink "$root/etc/systemd/system/paths.target.wants/link1.path" "/link1.path"
594167
 
594167
 : -------enable already linked different path-----------------
594167
-# FIXME
594167
-# "$systemctl" --root="$root" enable '/subdir/link1.path' && { echo "Expected failure" >&2; exit 1; }
594167
-# test -h "$root/etc/systemd/system/link1.path"
594167
-# readlink "$root/etc/systemd/system/link1.path"
594167
-# test -h "$root/etc/systemd/system/paths.target.wants/link1.path"
594167
-# readlink "$root/etc/systemd/system/paths.target.wants/link1.path"
594167
+"$systemctl" --root="$root" enable '/subdir/link1.path' && { echo "Expected failure" >&2; exit 1; }
594167
+islink "$root/etc/systemd/system/link1.path" "/link1.path"
594167
+islink "$root/etc/systemd/system/paths.target.wants/link1.path" "/link1.path"
594167
 
594167
 : -------enable bad suffix------------------------------------
594167
 cp "$root/link1.path" "$root/subdir/link1.suffix"