Skip to content

Commit d0dae92

Browse files
carenasgitster
authored andcommitted
compat/posix.h: track SA_RESTART fallback
Systems without SA_RESTART are using custom CFLAGS or headers instead of the standard header file. Correct that, and invent a Makefile variable to track the exceptions which will become handy in the next commits. Signed-off-by: Carlo Marcelo Arenas Belón <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cb3b403 commit d0dae92

File tree

6 files changed

+39
-4
lines changed

6 files changed

+39
-4
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ include shared.mak
3737
# when attempting to read from an fopen'ed directory (or even to fopen
3838
# it at all).
3939
#
40+
# Define USE_NON_POSIX_SIGNAL if don't have support for SA_RESTART or
41+
# prefer to use ANSI C signal() over POSIX sigaction()
42+
#
4043
# Define OPEN_RETURNS_EINTR if your open() system call may return EINTR
4144
# when a signal is received (as opposed to restarting).
4245
#
@@ -1811,6 +1814,9 @@ ifdef FREAD_READS_DIRECTORIES
18111814
COMPAT_CFLAGS += -DFREAD_READS_DIRECTORIES
18121815
COMPAT_OBJS += compat/fopen.o
18131816
endif
1817+
ifdef USE_NON_POSIX_SIGNAL
1818+
COMPAT_CFLAGS += -DUSE_NON_POSIX_SIGNAL
1819+
endif
18141820
ifdef OPEN_RETURNS_EINTR
18151821
COMPAT_CFLAGS += -DOPEN_RETURNS_EINTR
18161822
endif

compat/mingw-posix.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ struct sigaction {
9595
sig_handler_t sa_handler;
9696
unsigned sa_flags;
9797
};
98-
#define SA_RESTART 0
9998

10099
struct itimerval {
101100
struct timeval it_value, it_interval;

compat/posix.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,14 @@ char *gitdirname(char *);
250250
#define NAME_MAX 255
251251
#endif
252252

253+
/*
254+
* On most systems <signal.h> would have given us this, but
255+
* not on some systems (e.g. NonStop, QNX).
256+
*/
257+
#ifndef SA_RESTART
258+
# define SA_RESTART 0 /* disabled for sigaction() */
259+
#endif
260+
253261
typedef uintmax_t timestamp_t;
254262
#define PRItime PRIuMAX
255263
#define parse_timestamp strtoumax

config.mak.uname

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ ifeq ($(uname_S),Windows)
486486
NO_STRTOUMAX = YesPlease
487487
NO_MKDTEMP = YesPlease
488488
NO_INTTYPES_H = YesPlease
489+
USE_NON_POSIX_SIGNAL = YesPlease
489490
CSPRNG_METHOD = rtlgenrandom
490491
# VS2015 with UCRT claims that snprintf and friends are C99 compliant,
491492
# so we don't need this:
@@ -654,8 +655,6 @@ ifeq ($(uname_S),NONSTOP_KERNEL)
654655
FREAD_READS_DIRECTORIES = UnfortunatelyYes
655656

656657
# Not detected (nor checked for) by './configure'.
657-
# We don't have SA_RESTART on NonStop, unfortunalety.
658-
COMPAT_CFLAGS += -DSA_RESTART=0
659658
# Apparently needed in compat/fnmatch/fnmatch.c.
660659
COMPAT_CFLAGS += -DHAVE_STRING_H=1
661660
NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease
@@ -664,6 +663,7 @@ ifeq ($(uname_S),NONSTOP_KERNEL)
664663
NO_MMAP = YesPlease
665664
NO_POLL = YesPlease
666665
NO_INTPTR_T = UnfortunatelyYes
666+
USE_NON_POSIX_SIGNAL = UnfortunatelyYes
667667
CSPRNG_METHOD = openssl
668668
SANE_TOOL_PATH = /usr/coreutils/bin:/usr/local/bin
669669
SHELL_PATH = /usr/coreutils/bin/bash
@@ -699,6 +699,7 @@ ifeq ($(uname_S),MINGW)
699699
NEEDS_LIBICONV = YesPlease
700700
NO_STRTOUMAX = YesPlease
701701
NO_MKDTEMP = YesPlease
702+
USE_NON_POSIX_SIGNAL = YesPlease
702703
NO_SVN_TESTS = YesPlease
703704

704705
# The builtin FSMonitor requires Named Pipes and Threads on Windows.
@@ -782,7 +783,6 @@ ifeq ($(uname_S),MINGW)
782783
endif
783784
endif
784785
ifeq ($(uname_S),QNX)
785-
COMPAT_CFLAGS += -DSA_RESTART=0
786786
EXPAT_NEEDS_XMLPARSE_H = YesPlease
787787
HAVE_STRINGS_H = YesPlease
788788
NEEDS_SOCKET = YesPlease
@@ -794,4 +794,5 @@ ifeq ($(uname_S),QNX)
794794
NO_PTHREADS = YesPlease
795795
NO_STRCASESTR = YesPlease
796796
NO_STRLCPY = YesPlease
797+
USE_NON_POSIX_SIGNAL = UnfortunatelyYes
797798
endif

configure.ac

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,23 @@ fi
862862
GIT_CONF_SUBST([ICONV_OMITS_BOM])
863863
fi
864864

865+
# Define USE_NON_POSIX_SIGNAL if don't have support for SA_RESTART or
866+
# prefer using ANSI C signal() over POSIX sigaction()
867+
868+
AC_CACHE_CHECK([whether SA_RESTART is supported], [ac_cv_siginterrupt], [
869+
AC_COMPILE_IFELSE(
870+
[AC_LANG_PROGRAM([#include <signal.h>], [[
871+
#ifdef SA_RESTART
872+
#endif
873+
siginterrupt(SIGCHLD, 1)
874+
]])],[ac_cv_siginterrupt=yes],[
875+
ac_cv_siginterrupt=no
876+
USE_NON_POSIX_SIGNAL=UnfortunatelyYes
877+
]
878+
)
879+
])
880+
GIT_CONF_SUBST([USE_NON_POSIX_SIGNAL])
881+
865882
## Checks for typedefs, structures, and compiler characteristics.
866883
AC_MSG_NOTICE([CHECKS for typedefs, structures, and compiler characteristics])
867884
#

meson.build

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,10 @@ else
10941094
build_options_config.set('NO_EXPAT', '1')
10951095
endif
10961096

1097+
if compiler.get_define('SA_RESTART', prefix: '#include <signal.h>') == ''
1098+
libgit_c_args += '-DUSE_NON_POSIX_SIGNAL'
1099+
endif
1100+
10971101
if not compiler.has_header('sys/select.h')
10981102
libgit_c_args += '-DNO_SYS_SELECT_H'
10991103
endif

0 commit comments

Comments
 (0)