diff options
author | Jim Meyering <jim@meyering.net> | 2007-06-24 21:20:41 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2007-06-26 21:48:53 -0700 |
commit | 91c8d5905c33e9d7c9014a1c6c7cec8eb86584df (patch) | |
tree | c3dbbc16aa7df268aae8962bc4cac367fc5c51ca /refs.c | |
parent | 2275d502114c71045af991697048191fed88aac4 (diff) | |
download | git-91c8d5905c33e9d7c9014a1c6c7cec8eb86584df.tar.gz git-91c8d5905c33e9d7c9014a1c6c7cec8eb86584df.tar.xz |
detect close failure on just-written file handles
I audited git for potential undetected write failures.
In the cases fixed below, the diagnostics I add mimic the diagnostics
used in surrounding code, even when that means not reporting
the precise strerror(errno) cause of the error.
Signed-off-by: Jim Meyering <jim@meyering.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.c')
-rw-r--r-- | refs.c | 6 |
1 files changed, 2 insertions, 4 deletions
@@ -1106,8 +1106,7 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1, len += sprintf(logrec + len - 1, "\t%.*s\n", msglen, msg) - 1; written = len <= maxlen ? write_in_full(logfd, logrec, len) : -1; free(logrec); - close(logfd); - if (written != len) + if (close(logfd) != 0 || written != len) return error("Unable to append to %s", log_file); return 0; } @@ -1204,8 +1203,7 @@ int create_symref(const char *ref_target, const char *refs_heads_master, goto error_free_return; } written = write_in_full(fd, ref, len); - close(fd); - if (written != len) { + if (close(fd) != 0 || written != len) { error("Unable to write to %s", lockpath); goto error_unlink_return; } |