[PATCH 2/2] sequencer.c: check return value of close() in rewrite_file()
- From
Simon Ruderich <simon@ruderich.org>
- Date
- Nov 1, 2017, 14:45 UTC
- Message-ID
- <06c33d3cfa35c0524ede2970ee3169d6c62eb5c1.1509547231.git.simon@ruderich.org>
- In-Reply-To
- <22afeefa-cdd5-cd32-0a7c-6bad4de79f05@web.de>
Not checking close(2) can hide errors as not all errors are reported during the write(2).
Signed-off-by: Simon Ruderich <simon@ruderich.org> ---
On Wed, Nov 01, 2017 at 02:00:11PM +0100, René Scharfe wrote:
> 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; }
-- 2.15.0 -- + privacy is necessary + using gnupg http://gnupg.org + public key id: 0x92FEFDB7E44C32F9