Commit e380844b authored by ian@well-typed.com's avatar ian@well-typed.com
Browse files

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.
parent 2cdacc6e
......@@ -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
......@@ -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
......
......@@ -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
......
#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;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment