mirror of
https://github.com/arun11299/cpp-subprocess.git
synced 2025-08-04 12:26:19 -04:00
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:
parent
625a877579
commit
9974ff69cd
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user