summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Clemens Buchacher <clemens.buchacher@intel.com>2015-08-04 10:24:29 +0200
committerLibravatar Junio C Hamano <gitster@pobox.com>2015-08-12 13:56:19 -0700
commitdff6f280dff2b1d0d379ed0e73058819702d0f07 (patch)
treed5fd7e68b9a57d94f6567ac4966c0c884bab2504
parentGit 2.2.2 (diff)
downloadtgif-dff6f280dff2b1d0d379ed0e73058819702d0f07.tar.xz
git_open_noatime: return with errno=0 on success
In read_sha1_file_extended we die if read_object fails with a fatal error. We detect a fatal error if errno is non-zero and is not ENOENT. If the object could not be read because it does not exist, this is not considered a fatal error and we want to return NULL. Somewhere down the line, read_object calls git_open_noatime to open a pack index file, for example. We first try open with O_NOATIME. If O_NOATIME fails with EPERM, we retry without O_NOATIME. When the second open succeeds, errno is however still set to EPERM from the first attempt. When we finally determine that the object does not exist, read_object returns NULL and read_sha1_file_extended dies with a fatal error: fatal: failed to read object <sha1>: Operation not permitted Fix this by resetting errno to zero before we call open again. Cc: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Clemens Buchacher <clemens.buchacher@intel.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--sha1_file.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/sha1_file.c b/sha1_file.c
index d7f1838c13..3502dcf666 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1446,7 +1446,10 @@ int git_open_noatime(const char *name)
static int sha1_file_open_flag = O_NOATIME;
for (;;) {
- int fd = open(name, O_RDONLY | sha1_file_open_flag);
+ int fd;
+
+ errno = 0;
+ fd = open(name, O_RDONLY | sha1_file_open_flag);
if (fd >= 0)
return fd;