Bump to m4 1.4.19
[platform/upstream/m4.git] / lib / wait-process.c
index 17a2430..bbf5de2 100644 (file)
@@ -1,5 +1,5 @@
 /* Waiting for a subprocess to finish.
-   Copyright (C) 2001-2003, 2005-2013 Free Software Foundation, Inc.
+   Copyright (C) 2001-2003, 2005-2021 Free Software Foundation, Inc.
    Written by Bruno Haible <haible@clisp.cons.org>, 2001.
 
    This program is free software: you can redistribute it and/or modify
@@ -13,7 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
 
 
 #include <config.h>
 #define SIZEOF(a) (sizeof(a) / sizeof(a[0]))
 
 
-#if defined _MSC_VER || defined __MINGW32__
+#if defined _WIN32 && ! defined __CYGWIN__
 
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
 
-/* The return value of spawnvp() is really a process handle as returned
+/* The return value of _spawnvp() is really a process handle as returned
    by CreateProcess().  Therefore we can kill it using TerminateProcess.  */
-#define kill(pid,sig) TerminateProcess ((HANDLE) (pid), sig)
+# define kill(pid,sig) TerminateProcess ((HANDLE) (pid), sig)
 
 #endif
 
@@ -80,7 +80,7 @@ static size_t slaves_allocated = SIZEOF (static_slaves);
 #endif
 
 /* The cleanup action.  It gets called asynchronously.  */
-static void
+static _GL_ASYNC_SAFE void
 cleanup_slaves (void)
 {
   for (;;)
@@ -102,6 +102,14 @@ cleanup_slaves (void)
     }
 }
 
+/* The cleanup action, taking a signal argument.
+   It gets called asynchronously.  */
+static _GL_ASYNC_SAFE void
+cleanup_slaves_action (int sig _GL_UNUSED)
+{
+  cleanup_slaves ();
+}
+
 /* Register a subprocess as being a slave process.  This means that the
    subprocess will be terminated when its creator receives a catchable fatal
    signal or exits normally.  Registration ends when wait_subprocess()
@@ -113,7 +121,8 @@ register_slave_subprocess (pid_t child)
   if (!cleanup_slaves_registered)
     {
       atexit (cleanup_slaves);
-      at_fatal_signal (cleanup_slaves);
+      if (at_fatal_signal (cleanup_slaves_action) < 0)
+        xalloc_die ();
       cleanup_slaves_registered = true;
     }