mirror of
https://github.com/git/git
synced 2024-08-27 11:39:22 +00:00
Merge branch 'ew/fd-cloexec-fix'
Portability/fallback fix. * ew/fd-cloexec-fix: set FD_CLOEXEC properly when O_CLOEXEC is not supported
This commit is contained in:
commit
2842e06352
|
@ -1684,14 +1684,14 @@ int git_open_cloexec(const char *name, int flags)
|
||||||
fd = open(name, flags | o_cloexec);
|
fd = open(name, flags | o_cloexec);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(F_GETFL) && defined(F_SETFL) && defined(FD_CLOEXEC)
|
#if defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
|
||||||
{
|
{
|
||||||
static int fd_cloexec = FD_CLOEXEC;
|
static int fd_cloexec = FD_CLOEXEC;
|
||||||
|
|
||||||
if (!o_cloexec && 0 <= fd && fd_cloexec) {
|
if (!o_cloexec && 0 <= fd && fd_cloexec) {
|
||||||
/* Opened w/o O_CLOEXEC? try with fcntl(2) to add it */
|
/* Opened w/o O_CLOEXEC? try with fcntl(2) to add it */
|
||||||
int flags = fcntl(fd, F_GETFL);
|
int flags = fcntl(fd, F_GETFD);
|
||||||
if (fcntl(fd, F_SETFL, flags | fd_cloexec))
|
if (fcntl(fd, F_SETFD, flags | fd_cloexec))
|
||||||
fd_cloexec = 0;
|
fd_cloexec = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue