Thread (18 messages) 18 messages, 5 authors, 2017-11-03

Re: [PATCH 2/2] sequencer.c: check return value of close() in rewrite_file()

flat view

From: René Scharfe <hidden>
Date: 2017-11-01 17:10:03

Am 01.11.2017 um 15:45 schrieb Simon Ruderich:
quoted hunk ↗ jump to hunk
Not checking close(2) can hide errors as not all errors are reported
during the write(2).

Signed-off-by: Simon Ruderich <redacted>
---

On Wed, Nov 01, 2017 at 02:00:11PM +0100, René Scharfe wrote:
quoted
Most calls are not checked, but that doesn't necessarily mean they need
to (or should) stay that way.  The Linux man-page of close(2) spends
multiple paragraphs recommending to check its return value..  Care to
send a follow-up patch?
Hello,

Sure, here is it.

Regards
Simon

  sequencer.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/sequencer.c b/sequencer.c
index f93b60f61..e0cc2f777 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -2673,7 +2673,8 @@ static int rewrite_file(const char *path, const char *buf, size_t len)
  		return error_errno(_("could not open '%s' for writing"), path);
  	if (write_in_full(fd, buf, len) < 0)
  		rc = error_errno(_("could not write to '%s'"), path);
-	close(fd);
+	if (close(fd) && !rc)
+		rc = error_errno(_("could not close '%s'"), path);
  	return rc;
  }
  
Looks good to me, thank you!

René
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help