[commit: process] master: Fix process007 test. (843c1a4)
Edward Z. Yang
ezyang at ghc.haskell.org
Sun Jul 21 00:06:57 CEST 2013
Repository : http://darcs.haskell.org/ghc.git/
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/843c1a47ca5a5de05d1a3eff714bc1a2c3148386
>---------------------------------------------------------------
commit 843c1a47ca5a5de05d1a3eff714bc1a2c3148386
Author: Edward Z. Yang <ezyang at mit.edu>
Date: Sat Jul 20 15:05:53 2013 -0700
Fix process007 test.
Two fixes:
- Properly reimplement 'cat' using the 'write' system
call instead of printf; printf was expecting a NULL-terminating
string and was running over into the stack.
- Use the process007_fd shim program for the second cat
as well; essentially, apply the e380844b fix to all cases.
Signed-off-by: Edward Z. Yang <ezyang at mit.edu>
>---------------------------------------------------------------
tests/process007.hs | 2 +-
tests/process007_fd.c | 14 +++++++++-----
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/tests/process007.hs b/tests/process007.hs
index 10524f8..506a0ca 100644
--- a/tests/process007.hs
+++ b/tests/process007.hs
@@ -14,7 +14,7 @@ main = do
fd <- handleToFd =<< openFile tmpfile ReadMode
nul <- openFile "/dev/null" WriteMode
- (_,_,_,p) <- createProcess (shell ("cat 0<&" ++ show fd))
+ (_,_,_,p) <- createProcess (shell ("./process007_fd " ++ show fd))
{ close_fds = True,
std_err = UseHandle nul }
e <- waitForProcess p
diff --git a/tests/process007_fd.c b/tests/process007_fd.c
index 1de3b94..f62ec24 100644
--- a/tests/process007_fd.c
+++ b/tests/process007_fd.c
@@ -18,12 +18,16 @@ int main(int argc, char **argv) {
fd = atoi(argv[1]);
- while (nRead = read(fd, buf, SIZE) != 0) {
+ while ((nRead = read(fd, buf, SIZE)) != 0) {
if (nRead > 0) {
- nWrite = printf("%s", buf);
- if (nWrite < 0) {
- perror("printf failed");
- exit(1);
+ ssize_t nWritten = 0;
+ while (nWritten < nRead) {
+ nWrite = write(STDOUT_FILENO, buf + nWritten, nRead - nWritten);
+ if (nWrite < 0) {
+ perror("printf failed");
+ exit(1);
+ }
+ nWritten += nWrite;
}
}
else if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR) {
More information about the ghc-commits
mailing list