From 4ef542eb13bb82c2d4f7f5646c8aeed837d4f8c7 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Mon, 15 Sep 2025 11:05:34 +0200 Subject: [PATCH] drop fd_move_cloexec() There's really no need to duplicate fd to a trivial sysfs file, neither any need to explicitly mark it as close-on-exec. There's no locking whatsoever involved, even parallel writes are fully supported for sysfs attribute files. And the way it was done was really weird and fragile: it just brutely overwrote fd # MAXCLIENTS. The MAXCLIENTS define is internal to the Xserver, outside of individual driver's concern, and drivers really shouldn't directly mess with the fd table that way - they have no way to make sure it's really done right. Therefore, just drop this all and leave the fd as it is. Signed-off-by: Enrico Weigelt, metux IT consult --- src/backlight.c | 2 +- src/fd.c | 22 ---------------------- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/src/backlight.c b/src/backlight.c index f416f2a4..1dd8f8d7 100644 --- a/src/backlight.c +++ b/src/backlight.c @@ -326,7 +326,7 @@ int backlight_exists(const char *iface) static int __backlight_init(struct backlight *b, char *iface, int fd) { - b->fd = fd_move_cloexec(fd_set_nonblock(fd)); + b->fd = fd_set_nonblock(fd); b->iface = iface; return 1; } diff --git a/src/fd.c b/src/fd.c index f96de774..2ef1550e 100644 --- a/src/fd.c +++ b/src/fd.c @@ -37,28 +37,6 @@ #include "fd.h" -int fd_move_cloexec(int fd) -{ - int newfd; - - newfd = fcntl(fd, -#ifdef F_DUPFD_CLOEXEC - F_DUPFD_CLOEXEC, -#else - F_DUPFD, -#endif - MAXCLIENTS); - if (newfd < 0) - return fd; - -#ifndef F_DUPFD_CLOEXEC - newfd = fd_set_cloexec(newfd); -#endif - - close(fd); - return newfd; -} - int fd_set_cloexec(int fd) { int flags;