]> Savannah Git Hosting - gnulib.git/commitdiff
windows-spawn: Improve errno upon failure on native Windows.
authorBruno Haible <bruno@clisp.org>
Thu, 24 Dec 2020 17:19:08 +0000 (18:19 +0100)
committerBruno Haible <bruno@clisp.org>
Thu, 24 Dec 2020 17:19:08 +0000 (18:19 +0100)
* lib/windows-spawn.c (spawnpvech): Map the CreateProcess errors
ERROR_BAD_FORMAT and ERROR_BAD_EXE_FORMAT to ENOEXEC.
* tests/executable-script.sh: New file.
* tests/test-posix_spawn-script.c (main): Also try executing
executable-script.sh.
* tests/test-posix_spawnp-script.c (main): Likewise.
* tests/test-execute-script.c (main): Likewise.
* tests/test-spawn-pipe-script.c (main): Likewise.
* modules/posix_spawn-tests (Files): Add tests/executable-script.sh.
* modules/posix_spawnp-tests (Files): Likewise.
* modules/execute-tests (Files): Likewise.
* modules/spawn-pipe-tests (Files): Likewise.

ChangeLog
lib/windows-spawn.c
modules/execute-tests
modules/posix_spawn-tests
modules/posix_spawnp-tests
modules/spawn-pipe-tests
tests/executable-script.sh [new file with mode: 0755]
tests/test-execute-script.c
tests/test-posix_spawn-script.c
tests/test-posix_spawnp-script.c
tests/test-spawn-pipe-script.c

index 72eb5023933510430589dbbaf704df889e92ffa3..b0e4ad5e448fe85a7f0d7a44b6d61dfb7eea50fe 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2020-12-24  Bruno Haible  <bruno@clisp.org>
+
+       windows-spawn: Improve errno upon failure on native Windows.
+       * lib/windows-spawn.c (spawnpvech): Map the CreateProcess errors
+       ERROR_BAD_FORMAT and ERROR_BAD_EXE_FORMAT to ENOEXEC.
+       * tests/executable-script.sh: New file.
+       * tests/test-posix_spawn-script.c (main): Also try executing
+       executable-script.sh.
+       * tests/test-posix_spawnp-script.c (main): Likewise.
+       * tests/test-execute-script.c (main): Likewise.
+       * tests/test-spawn-pipe-script.c (main): Likewise.
+       * modules/posix_spawn-tests (Files): Add tests/executable-script.sh.
+       * modules/posix_spawnp-tests (Files): Likewise.
+       * modules/execute-tests (Files): Likewise.
+       * modules/spawn-pipe-tests (Files): Likewise.
+
 2020-12-24  Bruno Haible  <bruno@clisp.org>
 
        findprog-in: Improve errno upon failure on native Windows.
index 19251aea970e36959758342412f1ebe51ca400b4..0385b1ce1e46d3d0ce9c516b7e6242a7bfa2ff23 100644 (file)
@@ -482,6 +482,11 @@ spawnpvech (int mode,
           errno = ENAMETOOLONG;
           break;
 
+        case ERROR_BAD_FORMAT:
+        case ERROR_BAD_EXE_FORMAT:
+          errno = ENOEXEC;
+          break;
+
         default:
           errno = EINVAL;
           break;
index 2213a3225abe85b396c1e42975dc64847f35152f..422c1abe728fea4f62b7d39be20dcf3f7149d60a 100644 (file)
@@ -4,6 +4,7 @@ tests/test-execute-main.c
 tests/test-execute-child.c
 tests/test-execute-script.c
 tests/executable-script
+tests/executable-script.sh
 tests/executable-shell-script
 tests/macros.h
 
index 451dbd1ec47554ce45c9a227141fb58b9a541560..06a843496740d30dfd7a86f23f49a253ffcabb07 100644 (file)
@@ -5,6 +5,7 @@ tests/test-posix_spawn-inherit0.c
 tests/test-posix_spawn-inherit1.c
 tests/test-posix_spawn-script.c
 tests/executable-script
+tests/executable-script.sh
 tests/executable-shell-script
 tests/signature.h
 
index 04ccdbb6cd8a966fd9e395700b9578da02e455d9..887569c60507d849565a391a3b782dd66df5d404 100644 (file)
@@ -5,6 +5,7 @@ tests/test-posix_spawn-dup2-stdin.c
 tests/test-posix_spawn-dup2-stdin.in.sh
 tests/test-posix_spawnp-script.c
 tests/executable-script
+tests/executable-script.sh
 tests/executable-shell-script
 tests/signature.h
 
index 80614a93bcfb51966545061624ed9271fc686952..5dbd28d74a5d5698c8dc1c3e02c362bf9e7018f2 100644 (file)
@@ -4,6 +4,7 @@ tests/test-spawn-pipe-main.c
 tests/test-spawn-pipe-child.c
 tests/test-spawn-pipe-script.c
 tests/executable-script
+tests/executable-script.sh
 tests/executable-shell-script
 tests/macros.h
 
diff --git a/tests/executable-script.sh b/tests/executable-script.sh
new file mode 100755 (executable)
index 0000000..993f41c
--- /dev/null
@@ -0,0 +1,4 @@
+printf 'Halle '
+printf "Potta"
+# This script is intentionally not immediately recognizable as a shell script.
+# Don't add a #! header in the first line.
index 060f0c5fd1cc990e193497eca0b6f368bacb1d12..aff92361ff5a92c6e2db2856880787ce2024377f 100644 (file)
@@ -48,13 +48,20 @@ main ()
   ASSERT (fp != NULL);
 
   {
-    const char *progname = "executable-script";
-    const char *prog_path = SRCDIR "executable-script";
-    const char *prog_argv[2] = { prog_path, NULL };
-
-    int ret = execute (progname, prog_argv[0], prog_argv, NULL,
-                       false, false, false, false, true, false, NULL);
-    ASSERT (ret == 127);
+    size_t i;
+
+    for (i = 0; i < 2; i++)
+      {
+        const char *progname =
+          (i == 0 ? "executable-script" : "executable-script.sh");
+        const char *prog_path =
+          (i == 0 ? SRCDIR "executable-script" : SRCDIR "executable-script.sh");
+        const char *prog_argv[2] = { prog_path, NULL };
+
+        int ret = execute (progname, prog_argv[0], prog_argv, NULL,
+                           false, false, false, false, true, false, NULL);
+        ASSERT (ret == 127);
+      }
   }
 
 #if defined _WIN32 && !defined __CYGWIN__
index a632841d8e34a40079feb49cafde74fb85ffac31..e17c3b84ff44be4a6786f351d4c8bd02fa505ee9 100644 (file)
@@ -52,34 +52,40 @@ main ()
           == 0);
 
   {
-    const char *prog_path = SRCDIR "executable-script";
-    const char *prog_argv[2] = { prog_path, NULL };
+    size_t i;
 
-    int err = posix_spawn (&child, prog_path, &actions, NULL,
-                           (char **) prog_argv, environ);
-    if (err != ENOEXEC)
+    for (i = 0; i < 2; i++)
       {
-        if (err != 0)
-          {
-            errno = err;
-            perror ("posix_spawn");
-            return 1;
-          }
+        const char *prog_path =
+          (i == 0 ? SRCDIR "executable-script" : SRCDIR "executable-script.sh");
+        const char *prog_argv[2] = { prog_path, NULL };
 
-        /* Wait for child.  */
-        int status = 0;
-        while (waitpid (child, &status, 0) != child)
-          ;
-        if (!WIFEXITED (status))
-          {
-            fprintf (stderr, "subprocess terminated with unexpected wait status %d\n", status);
-            return 1;
-          }
-        int exitstatus = WEXITSTATUS (status);
-        if (exitstatus != 127)
+        int err = posix_spawn (&child, prog_path, &actions, NULL,
+                               (char **) prog_argv, environ);
+        if (err != ENOEXEC)
           {
-            fprintf (stderr, "subprocess terminated with unexpected exit status %d\n", exitstatus);
-            return 1;
+            if (err != 0)
+              {
+                errno = err;
+                perror ("posix_spawn");
+                return 1;
+              }
+
+            /* Wait for child.  */
+            int status = 0;
+            while (waitpid (child, &status, 0) != child)
+              ;
+            if (!WIFEXITED (status))
+              {
+                fprintf (stderr, "subprocess terminated with unexpected wait status %d\n", status);
+                return 1;
+              }
+            int exitstatus = WEXITSTATUS (status);
+            if (exitstatus != 127)
+              {
+                fprintf (stderr, "subprocess terminated with unexpected exit status %d\n", exitstatus);
+                return 1;
+              }
           }
       }
   }
index 04bf496870ac4b2afe07128916a053f8432a07a8..b48e7914c3a1c7dae9c5749fd3028b30e5d02422 100644 (file)
@@ -52,34 +52,40 @@ main ()
           == 0);
 
   {
-    const char *prog_path = SRCDIR "executable-script";
-    const char *prog_argv[2] = { prog_path, NULL };
+    size_t i;
 
-    int err = posix_spawnp (&child, prog_path, &actions, NULL,
-                            (char **) prog_argv, environ);
-    if (err != ENOEXEC)
+    for (i = 0; i < 2; i++)
       {
-        if (err != 0)
-          {
-            errno = err;
-            perror ("posix_spawn");
-            return 1;
-          }
+        const char *prog_path =
+          (i == 0 ? SRCDIR "executable-script" : SRCDIR "executable-script.sh");
+        const char *prog_argv[2] = { prog_path, NULL };
 
-        /* Wait for child.  */
-        int status = 0;
-        while (waitpid (child, &status, 0) != child)
-          ;
-        if (!WIFEXITED (status))
-          {
-            fprintf (stderr, "subprocess terminated with unexpected wait status %d\n", status);
-            return 1;
-          }
-        int exitstatus = WEXITSTATUS (status);
-        if (exitstatus != 127)
+        int err = posix_spawnp (&child, prog_path, &actions, NULL,
+                                (char **) prog_argv, environ);
+        if (err != ENOEXEC)
           {
-            fprintf (stderr, "subprocess terminated with unexpected exit status %d\n", exitstatus);
-            return 1;
+            if (err != 0)
+              {
+                errno = err;
+                perror ("posix_spawn");
+                return 1;
+              }
+
+            /* Wait for child.  */
+            int status = 0;
+            while (waitpid (child, &status, 0) != child)
+              ;
+            if (!WIFEXITED (status))
+              {
+                fprintf (stderr, "subprocess terminated with unexpected wait status %d\n", status);
+                return 1;
+              }
+            int exitstatus = WEXITSTATUS (status);
+            if (exitstatus != 127)
+              {
+                fprintf (stderr, "subprocess terminated with unexpected exit status %d\n", exitstatus);
+                return 1;
+              }
           }
       }
   }
index dbd28ed5ab72b81dd5ab51e5760a401385bc6ca1..1bde5c1bcabbc9597467b45ff4d5af13dd42b8d6 100644 (file)
@@ -41,22 +41,30 @@ main ()
   pid_t pid;
 
   {
-    const char *progname = "executable-script";
-    const char *prog_path = SRCDIR "executable-script";
-    const char *prog_argv[2] = { prog_path, NULL };
+    size_t i;
 
-    pid = create_pipe_in (progname, prog_argv[0], prog_argv, NULL,
-                          NULL, false, true, false, fd);
-    if (pid >= 0)
-      {
-        /* Wait for child.  */
-        ASSERT (wait_subprocess (pid, progname, true, true, true, false, NULL)
-                == 127);
-      }
-    else
+    for (i = 0; i < 2; i++)
       {
-        ASSERT (pid == -1);
-        ASSERT (errno == ENOEXEC);
+        const char *progname =
+          (i == 0 ? "executable-script" : "executable-script.sh");
+        const char *prog_path =
+          (i == 0 ? SRCDIR "executable-script" : SRCDIR "executable-script.sh");
+        const char *prog_argv[2] = { prog_path, NULL };
+
+        pid = create_pipe_in (progname, prog_argv[0], prog_argv, NULL,
+                              NULL, false, true, false, fd);
+        if (pid >= 0)
+          {
+            /* Wait for child.  */
+            ASSERT (wait_subprocess (pid, progname, true, true, true, false,
+                                     NULL)
+                    == 127);
+          }
+        else
+          {
+            ASSERT (pid == -1);
+            ASSERT (errno == ENOEXEC);
+          }
       }
   }