Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 09ee60c

Browse files
author
Vicent Martí
committed
Merge pull request libgit2#1670 from arrbee/open-cloexec
Add O_CLOEXEC to open calls
2 parents 6c4dadb + 3d3ea4d commit 09ee60c

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/fileops.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ int git_futils_creat_locked(const char *path, const mode_t mode)
6161
wchar_t buf[GIT_WIN_PATH];
6262

6363
git__utf8_to_16(buf, GIT_WIN_PATH, path);
64-
fd = _wopen(buf, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_EXCL, mode);
64+
fd = _wopen(buf, O_WRONLY | O_CREAT | O_TRUNC |
65+
O_EXCL | O_BINARY | O_CLOEXEC, mode);
6566
#else
66-
fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_EXCL, mode);
67+
fd = open(path, O_WRONLY | O_CREAT | O_TRUNC |
68+
O_EXCL | O_BINARY | O_CLOEXEC, mode);
6769
#endif
6870

6971
if (fd < 0) {

src/posix.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ int p_open(const char *path, int flags, ...)
111111
va_end(arg_list);
112112
}
113113

114-
return open(path, flags | O_BINARY, mode);
114+
return open(path, flags | O_BINARY | O_CLOEXEC, mode);
115115
}
116116

117117
int p_creat(const char *path, mode_t mode)
118118
{
119-
return open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode);
119+
return open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_CLOEXEC, mode);
120120
}
121121

122122
int p_getcwd(char *buffer_out, size_t size)

src/posix.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
#if !defined(O_BINARY)
2626
#define O_BINARY 0
2727
#endif
28+
#if !defined(O_CLOEXEC)
29+
#define O_CLOEXEC 0
30+
#endif
2831

2932
typedef int git_file;
3033

0 commit comments

Comments
 (0)