mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 06:49:38 -04:00
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. Github-Pull: arun11299/cpp-subprocess#117 Rebased-From: 9974ff69cdd5fc1a2722cb63f006df9308628b35
This commit is contained in:
parent
e25ec7300c
commit
7e80030a95
1 changed files with 6 additions and 2 deletions
|
@ -346,10 +346,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…
Add table
Reference in a new issue