From 5a9b41ed4462ec765303b973f74f17d5c0138a9a Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Mon, 17 Aug 2009 09:38:50 +0200 Subject: [PATCH] daemon/zero: don't ignore write and close errors * daemon/zero.c (do_zero): Detect write and close errors. --- daemon/zero.c | 18 ++++++++++++++---- 1 file 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.8.3.1