fix(subprocess): check and handle fcntl(F_GETFD) failure (#117)

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.
This commit is contained in:
Tomás Andróil 2025-04-28 18:02:14 +02:00 committed by GitHub
parent 625a877579
commit 9974ff69cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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);
}
}