diff options
author | Jim Meyering <meyering@redhat.com> | 2009-08-17 09:38:50 +0200 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2009-08-17 11:40:24 +0200 |
commit | 5a9b41ed4462ec765303b973f74f17d5c0138a9a (patch) | |
tree | f2f338e8f13ca9e8ec6d456b4f0e63db121d52bb /daemon | |
parent | ff2f3fc656b62ba4291ddb4a7238426c446db7c3 (diff) | |
download | libguestfs-5a9b41ed4462ec765303b973f74f17d5c0138a9a.tar.gz libguestfs-5a9b41ed4462ec765303b973f74f17d5c0138a9a.tar.xz libguestfs-5a9b41ed4462ec765303b973f74f17d5c0138a9a.zip |
daemon/zero: don't ignore write and close errors
* daemon/zero.c (do_zero): Detect write and close errors.
Diffstat (limited to 'daemon')
-rw-r--r-- | daemon/zero.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/daemon/zero.c b/daemon/zero.c index ce45ae23..0ade2423 100644 --- a/daemon/zero.c +++ b/daemon/zero.c @@ -41,10 +41,20 @@ do_zero (const char *device) memset (buf, 0, sizeof buf); + int err = 0; + int saved_errno = 0; for (i = 0; i < 32; ++i) - (void) write (fd, buf, sizeof buf); - - close (fd); + if (write (fd, buf, sizeof buf) != sizeof buf) { + saved_errno = errno; + err = -1; + } + + if (close (fd) && saved_errno == 0) { + saved_errno = errno; + err = -1; + } - return 0; + if (saved_errno) + errno = saved_errno; + return err; } |