]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dissect-image: automatically convert O_PATH fd to proper fd in mountfsd client 40149/head
authorLennart Poettering <lennart@poettering.net>
Wed, 3 Dec 2025 08:40:22 +0000 (09:40 +0100)
committerLennart Poettering <lennart@poettering.net>
Sun, 21 Dec 2025 06:04:42 +0000 (07:04 +0100)
Let's make the mountfsd client code a bit easier to use, and convert an
O_PATH fd to a real one if necessary, automatically.

src/shared/dissect-image.c

index 0957257080e9f090cb20ef76fef61cd235c28aa5..28e40606aee85d7f5e1bbf473799918feabd6ae0 100644 (file)
@@ -5081,6 +5081,12 @@ int mountfsd_mount_image_fd(
         if (r < 0)
                 return log_error_errno(r, "Failed to enable varlink fd passing for write: %m");
 
+        _cleanup_close_ int reopened_fd = -EBADF;
+
+        image_fd = fd_reopen_condition(image_fd, O_CLOEXEC|O_NOCTTY|O_NONBLOCK|(FLAGS_SET(flags, DISSECT_IMAGE_MOUNT_READ_ONLY) ? O_RDONLY : O_RDWR), O_PATH, &reopened_fd);
+        if (image_fd < 0)
+                return log_error_errno(image_fd, "Failed to reopen fd: %m");
+
         r = sd_varlink_push_dup_fd(vl, image_fd);
         if (r < 0)
                 return log_error_errno(r, "Failed to push image fd into varlink connection: %m");