aboutsummaryrefslogtreecommitdiff
path: root/stdio-common
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2007-07-19 17:03:08 +0000
committerUlrich Drepper <drepper@redhat.com>2007-07-19 17:03:08 +0000
commit4e425301f4a6264c73eddf31b82c2d197a1a8b16 (patch)
tree926ef5bb537569181d803751e84531c4bb72777b /stdio-common
parentd8d7feefa738eb3138790c99aa891ef44d85e4cc (diff)
downloadglibc-4e425301f4a6264c73eddf31b82c2d197a1a8b16.tar
glibc-4e425301f4a6264c73eddf31b82c2d197a1a8b16.tar.gz
glibc-4e425301f4a6264c73eddf31b82c2d197a1a8b16.tar.bz2
glibc-4e425301f4a6264c73eddf31b82c2d197a1a8b16.zip
* libio/iopopen.c (_IO_new_proc_open): Don't close child_std_end
if one of proc_file_chain streams has that fileno. * stdio-common/Makefile (tests): Add tst-popen2. * stdio-common/tst-popen2.c: New test.
Diffstat (limited to 'stdio-common')
-rw-r--r--stdio-common/Makefile2
-rw-r--r--stdio-common/tst-popen2.c92
2 files changed, 93 insertions, 1 deletions
diff --git a/stdio-common/Makefile b/stdio-common/Makefile
index 4ead0f9574..3388c7e215 100644
--- a/stdio-common/Makefile
+++ b/stdio-common/Makefile
@@ -55,7 +55,7 @@ tests := tstscanf test_rdwr test-popen tstgetln test-fseek \
tst-perror tst-sprintf tst-rndseek tst-fdopen tst-fphex bug14 bug15 \
tst-popen tst-unlockedio tst-fmemopen2 tst-put-error tst-fgets \
tst-fwrite bug16 bug17 tst-swscanf tst-sprintf2 bug18 bug18a \
- bug19 bug19a
+ bug19 bug19a tst-popen2
test-srcs = tst-unbputc tst-printf
diff --git a/stdio-common/tst-popen2.c b/stdio-common/tst-popen2.c
new file mode 100644
index 0000000000..0ab151c598
--- /dev/null
+++ b/stdio-common/tst-popen2.c
@@ -0,0 +1,92 @@
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+static int
+do_test (void)
+{
+ int fd = dup (fileno (stdout));
+ if (fd <= 1)
+ {
+ puts ("dup failed");
+ return 1;
+ }
+
+ FILE *f1 = fdopen (fd, "w");
+ if (f1 == NULL)
+ {
+ printf ("fdopen failed: %m\n");
+ return 1;
+ }
+
+ fclose (stdout);
+
+ FILE *f2 = popen ("echo test1", "r");
+ if (f2 == NULL)
+ {
+ fprintf (f1, "1st popen failed: %m\n");
+ return 1;
+ }
+ FILE *f3 = popen ("echo test2", "r");
+ if (f2 == NULL || f3 == NULL)
+ {
+ fprintf (f1, "2nd popen failed: %m\n");
+ return 1;
+ }
+
+ char *line = NULL;
+ size_t len = 0;
+ int result = 0;
+ if (getline (&line, &len, f2) != 6)
+ {
+ fputs ("could not read line from 1st popen\n", f1);
+ result = 1;
+ }
+ else if (strcmp (line, "test1\n") != 0)
+ {
+ fprintf (f1, "read \"%s\"\n", line);
+ result = 1;
+ }
+
+ if (getline (&line, &len, f2) != -1)
+ {
+ fputs ("second getline did not return -1\n", f1);
+ result = 1;
+ }
+
+ if (getline (&line, &len, f3) != 6)
+ {
+ fputs ("could not read line from 2nd popen\n", f1);
+ result = 1;
+ }
+ else if (strcmp (line, "test2\n") != 0)
+ {
+ fprintf (f1, "read \"%s\"\n", line);
+ result = 1;
+ }
+
+ if (getline (&line, &len, f3) != -1)
+ {
+ fputs ("second getline did not return -1\n", f1);
+ result = 1;
+ }
+
+ int ret = pclose (f2);
+ if (ret != 0)
+ {
+ fprintf (f1, "1st pclose returned %d\n", ret);
+ result = 1;
+ }
+
+ ret = pclose (f3);
+ if (ret != 0)
+ {
+ fprintf (f1, "2nd pclose returned %d\n", ret);
+ result = 1;
+ }
+
+ return result;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"