From af48907c0b534f7f81f639f546bfcea6bc8e99b1 Mon Sep 17 00:00:00 2001 From: CismonX Date: Tue, 12 Aug 2025 08:55:42 +0800 Subject: fuse_loop_mt.c: fix close-on-exec flag on clone fd Closes: https://github.com/libfuse/libfuse/issues/1310 Signed-off-by: CismonX (cherry picked from commit 42b9b3bbb71d38be6a5670bbd0948cf406c1573c) --- lib/fuse_loop_mt.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/fuse_loop_mt.c b/lib/fuse_loop_mt.c index d6be998..01c51cc 100644 --- a/lib/fuse_loop_mt.c +++ b/lib/fuse_loop_mt.c @@ -275,9 +275,15 @@ static int fuse_clone_chan_fd_default(struct fuse_session *se) strerror(errno)); return -1; } -#ifndef O_CLOEXEC - fcntl(clonefd, F_SETFD, FD_CLOEXEC); -#endif + if (!O_CLOEXEC) { + res = fcntl(clonefd, F_SETFD, FD_CLOEXEC); + if (res == -1) { + fuse_log(FUSE_LOG_ERR, "fuse: failed to set CLOEXEC: %s\n", + strerror(errno)); + close(clonefd); + return -1; + } + } masterfd = se->fd; res = ioctl(clonefd, FUSE_DEV_IOC_CLONE, &masterfd); -- cgit v1.2.3