From f94e72627150e3e988b741793f4a3b005eb73014 Mon Sep 17 00:00:00 2001 From: Andrew Chambers Date: Sat, 9 May 2020 12:11:08 +1200 Subject: [PATCH 1/2] Improve rng doc string accuracy. --- src/core/math.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/math.c b/src/core/math.c index b1c3fda9..c2b575ef 100644 --- a/src/core/math.c +++ b/src/core/math.c @@ -413,7 +413,7 @@ static const JanetReg math_cfuns[] = { "math/rng", cfun_rng_make, JDOC("(math/rng &opt seed)\n\n" "Creates a Psuedo-Random number generator, with an optional seed. " - "The seed should be an unsigned 32 bit integer. " + "The seed should be an unsigned 32 bit integer or a buffer. " "Do not use this for cryptography. Returns a core/rng abstract type.") }, { From 057486cf56e89b72005ba1c7db9ac517b01de3e4 Mon Sep 17 00:00:00 2001 From: Andrew Chambers Date: Sat, 9 May 2020 22:26:50 +1200 Subject: [PATCH 2/2] Avoid setting O_CLOEXEC on stdin/stdout/stderr. --- src/core/io.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/core/io.c b/src/core/io.c index 97b205e3..642285f3 100644 --- a/src/core/io.c +++ b/src/core/io.c @@ -92,7 +92,8 @@ static Janet makef(FILE *f, int flags) { #ifndef JANET_WINDOWS /* While we would like fopen to set cloexec by default (like O_CLOEXEC) with the e flag, that is * not standard. */ - fcntl(fileno(f), F_SETFD, FD_CLOEXEC); + if (!(flags & JANET_FILE_NOT_CLOSEABLE)) + fcntl(fileno(f), F_SETFD, FD_CLOEXEC); #endif return janet_wrap_abstract(iof); } @@ -136,22 +137,10 @@ static Janet cfun_io_popen(int32_t argc, Janet *argv) { static Janet cfun_io_temp(int32_t argc, Janet *argv) { (void)argv; janet_fixarity(argc, 0); + // XXX use mkostemp when we can to avoid CLOEXEC race. FILE *tmp = tmpfile(); if (!tmp) janet_panicf("unable to create temporary file - %s", strerror(errno)); - -#ifndef JANET_WINDOWS - /* It seems highly unlikely a typical janet user wants a tempfile to be inherited and - libc tmpfile does NOT set O_CLOEXEC by default. - - For threaded programs we should use mkostemp - which is coming to POSIX at a later time. */ - if (fcntl(fileno(tmp), F_SETFD, FD_CLOEXEC) != 0) { - fclose(tmp); - janet_panic("unable initialize temporary file"); - } -#endif - return janet_makefile(tmp, JANET_FILE_WRITE | JANET_FILE_READ | JANET_FILE_BINARY); }