]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
portablectl: normalize read-only image paths
authordongshengyuan <545258830@qq.com>
Wed, 15 Jul 2026 08:36:02 +0000 (16:36 +0800)
committerdongshengyuan <545258830@qq.com>
Wed, 15 Jul 2026 10:13:11 +0000 (18:13 +0800)
Run read-only image arguments through determine_image() before sending
them over D-Bus. This gives relative paths the same normalized form as
other portablectl image operations.

Reproducer:
  cd /tmp
  portablectl read-only ./portable-repro true

Before:
  ./portable-repro was sent unchanged to portabled and rejected as an
  invalid image name/path. The same image worked when passed as an
  absolute path, so relative paths behaved inconsistently.

Follow-up: 61d0578b07b97cbffebfd350bac481274e310d39

src/portable/portablectl.c

index 1c479f1134a403dbbedac15c38b7b5233770969b..641fc1365fc265157e3e9c73c4d84723ef3df213 100644 (file)
@@ -1399,6 +1399,7 @@ VERB(verb_read_only_image, "read-only", "NAME|PATH [BOOL]", 2, 3, 0,
 static int verb_read_only_image(int argc, char *argv[], uintptr_t _data, void *userdata) {
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
         _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
+        _cleanup_free_ char *image = NULL;
         int b = true, r;
 
         if (argc > 2) {
@@ -1407,13 +1408,17 @@ static int verb_read_only_image(int argc, char *argv[], uintptr_t _data, void *u
                         return log_error_errno(b, "Failed to parse boolean argument: %s", argv[2]);
         }
 
+        r = determine_image(argv[1], false, &image);
+        if (r < 0)
+                return r;
+
         r = acquire_bus(&bus);
         if (r < 0)
                 return r;
 
         (void) polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
 
-        r = bus_call_method(bus, bus_portable_mgr, "MarkImageReadOnly", &error, NULL, "sb", argv[1], b);
+        r = bus_call_method(bus, bus_portable_mgr, "MarkImageReadOnly", &error, NULL, "sb", image, b);
         if (r < 0)
                 return log_error_errno(r, "Could not mark image read-only: %s", bus_error_message(&error, r));