Merge pull request #1670 from arrbee/open-cloexec Add O_CLOEXEC to open calls
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
diff --git a/src/fileops.c b/src/fileops.c
index 95b15c6..d5f6acf 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -61,9 +61,11 @@ int git_futils_creat_locked(const char *path, const mode_t mode)
wchar_t buf[GIT_WIN_PATH];
git__utf8_to_16(buf, GIT_WIN_PATH, path);
- fd = _wopen(buf, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_EXCL, mode);
+ fd = _wopen(buf, O_WRONLY | O_CREAT | O_TRUNC |
+ O_EXCL | O_BINARY | O_CLOEXEC, mode);
#else
- fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_EXCL, mode);
+ fd = open(path, O_WRONLY | O_CREAT | O_TRUNC |
+ O_EXCL | O_BINARY | O_CLOEXEC, mode);
#endif
if (fd < 0) {
diff --git a/src/posix.c b/src/posix.c
index 5d526d3..b75109b 100644
--- a/src/posix.c
+++ b/src/posix.c
@@ -111,12 +111,12 @@ int p_open(const char *path, int flags, ...)
va_end(arg_list);
}
- return open(path, flags | O_BINARY, mode);
+ return open(path, flags | O_BINARY | O_CLOEXEC, mode);
}
int p_creat(const char *path, mode_t mode)
{
- return open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode);
+ return open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_CLOEXEC, mode);
}
int p_getcwd(char *buffer_out, size_t size)
diff --git a/src/posix.h b/src/posix.h
index 719c8a0..40bcc1a 100644
--- a/src/posix.h
+++ b/src/posix.h
@@ -25,6 +25,9 @@
#if !defined(O_BINARY)
#define O_BINARY 0
#endif
+#if !defined(O_CLOEXEC)
+#define O_CLOEXEC 0
+#endif
typedef int git_file;