summaryrefslogtreecommitdiff
path: root/lockfile.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2014-10-01 12:28:40 +0200
committerJunio C Hamano <gitster@pobox.com>2014-10-01 13:53:54 -0700
commit4d423a3e62c7ab0b04c4bd84995c32daff3b24c3 (patch)
tree7d8744732c898c665086d784bd2fce28cd8248d5 /lockfile.c
parentec38b4e482e96e62762452cab5714e55abdb48c3 (diff)
downloadgit-4d423a3e62c7ab0b04c4bd84995c32daff3b24c3.tar.gz
hold_lock_file_for_append(): restore errno before returning
Callers who don't pass LOCK_DIE_ON_ERROR might want to examine errno to see what went wrong, so restore errno before returning. In fact this function only has one caller, add_to_alternates_file(), and it *does* use LOCK_DIE_ON_ERROR, but, you know, think of future generations. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'lockfile.c')
-rw-r--r--lockfile.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/lockfile.c b/lockfile.c
index c51c6ec69d..b2f5d36f7e 100644
--- a/lockfile.c
+++ b/lockfile.c
@@ -243,15 +243,22 @@ int hold_lock_file_for_append(struct lock_file *lk, const char *path, int flags)
orig_fd = open(path, O_RDONLY);
if (orig_fd < 0) {
if (errno != ENOENT) {
+ int save_errno = errno;
+
if (flags & LOCK_DIE_ON_ERROR)
die("cannot open '%s' for copying", path);
rollback_lock_file(lk);
- return error("cannot open '%s' for copying", path);
+ error("cannot open '%s' for copying", path);
+ errno = save_errno;
+ return -1;
}
} else if (copy_fd(orig_fd, fd)) {
+ int save_errno = errno;
+
if (flags & LOCK_DIE_ON_ERROR)
exit(128);
rollback_lock_file(lk);
+ errno = save_errno;
return -1;
}
return fd;