From 9cfefbf9835eb1f6d6a82d74d1be2d2a23952a1a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 3 Dec 2025 09:40:22 +0100 Subject: [PATCH] dissect-image: automatically convert O_PATH fd to proper fd in mountfsd client 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 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index 0957257080e..28e40606aee 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -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"); -- 2.47.3