about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-07-11T08·16+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-07-11T08·16+0000
commitc834a5c5975b9a62413b4aa9446f73d1c573c909 (patch)
tree3b5d4cbe346ef0bdbbf005ef5a24c125f65a467c
parent822c072cfa0f1e4ac304343d78e024ba19da34a8 (diff)
* Fix handling of pipes (read(2) may not return the required
  number of bytes in one call).

-rw-r--r--src/nix.cc12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/nix.cc b/src/nix.cc
index 19c73165cdc8..8fc0fa2c325c 100644
--- a/src/nix.cc
+++ b/src/nix.cc
@@ -250,11 +250,13 @@ struct StdinSource : RestoreSource
 {
     virtual void operator () (const unsigned char * data, unsigned int len)
     {
-        ssize_t res = read(STDIN_FILENO, (char *) data, len);
-        if (res == -1)
-            throw SysError("reading from stdin");
-        if (res != (ssize_t) len)
-            throw Error("not enough data available on stdin");
+        while (len) {
+            ssize_t res = read(STDIN_FILENO, (char *) data, len);
+            if (res == -1) throw SysError("reading from stdin");
+            if (res == 0) throw SysError("unexpected end-of-file on stdin");
+            len -= res;
+            data += res;
+        }
     }
 };