Skip to content

Commit cd95c9d

Browse files
tomasandroilhebasto
authored andcommitted
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
1 parent b7288de commit cd95c9d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/util/subprocess.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,14 @@ namespace util
346346
void set_clo_on_exec(int fd, bool set = true)
347347
{
348348
int flags = fcntl(fd, F_GETFD, 0);
349+
if (flags == -1) {
350+
throw OSError("fcntl F_GETFD failed", errno);
351+
}
349352
if (set) flags |= FD_CLOEXEC;
350353
else flags &= ~FD_CLOEXEC;
351-
//TODO: should check for errors
352-
fcntl(fd, F_SETFD, flags);
354+
if (fcntl(fd, F_SETFD, flags) == -1) {
355+
throw OSError("fcntl F_SETFD failed", errno);
356+
}
353357
}
354358

355359

0 commit comments

Comments
 (0)