diff options
author | Andrew J. Schorr <aschorr@telemetry-investments.com> | 2013-07-07 12:57:40 -0400 |
---|---|---|
committer | Andrew J. Schorr <aschorr@telemetry-investments.com> | 2013-07-07 12:57:40 -0400 |
commit | faf3affc19f760a330153b22a8e56fc9a13a0cb6 (patch) | |
tree | dd00789c54a6b35a6dda2da7f8a0acd268d715ea | |
parent | 2376c18714fe197fbf56a19f8271e5f256ec7caf (diff) | |
download | egawk-faf3affc19f760a330153b22a8e56fc9a13a0cb6.tar.gz egawk-faf3affc19f760a330153b22a8e56fc9a13a0cb6.tar.bz2 egawk-faf3affc19f760a330153b22a8e56fc9a13a0cb6.zip |
In io.c:wait_any, use sigprocmask if available.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | configh.in | 3 | ||||
-rwxr-xr-x | configure | 3 | ||||
-rw-r--r-- | configure.ac | 3 | ||||
-rw-r--r-- | io.c | 27 |
5 files changed, 39 insertions, 3 deletions
@@ -1,3 +1,9 @@ +2013-07-07 Andrew J. Schorr <aschorr@telemetry-investments.com> + + * configure.ac (AC_CHECK_FUNCS): Check for sigprocmask. + * io.c (wait_any): If sigprocmask is available, block signals instead + of ignoring them temporarily. + 2013-07-05 Andrew J. Schorr <aschorr@telemetry-investments.com> * gawkapi.h (gawk_api): Document that the api_get_file function will not @@ -171,6 +171,9 @@ /* Define to 1 if you have the `setsid' function. */ #undef HAVE_SETSID +/* Define to 1 if you have the `sigprocmask' function. */ +#undef HAVE_SIGPROCMASK + /* Define to 1 if you have the `snprintf' function. */ #undef HAVE_SNPRINTF @@ -10018,7 +10018,8 @@ esac for ac_func in atexit btowc fmod getgrent getgroups grantpt \ isascii iswctype iswlower iswupper mbrlen \ memcmp memcpy memcpy_ulong memmove memset \ - memset_ulong mkstemp posix_openpt setenv setlocale setsid snprintf strchr \ + memset_ulong mkstemp posix_openpt setenv setlocale setsid sigprocmask \ + snprintf strchr \ strerror strftime strncasecmp strcoll strtod strtoul \ system tmpfile towlower towupper tzset usleep waitpid wcrtomb \ wcscoll wctype diff --git a/configure.ac b/configure.ac index ba242c51..9f2878b0 100644 --- a/configure.ac +++ b/configure.ac @@ -274,7 +274,8 @@ esac AC_CHECK_FUNCS(atexit btowc fmod getgrent getgroups grantpt \ isascii iswctype iswlower iswupper mbrlen \ memcmp memcpy memcpy_ulong memmove memset \ - memset_ulong mkstemp posix_openpt setenv setlocale setsid snprintf strchr \ + memset_ulong mkstemp posix_openpt setenv setlocale setsid sigprocmask \ + snprintf strchr \ strerror strftime strncasecmp strcoll strtod strtoul \ system tmpfile towlower towupper tzset usleep waitpid wcrtomb \ wcscoll wctype) @@ -2177,17 +2177,34 @@ use_pipes: * * Note: on platforms that do not support waitpid with WNOHANG, when called with * a zero argument, this function will hang until all children have exited. + * + * AJS, 2013-07-07: I do not see why we need to ignore signals during this + * function. This function just waits and updates the pid and status fields. + * I don't see why that should interfere with any signal handlers. But I am + * reluctant to remove this protection. So I changed to use sigprocmask to + * block signals instead to avoid interfering with installed signal handlers. */ static int wait_any(int interesting) /* pid of interest, if any */ { - RETSIGTYPE (*hstat)(int), (*istat)(int), (*qstat)(int); int pid; int status = 0; struct redirect *redp; +#ifdef HAVE_SIGPROCMASK + sigset_t set, oldset; + + /* I have no idea why we are blocking signals during this function... */ + sigemptyset(& set); + sigaddset(& set, SIGINT); + sigaddset(& set, SIGHUP); + sigaddset(& set, SIGQUIT); + sigprocmask(SIG_BLOCK, & set, & oldset); +#else + RETSIGTYPE (*hstat)(int), (*istat)(int), (*qstat)(int); istat = signal(SIGINT, SIG_IGN); +#endif #ifdef __MINGW32__ if (interesting < 0) { status = -1; @@ -2204,8 +2221,10 @@ wait_any(int interesting) /* pid of interest, if any */ } } #else +#ifndef HAVE_SIGPROCMASK hstat = signal(SIGHUP, SIG_IGN); qstat = signal(SIGQUIT, SIG_IGN); +#endif for (;;) { # if defined(HAVE_WAITPID) && defined(WNOHANG) if ((pid = waitpid(-1, & status, WNOHANG)) == 0) @@ -2229,10 +2248,16 @@ wait_any(int interesting) /* pid of interest, if any */ if (pid == -1 && errno == ECHILD) break; } +#ifndef HAVE_SIGPROCMASK signal(SIGHUP, hstat); signal(SIGQUIT, qstat); #endif +#endif +#ifndef HAVE_SIGPROCMASK signal(SIGINT, istat); +#else + sigprocmask(SIG_SETMASK, & oldset, NULL); +#endif return status; } |