1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-17 08:47:39 +00:00

Add CLOEXECs when getting file descriptors (#374)

This should help address leaking file descriptors in multithreaded
programs. There are a few cases where a race can occur though, as
some apis (fopen and mktemp).
This commit is contained in:
Calvin Rose
2020-05-06 18:33:25 -05:00
parent 9aefb59afe
commit dc3e9fb77c
4 changed files with 24 additions and 9 deletions

View File

@@ -606,7 +606,7 @@ static Janet os_cryptorand(int32_t argc, Janet *argv) {
In both cases, use this fallback path for now... */
int rc;
int randfd;
RETRY_EINTR(randfd, open("/dev/urandom", O_RDONLY));
RETRY_EINTR(randfd, open("/dev/urandom", O_RDONLY | O_CLOEXEC));
if (randfd < 0)
janet_panic(genericerr);
while (n > 0) {