summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@dtucker.net>2020-05-01 15:09:26 +1000
committerDarren Tucker <dtucker@dtucker.net>2020-05-01 15:09:26 +1000
commit6c6072ba8b079e6f5caa38b011a6f4570c14ed38 (patch)
tree44b3f0cc5a5d5cda88c3d8dd2ed063597743cfb8
parent90a0b434ed41f9c505662dba8782591818599cb3 (diff)
See if SA_RESTART signals will interrupt select().
On some platforms (at least older HP-UXes such as 11.11, possibly others) setting SA_RESTART on signal handers will cause it to not interrupt select(), at least for calls that do not specify a timeout. Try to detect this and if found, don't use SA_RESTART. POSIX says "If SA_RESTART has been set for the interrupting signal, it is implementation-dependent whether select() restarts or returns with [EINTR]" so this behaviour is within spec.
-rw-r--r--configure.ac37
-rw-r--r--misc.c2
2 files changed, 39 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 8adfcb347..e696ac751 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2500,6 +2500,43 @@ static void sighandler(int sig) { _exit(1); }
2500 ) 2500 )
2501fi 2501fi
2502 2502
2503AC_MSG_CHECKING([if SA_RESTARTed signals interrupt select()])
2504AC_RUN_IFELSE(
2505 [AC_LANG_PROGRAM([[
2506#ifdef HAVE_SYS_SELECT
2507# include <sys/select.h>
2508#endif
2509#include <sys/types.h>
2510#include <sys/time.h>
2511#include <stdlib.h>
2512#include <signal.h>
2513static void sighandler(int sig) { }
2514 ]], [[
2515 int r;
2516 pid_t pid;
2517 struct sigaction sa;
2518
2519 sa.sa_handler = sighandler;
2520 sa.sa_flags = SA_RESTART;
2521 (void)sigaction(SIGTERM, &sa, NULL);
2522 if ((pid = fork()) == 0) { /* child */
2523 sleep(1);
2524 kill(getppid(), SIGTERM);
2525 sleep(1);
2526 kill(getppid(), SIGKILL);
2527 exit(0);
2528 } else { /* parent */
2529 r = select(0, NULL, NULL, NULL, NULL);
2530 }
2531 exit(r == -1 ? 0 : 1);
2532 ]])],
2533 [AC_MSG_RESULT([yes])],
2534 [AC_MSG_RESULT([no])
2535 AC_DEFINE([NO_SA_RESTART], [1],
2536 [SA_RESTARTed signals do no interrupt select])],
2537 [AC_MSG_WARN([cross compiling: assuming yes])]
2538)
2539
2503AC_CHECK_FUNCS([getpgrp],[ 2540AC_CHECK_FUNCS([getpgrp],[
2504 AC_MSG_CHECKING([if getpgrp accepts zero args]) 2541 AC_MSG_CHECKING([if getpgrp accepts zero args])
2505 AC_COMPILE_IFELSE( 2542 AC_COMPILE_IFELSE(
diff --git a/misc.c b/misc.c
index 506507226..554ceb0b1 100644
--- a/misc.c
+++ b/misc.c
@@ -2258,8 +2258,10 @@ ssh_signal(int signum, sshsig_t handler)
2258 memset(&sa, 0, sizeof(sa)); 2258 memset(&sa, 0, sizeof(sa));
2259 sa.sa_handler = handler; 2259 sa.sa_handler = handler;
2260 sigfillset(&sa.sa_mask); 2260 sigfillset(&sa.sa_mask);
2261#if defined(SA_RESTART) && !defined(NO_SA_RESTART)
2261 if (signum != SIGALRM) 2262 if (signum != SIGALRM)
2262 sa.sa_flags = SA_RESTART; 2263 sa.sa_flags = SA_RESTART;
2264#endif
2263 if (sigaction(signum, &sa, &osa) == -1) { 2265 if (sigaction(signum, &sa, &osa) == -1) {
2264 debug3("sigaction(%s): %s", strsignal(signum), strerror(errno)); 2266 debug3("sigaction(%s): %s", strsignal(signum), strerror(errno));
2265 return SIG_ERR; 2267 return SIG_ERR;