summaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorLars Schneider <larsxschneider@gmail.com>2016-10-24 18:02:59 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-10-25 18:09:54 (GMT)
commitcd66ada06588f797a424dd1f6da1c6bb51de1660 (patch)
tree0dc5420dbe93ec54c0982f320b899c516a7c967c /sha1_file.c
parenta5436b57941d99302a4cf68373da6288c11f0340 (diff)
downloadgit-cd66ada06588f797a424dd1f6da1c6bb51de1660.zip
git-cd66ada06588f797a424dd1f6da1c6bb51de1660.tar.gz
git-cd66ada06588f797a424dd1f6da1c6bb51de1660.tar.bz2
sha1_file: open window into packfiles with O_CLOEXEC
All processes that the Git main process spawns inherit the open file descriptors of the main process. These leaked file descriptors can cause problems. Use the O_CLOEXEC flag similar to 05d1ed61 to fix the leaked file descriptors. Signed-off-by: Lars Schneider <larsxschneider@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/sha1_file.c b/sha1_file.c
index 5d2bcd3..09045df 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1561,7 +1561,7 @@ int check_sha1_signature(const unsigned char *sha1, void *map,
int git_open(const char *name)
{
- static int sha1_file_open_flag = O_NOATIME;
+ static int sha1_file_open_flag = O_NOATIME | O_CLOEXEC;
for (;;) {
int fd;
@@ -1571,12 +1571,17 @@ int git_open(const char *name)
if (fd >= 0)
return fd;
- /* Might the failure be due to O_NOATIME? */
- if (errno != ENOENT && sha1_file_open_flag) {
- sha1_file_open_flag = 0;
+ /* Try again w/o O_CLOEXEC: the kernel might not support it */
+ if ((sha1_file_open_flag & O_CLOEXEC) && errno == EINVAL) {
+ sha1_file_open_flag &= ~O_CLOEXEC;
continue;
}
+ /* Might the failure be due to O_NOATIME? */
+ if (errno != ENOENT && (sha1_file_open_flag & O_NOATIME)) {
+ sha1_file_open_flag &= ~O_NOATIME;
+ continue;
+ }
return -1;
}
}