From: Jim Meyering Date: Mon, 17 Aug 2009 07:38:50 +0000 (+0200) Subject: daemon/zero: don't ignore write and close errors X-Git-Tag: 1.0.68~42 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=5a9b41ed4462ec765303b973f74f17d5c0138a9a;p=libguestfs.git daemon/zero: don't ignore write and close errors * daemon/zero.c (do_zero): Detect write and close errors. --- diff --git a/daemon/zero.c b/daemon/zero.c index ce45ae2..0ade242 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; }