Set the close-on-exec flag for file and pipe redirections.

This commit is contained in:
Arnold D. Robbins 2020-01-22 02:10:59 -07:00
parent de6284e037
commit 5a18f63b8d
3 changed files with 9 additions and 4 deletions

View File

@ -1,3 +1,8 @@
2020-01-20 Arnold D. Robbins <arnold@skeeve.com>
* 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 <arnold@skeeve.com> 2020-01-06 Arnold D. Robbins <arnold@skeeve.com>
Minor fixes. Minor fixes.

5
TODO
View File

@ -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 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 a test suite target that runs valgrind on all the tests and
reports if there are any definite losses or any invalid reads reports if there are any definite losses or any invalid reads
or writes (similar to gawk's test of this nature). or writes (similar to gawk's test of this nature).
4. Set the "close on exec" flag for file and pipe redirection
file descriptors.

3
run.c
View File

@ -25,6 +25,7 @@ THIS SOFTWARE.
#define DEBUG #define DEBUG
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
#include <fcntl.h>
#include <setjmp.h> #include <setjmp.h>
#include <limits.h> #include <limits.h>
#include <math.h> #include <math.h>
@ -1744,6 +1745,8 @@ FILE *openfile(int a, const char *us)
files[i].fname = tostring(s); files[i].fname = tostring(s);
files[i].fp = fp; files[i].fp = fp;
files[i].mode = m; files[i].mode = m;
if (fp != stdin && fp != stdout && fp != stderr)
(void) fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
} }
return fp; return fp;
} }