From ea9572e1d0012ff80f61493b67ba20024b68d303 Mon Sep 17 00:00:00 2001 From: jilles Date: Mon, 20 May 2013 17:31:18 +0000 Subject: popen(): Add 'e' mode character to set close-on-exec on the new fd. If 'e' is used, the kernel must support the recently added pipe2() system call. The use of pipe2() with O_CLOEXEC also fixes race conditions between concurrent popen() calls from different threads, even if the close-on-exec flag on the fd of the returned FILE is later cleared (because popen() closes all file descriptors from earlier popen() calls in the child process). Therefore, this approach should be used in all cases when pipe2() can be assumed present. The old version of popen() rejects "re" and "we" but treats "r+e" like "r+". --- tools/regression/lib/libc/gen/test-popen.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tools/regression/lib/libc/gen/test-popen.c') diff --git a/tools/regression/lib/libc/gen/test-popen.c b/tools/regression/lib/libc/gen/test-popen.c index b1ae295..bf301d2 100644 --- a/tools/regression/lib/libc/gen/test-popen.c +++ b/tools/regression/lib/libc/gen/test-popen.c @@ -70,10 +70,10 @@ main(int argc, char *argv[]) FILE *fp, *fp2; int i, j, status; const char *mode; - const char *allmodes[] = { "r", "w", "r+" }; - const char *rmodes[] = { "r", "r+" }; - const char *wmodes[] = { "w", "r+" }; - const char *rwmodes[] = { "r+" }; + const char *allmodes[] = { "r", "w", "r+", "re", "we", "r+e", "re+" }; + const char *rmodes[] = { "r", "r+", "re", "r+e", "re+" }; + const char *wmodes[] = { "w", "r+", "we", "r+e", "re+" }; + const char *rwmodes[] = { "r+", "r+e", "re+" }; char buf[80]; struct sigaction act, oact; -- cgit v1.1