]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl-edit: ignore ENOENT from unit_is_masked()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 16 Dec 2024 03:37:17 +0000 (12:37 +0900)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 20 Dec 2024 19:43:57 +0000 (19:43 +0000)
If a specified unit does not exist, then it is definitely not masked.

Fixes #35632.

(cherry picked from commit b58b00e4c33474505009c8118d6cfdf29a2c6cb1)
(cherry picked from commit 48b404d546e6cb6d32d9cb346bbd43760311790b)

src/systemctl/systemctl-edit.c
test/units/TEST-26-SYSTEMCTL.sh

index 15398f83646eb8d30bac92ec450df463de9ed0ae..df67098c6d5fc3963101a6b5fed54b047a3f67e8 100644 (file)
@@ -348,8 +348,8 @@ int verb_edit(int argc, char *argv[], void *userdata) {
 
         STRV_FOREACH(tmp, names) {
                 r = unit_is_masked(bus, *tmp);
-                if (r < 0)
-                        return r;
+                if (r < 0 && r != -ENOENT)
+                        return log_error_errno(r, "Failed to check if unit %s is masked: %m", *tmp);
                 if (r > 0)
                         return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Cannot edit %s: unit is masked.", *tmp);
         }
index 1471f3fd9e47be72a720d14f03b25041d67a8f9f..8e1a03b90fb340df237556e2cec96d386a85bcd6 100755 (executable)
@@ -21,6 +21,7 @@ at_exit() {
 #       the 'revert' verb as well
 export UNIT_NAME="systemctl-test-$RANDOM.service"
 export UNIT_NAME2="systemctl-test-$RANDOM.service"
+export UNIT_NAME_TEMPLATE="systemctl-test-${RANDOM}@.service"
 
 cat >"/usr/lib/systemd/system/$UNIT_NAME" <<\EOF
 [Unit]
@@ -65,6 +66,16 @@ EOF
 printf '%s\n' '[Unit]'   'Description=spectacular' '# this comment should remain' | \
     cmp - "/etc/systemd/system/$UNIT_NAME.d/override2.conf"
 
+# Edit nonexistent template unit, see issue #35632.
+systemctl edit "$UNIT_NAME_TEMPLATE" --stdin --runtime --force --full <<EOF
+[Unit]
+Description=template unit test
+# this comment should remain
+
+EOF
+printf '%s\n' '[Unit]' 'Description=template unit test' '# this comment should remain' | \
+    cmp - "/run/systemd/system/$UNIT_NAME_TEMPLATE"
+
 # Test simultaneous editing of two units and creation of drop-in for a nonexistent unit
 systemctl edit "$UNIT_NAME" "$UNIT_NAME2" --stdin --force --drop-in=override2.conf <<<'[X-Section]'
 printf '%s\n' '[X-Section]' | cmp - "/etc/systemd/system/$UNIT_NAME.d/override2.conf"