Skip to content

Commit 9fb9495

Browse files
Eric Wonggitster
authored andcommitted
set FD_CLOEXEC properly when O_CLOEXEC is not supported
FD_CLOEXEC only applies to the file descriptor, so it needs to be manipuluated via F_GETFD/F_SETFD. F_GETFL/F_SETFL are for file description flags. Verified via strace with o_cloexec set to zero. Signed-off-by: Eric Wong <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1e3001a commit 9fb9495

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

sha1_file.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,14 +1571,14 @@ int git_open_cloexec(const char *name, int flags)
15711571
fd = open(name, flags | o_cloexec);
15721572
}
15731573

1574-
#if defined(F_GETFL) && defined(F_SETFL) && defined(FD_CLOEXEC)
1574+
#if defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
15751575
{
15761576
static int fd_cloexec = FD_CLOEXEC;
15771577

15781578
if (!o_cloexec && 0 <= fd && fd_cloexec) {
15791579
/* Opened w/o O_CLOEXEC? try with fcntl(2) to add it */
1580-
int flags = fcntl(fd, F_GETFL);
1581-
if (fcntl(fd, F_SETFL, flags | fd_cloexec))
1580+
int flags = fcntl(fd, F_GETFD);
1581+
if (fcntl(fd, F_SETFD, flags | fd_cloexec))
15821582
fd_cloexec = 0;
15831583
}
15841584
}

0 commit comments

Comments
 (0)