From 7127931f3be3c4fe201b71c8526e96be560f3107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Andr=C3=B3il?= Date: Mon, 28 Apr 2025 11:35:03 +0200 Subject: [PATCH] fix(subprocess): check and handle fcntl(F_GETFD) failure Add missing error check for fcntl(fd, F_GETFD, 0) in set_clo_on_exec. Raise OSError on failure to align with existing FD_SETFD behavior. This improves robustness in subprocess setup and error visibility. --- subprocess.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/subprocess.hpp b/subprocess.hpp index 073f075..1b35574 100755 --- a/subprocess.hpp +++ b/subprocess.hpp @@ -471,10 +471,14 @@ namespace util void set_clo_on_exec(int fd, bool set = true) { int flags = fcntl(fd, F_GETFD, 0); + if (flags == -1) { + throw OSError("fcntl F_GETFD failed", errno); + } if (set) flags |= FD_CLOEXEC; else flags &= ~FD_CLOEXEC; - //TODO: should check for errors - fcntl(fd, F_SETFD, flags); + if (fcntl(fd, F_SETFD, flags) == -1) { + throw OSError("fcntl F_SETFD failed", errno); + } }