[commit: process] master: Fix process007 with dash as /bin/sh (e380844)
Ian Lynagh
igloo at earth.li
Sun Jun 16 21:44:17 CEST 2013
Repository : ssh://darcs.haskell.org//srv/darcs/packages/process
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/e380844b1e2c17faaaf6bbb9580a903bc30baa25
>---------------------------------------------------------------
commit e380844b1e2c17faaaf6bbb9580a903bc30baa25
Author: Ian Lynagh <ian at well-typed.com>
Date: Sun Jun 16 18:47:13 2013 +0100
Fix process007 with dash as /bin/sh
dash doesn't support 2-digit FD numbers with the 0<&10 syntax, and
some ways were using FDs that high. So now we have a little C program
to do the job instead.
>---------------------------------------------------------------
tests/Makefile | 5 +++++
tests/all.T | 7 ++++++-
tests/process007.hs | 4 +---
tests/process007_fd.c | 37 +++++++++++++++++++++++++++++++++++++
4 files changed, 49 insertions(+), 4 deletions(-)
diff --git a/tests/Makefile b/tests/Makefile
index 6a0abcf..87c62e2 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -5,3 +5,8 @@
TOP=../../../testsuite
include $(TOP)/mk/boilerplate.mk
include $(TOP)/mk/test.mk
+
+.PHONY: process007_fd
+process007_fd:
+ '$(TEST_HC)' -no-hs-main -no-auto-link-packages process007_fd.c -o process007_fd
+
diff --git a/tests/all.T b/tests/all.T
index 643863b..3a19367 100644
--- a/tests/all.T
+++ b/tests/all.T
@@ -6,7 +6,12 @@ test('T1780', normal, compile_and_run, [''])
test('process005', normal, compile_and_run, [''])
test('process006', normal, compile_and_run, [''])
-test('process007', [extra_clean(['process007.tmp']), reqlib('unix')], compile_and_run, [''])
+test('process007',
+ [extra_clean(['process007.tmp',
+ 'process007_fd.o', 'process007_fd', 'process007_fd.exe']),
+ reqlib('unix'),
+ pre_cmd('$MAKE -s --no-print-directory process007_fd')],
+ compile_and_run, [''])
test('process008', normal, compile_and_run, [''])
# not the normal way: this test runs processes from multiple threads, and
diff --git a/tests/process007.hs b/tests/process007.hs
index 1e2421f..10524f8 100644
--- a/tests/process007.hs
+++ b/tests/process007.hs
@@ -9,9 +9,7 @@ tmpfile = "process007.tmp"
main = do
writeFile tmpfile "You bad pie-rats!\n"
fd <- handleToFd =<< openFile tmpfile ReadMode
- system ("cat 0<&" ++ show fd)
- -- or this, but maybe less portable?
- -- rawSystem "cat" ["/dev/fd/" ++ show fd]
+ rawSystem "./process007_fd" [show fd]
closeFd fd
fd <- handleToFd =<< openFile tmpfile ReadMode
diff --git a/tests/process007_fd.c b/tests/process007_fd.c
new file mode 100644
index 0000000..1de3b94
--- /dev/null
+++ b/tests/process007_fd.c
@@ -0,0 +1,37 @@
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#define SIZE 1024
+
+int main(int argc, char **argv) {
+ int fd;
+ char buf[SIZE];
+ int nRead, nWrite;
+
+ if (argc != 2) {
+ printf("Bad arguments\n");
+ exit(1);
+ }
+
+ fd = atoi(argv[1]);
+
+ while (nRead = read(fd, buf, SIZE) != 0) {
+ if (nRead > 0) {
+ nWrite = printf("%s", buf);
+ if (nWrite < 0) {
+ perror("printf failed");
+ exit(1);
+ }
+ }
+ else if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR) {
+ perror("read failed");
+ exit(1);
+ }
+ }
+
+ return 0;
+}
+
More information about the ghc-commits
mailing list