Commit 843c1a47 authored by Edward Z. Yang's avatar Edward Z. Yang
Browse files

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's avatarEdward Z. Yang <ezyang@mit.edu>
parent 26be9f20
......@@ -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
......
......@@ -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) {
......
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