aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-07-16 21:24:02 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-07-16 21:24:02 +0000
commit54664b6fb74e964d70530d13e25459751d0c63fb (patch)
tree9b305d680ebec562274d718feaedf8a51c3f4b75 /src
parent335aa1c35d8835619b465df3f5629b435bac157d (diff)
* The write() system call can write less than the requested
number of bytes, e.g., in case of a signal like SIGSTOP. This caused `nix --dump' to fail sometimes. Note that this bug went unnoticed because the call to `nix --dump' is in a pipeline, and the shell ignores non-zero exit codes from all but the last element in the pipeline. Is there any way to check the result of the initial elements in the pipeline? (In other words, is it at all possible to write reliable shell scripts?)
Diffstat (limited to 'src')
-rw-r--r--src/nix.cc10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/nix.cc b/src/nix.cc
index ae016824d..fe762798e 100644
--- a/src/nix.cc
+++ b/src/nix.cc
@@ -216,8 +216,12 @@ struct StdoutSink : DumpSink
virtual void operator ()
(const unsigned char * data, unsigned int len)
{
- if (write(STDOUT_FILENO, (char *) data, len) != (ssize_t) len)
- throw SysError("writing to stdout");
+ while (len) {
+ ssize_t res = write(STDOUT_FILENO, (char *) data, len);
+ if (res == -1) throw SysError("writing to stdout");
+ len -= res;
+ data += res;
+ }
}
};
@@ -249,7 +253,7 @@ struct StdinSource : RestoreSource
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");
+ if (res == 0) throw Error("unexpected end-of-file on stdin");
len -= res;
data += res;
}