summaryrefslogtreecommitdiffstats
path: root/daemon/zero.c
diff options
context:
space:
mode:
Diffstat (limited to 'daemon/zero.c')
-rw-r--r--daemon/zero.c18
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;
}