[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH libguestfs 07/13] daemon/zero: don't ignore write and close errors



From: Jim Meyering <meyering redhat com>

* daemon/zero.c (do_zero): Detect write and close errors.
---
 daemon/zero.c |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)

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;
 }
-- 
1.6.4.378.g88f2f


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]