]> Savannah Git Hosting - gnulib.git/commitdiff
execute: Treat signalled processes like wait-process does.
authorBruno Haible <bruno@clisp.org>
Thu, 24 Dec 2020 18:04:57 +0000 (19:04 +0100)
committerBruno Haible <bruno@clisp.org>
Thu, 24 Dec 2020 18:04:57 +0000 (19:04 +0100)
* lib/execute.c: Include <sys/types.h>, <sys/wait.h>.
(execute): Recognize the case where the exit code indicates a signalled
child process.
* tests/test-execute-main.c (main): Update expected test result.
* modules/execute (Depends-on): Add sys_wait.

ChangeLog
lib/execute.c
modules/execute
tests/test-execute-main.c

index b0e4ad5e448fe85a7f0d7a44b6d61dfb7eea50fe..397bd7dbdd0957456f9eb691ff0f56c4a43611d0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2020-12-24  Bruno Haible  <bruno@clisp.org>
+
+       execute: Treat signalled processes like wait-process does.
+       * lib/execute.c: Include <sys/types.h>, <sys/wait.h>.
+       (execute): Recognize the case where the exit code indicates a signalled
+       child process.
+       * tests/test-execute-main.c (main): Update expected test result.
+       * modules/execute (Depends-on): Add sys_wait.
+
 2020-12-24  Bruno Haible  <bruno@clisp.org>
 
        windows-spawn: Improve errno upon failure on native Windows.
index 38dd07bcef3283c6c945c8caee0dacb15fde579b..4cc779e4acc832d75260dd03697a768ae784ae9c 100644 (file)
@@ -28,6 +28,9 @@
 #include <signal.h>
 #include <unistd.h>
 
+#include <sys/types.h>
+#include <sys/wait.h>
+
 #include "canonicalize.h"
 #include "error.h"
 #include "fatal-signal.h"
@@ -214,12 +217,22 @@ execute (const char *progname,
   free (argv_mem_to_free);
   free (prog_path_to_free);
 
+  /* Treat failure and signalled child processes like wait_subprocess()
+     does.  */
   if (termsigp != NULL)
     *termsigp = 0;
 
   if (exitcode == -1)
     goto fail_with_saved_errno;
 
+  if (WIFSIGNALED (exitcode))
+    {
+      if (termsigp != NULL)
+        *termsigp = WTERMSIG (exitcode);
+      saved_errno = 0;
+      goto fail_with_saved_errno;
+    }
+
   return exitcode;
 
 #else
index 90a7b89c3c8413cce2e6f69281398e560f5e6678..434558050e10dfc3a5140f6aedeba23c5c2a5e9e 100644 (file)
@@ -29,6 +29,7 @@ posix_spawnattr_setflags
 posix_spawnattr_destroy
 stdbool
 stdlib
+sys_wait
 unistd
 wait-process
 windows-spawn
index c58a62dcae6e63c9ab12952b96b9a1a971e491b7..29a4c309d1f7e5d2f45bf2123e43b3d129868d2b 100644 (file)
@@ -135,11 +135,10 @@ main (int argc, char *argv[])
         int termsig = 0xDEADBEEF;
         int ret = execute (progname, prog_argv[0], prog_argv, NULL,
                            false, false, false, false, true, false, &termsig);
+        ASSERT (ret == 127);
         #if defined _WIN32 && !defined __CYGWIN__
-        ASSERT (ret == 3);
-        ASSERT (termsig == 0);
+        ASSERT (termsig == SIGTERM); /* dummy, from WTERMSIG in <sys/wait.h> */
         #else
-        ASSERT (ret == 127);
         ASSERT (termsig == SIGINT);
         #endif
       }