From 5a18f63b8dfc35fb7bcda4688661e354783d2bb7 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Wed, 22 Jan 2020 02:10:59 -0700 Subject: [PATCH] Set the close-on-exec flag for file and pipe redirections. --- ChangeLog | 5 +++++ TODO | 5 +---- run.c | 3 +++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1afd9de..4e95699 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2020-01-20 Arnold D. Robbins + + * run.c (openfile): Set the close-on-exec flag for file + and pipe redirections that aren't stdin/stdout/stderr. + 2020-01-06 Arnold D. Robbins Minor fixes. diff --git a/TODO b/TODO index 3067377..13f2925 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -Fri Jan 17 14:04:29 IST 2020 +Wed Jan 22 02:10:35 MST 2020 ============================ Here are some things that it'd be nice to have volunteer @@ -17,6 +17,3 @@ and see exactly which tests fail: a test suite target that runs valgrind on all the tests and reports if there are any definite losses or any invalid reads or writes (similar to gawk's test of this nature). - -4. Set the "close on exec" flag for file and pipe redirection - file descriptors. diff --git a/run.c b/run.c index 2bef988..ad6432b 100644 --- a/run.c +++ b/run.c @@ -25,6 +25,7 @@ THIS SOFTWARE. #define DEBUG #include #include +#include #include #include #include @@ -1744,6 +1745,8 @@ FILE *openfile(int a, const char *us) files[i].fname = tostring(s); files[i].fp = fp; files[i].mode = m; + if (fp != stdin && fp != stdout && fp != stderr) + (void) fcntl(fileno(fp), F_SETFD, FD_CLOEXEC); } return fp; }