]> Savannah Git Hosting - gnulib.git/commitdiff
execute: Fix uninitialized use of errno.
authorBruno Haible <bruno@clisp.org>
Tue, 1 Dec 2020 02:59:57 +0000 (03:59 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 1 Dec 2020 02:59:57 +0000 (03:59 +0100)
* lib/execute.c (execute): Preserve errno across several system calls.

ChangeLog
lib/execute.c

index b08614eb261ad00765439e87f3eef1e41e63967d..41c85c01c93140ef06d7bcfacfc6ce49d9ac63c6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2020-11-30  Bruno Haible  <bruno@clisp.org>
+
+       execute: Fix uninitialized use of errno.
+       * lib/execute.c (execute): Preserve errno across several system calls.
+
 2020-11-30  Bruno Haible  <bruno@clisp.org>
 
        access tests: Fix test failure on native Windows.
index 149cc894546ed0a87969cb61b7b384b0aca3734c..15556cf7915fa7d29093a79b711122072d32693c 100644 (file)
@@ -103,6 +103,8 @@ execute (const char *progname,
 
   /* Native Windows API.  */
 
+  int saved_errno;
+
   /* FIXME: Need to free memory allocated by prepare_spawn.  */
   prog_argv = prepare_spawn (prog_argv);
 
@@ -144,6 +146,8 @@ execute (const char *progname,
                                  stdin_handle, stdout_handle, stderr_handle);
         }
     }
+  if (exitcode == -1)
+    saved_errno = errno;
   if (nulloutfd >= 0)
     close (nulloutfd);
   if (nullinfd >= 0)
@@ -155,7 +159,7 @@ execute (const char *progname,
   if (exitcode == -1)
     {
       if (exit_on_error || !null_stderr)
-        error (exit_on_error ? EXIT_FAILURE : 0, errno,
+        error (exit_on_error ? EXIT_FAILURE : 0, saved_errno,
                _("%s subprocess failed"), progname);
       return 127;
     }