summaryrefslogtreecommitdiffstats
path: root/daemon/zero.c
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2009-11-26 16:06:03 +0000
committerRichard Jones <rjones@redhat.com>2009-11-26 17:16:17 +0000
commitbba019781a0df3744ccbfe9e580786b66dc9afa9 (patch)
tree2a9ece39b3b16e9f94389773e134f0f44be720c9 /daemon/zero.c
parent4d53df4d7399d35b51bd69d76e00539d1de825e0 (diff)
downloadlibguestfs-bba019781a0df3744ccbfe9e580786b66dc9afa9.tar.gz
libguestfs-bba019781a0df3744ccbfe9e580786b66dc9afa9.tar.xz
libguestfs-bba019781a0df3744ccbfe9e580786b66dc9afa9.zip
Fix error handling in 'zero' function.
Diffstat (limited to 'daemon/zero.c')
-rw-r--r--daemon/zero.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/daemon/zero.c b/daemon/zero.c
index 0ade2423..4d065052 100644
--- a/daemon/zero.c
+++ b/daemon/zero.c
@@ -41,20 +41,17 @@ do_zero (const char *device)
memset (buf, 0, sizeof buf);
- int err = 0;
- int saved_errno = 0;
for (i = 0; i < 32; ++i)
if (write (fd, buf, sizeof buf) != sizeof buf) {
- saved_errno = errno;
- err = -1;
+ reply_with_perror ("write: %s", device);
+ close (fd);
+ return -1;
}
- if (close (fd) && saved_errno == 0) {
- saved_errno = errno;
- err = -1;
+ if (close (fd) == -1) {
+ reply_with_perror ("close: %s", device);
+ return -1;
}
- if (saved_errno)
- errno = saved_errno;
- return err;
+ return 0;
}