From: Lennart Poettering Date: Wed, 3 Dec 2025 08:40:22 +0000 (+0100) Subject: dissect-image: automatically convert O_PATH fd to proper fd in mountfsd client X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9cfefbf9835eb1f6d6a82d74d1be2d2a23952a1a;p=thirdparty%2Fsystemd.git 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. --- 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");