Skip to content

Commit 1b98ac6

Browse files
committed
Add SetCloseOnExec
1 parent 52afbdc commit 1b98ac6

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/unix/pty.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,17 @@ struct ExitEvent {
113113
};
114114

115115
#if defined(__linux__)
116+
117+
static int
118+
SetCloseOnExec(int fd) {
119+
int flags = fcntl(fd, F_GETFD, 0);
120+
if (flags == -1)
121+
return flags;
122+
if (flags & FD_CLOEXEC)
123+
return 0;
124+
return fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
125+
}
126+
116127
/**
117128
* Close all file descriptors >= 3 to prevent FD leakage to child processes.
118129
* Uses close_range() syscall on Linux 5.9+, falls back to /proc/self/fd iteration.

0 commit comments

Comments
 (0)