Skip to content

Commit 921846f

Browse files
committed
Merge branch 'jk/open-returns-eintr'
Work around platforms whose open() is reported to return EINTR (it shouldn't, as we do our signals with SA_RESTART). * jk/open-returns-eintr: config.mak.uname: enable OPEN_RETURNS_EINTR for macOS Big Sur Makefile: add OPEN_RETURNS_EINTR knob
2 parents 85c787f + bbabaad commit 921846f

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ all::
2222
# when attempting to read from an fopen'ed directory (or even to fopen
2323
# it at all).
2424
#
25+
# Define OPEN_RETURNS_EINTR if your open() system call may return EINTR
26+
# when a signal is received (as opposed to restarting).
27+
#
2528
# Define NO_OPENSSL environment variable if you do not have OpenSSL.
2629
#
2730
# Define USE_LIBPCRE if you have and want to use libpcre. Various
@@ -1539,6 +1542,10 @@ ifdef FREAD_READS_DIRECTORIES
15391542
COMPAT_CFLAGS += -DFREAD_READS_DIRECTORIES
15401543
COMPAT_OBJS += compat/fopen.o
15411544
endif
1545+
ifdef OPEN_RETURNS_EINTR
1546+
COMPAT_CFLAGS += -DOPEN_RETURNS_EINTR
1547+
COMPAT_OBJS += compat/open.o
1548+
endif
15421549
ifdef NO_SYMLINK_HEAD
15431550
BASIC_CFLAGS += -DNO_SYMLINK_HEAD
15441551
endif

compat/mingw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ int mingw_rmdir(const char *path);
227227

228228
int mingw_open (const char *filename, int oflags, ...);
229229
#define open mingw_open
230+
#undef OPEN_RETURNS_EINTR
230231

231232
int mingw_fgetc(FILE *stream);
232233
#define fgetc mingw_fgetc

compat/open.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "git-compat-util.h"
2+
3+
#undef open
4+
int git_open_with_retry(const char *path, int flags, ...)
5+
{
6+
mode_t mode = 0;
7+
int ret;
8+
9+
/*
10+
* Also O_TMPFILE would take a mode, but it isn't defined everywhere.
11+
* And anyway, we don't use it in our code base.
12+
*/
13+
if (flags & O_CREAT) {
14+
va_list ap;
15+
va_start(ap, flags);
16+
mode = va_arg(ap, int);
17+
va_end(ap);
18+
}
19+
20+
do {
21+
ret = open(path, flags, mode);
22+
} while (ret < 0 && errno == EINTR);
23+
24+
return ret;
25+
}

config.mak.uname

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ ifeq ($(uname_S),Darwin)
124124
ifeq ($(shell test "`expr "$(uname_R)" : '\([0-9][0-9]*\)\.'`" -ge 11 && echo 1),1)
125125
HAVE_GETDELIM = YesPlease
126126
endif
127+
ifeq ($(shell test "`expr "$(uname_R)" : '\([0-9][0-9]*\)\.'`" -ge 20 && echo 1),1)
128+
OPEN_RETURNS_EINTR = UnfortunatelyYes
129+
endif
127130
NO_MEMMEM = YesPlease
128131
USE_ST_TIMESPEC = YesPlease
129132
HAVE_DEV_TTY = YesPlease

git-compat-util.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,12 @@ int git_vsnprintf(char *str, size_t maxsize,
788788
const char *format, va_list ap);
789789
#endif
790790

791+
#ifdef OPEN_RETURNS_EINTR
792+
#undef open
793+
#define open git_open_with_retry
794+
int git_open_with_retry(const char *path, int flag, ...);
795+
#endif
796+
791797
#ifdef __GLIBC_PREREQ
792798
#if __GLIBC_PREREQ(2, 1)
793799
#define HAVE_STRCHRNUL

0 commit comments

Comments
 (0)