]> 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>
Thu, 19 Dec 2024 09:56:00 +0000 (09:56 +0000)
If a specified unit does not exist, then it is definitely not masked.

Fixes #35632.

(cherry picked from commit b58b00e4c33474505009c8118d6cfdf29a2c6cb1)

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

index c42a31153dc65422592a54a1c22eff421a62c4f6..7165fa1cf74990e5deb90b3d2268c2c80b0ead16 100644 (file)
@@ -349,8 +349,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 ed7b9f64bff3e910d93a73a233ebc05468e5d208..8e895aa9ae8a8413010e618755275b1d97af4a59 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"