summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2020-12-24 18:19:08 +0100
committerBruno Haible <bruno@clisp.org>2020-12-24 18:19:08 +0100
commitad6d18b5699f75d9fb356b1ef6ea0ed4c50e0216 (patch)
tree8dd06d8301b0f82f8d160fb7eda1b04739793235
parentd9c121346a283503350c0ac7cd6eb5092e87181b (diff)
downloadgnulib-ad6d18b5699f75d9fb356b1ef6ea0ed4c50e0216.tar.gz
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.
-rw-r--r--ChangeLog16
-rw-r--r--lib/windows-spawn.c5
-rw-r--r--modules/execute-tests1
-rw-r--r--modules/posix_spawn-tests1
-rw-r--r--modules/posix_spawnp-tests1
-rw-r--r--modules/spawn-pipe-tests1
-rwxr-xr-xtests/executable-script.sh4
-rw-r--r--tests/test-execute-script.c21
-rw-r--r--tests/test-posix_spawn-script.c54
-rw-r--r--tests/test-posix_spawnp-script.c54
-rw-r--r--tests/test-spawn-pipe-script.c36
11 files changed, 125 insertions, 69 deletions
diff --git a/ChangeLog b/ChangeLog
index 72eb502393..b0e4ad5e44 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
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.
* lib/findprog-in.c (find_in_given_path): If the file basename has no
dot and the search with a suffix returned no result, do also a search
diff --git a/lib/windows-spawn.c b/lib/windows-spawn.c
index 19251aea97..0385b1ce1e 100644
--- a/lib/windows-spawn.c
+++ b/lib/windows-spawn.c
@@ -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;
diff --git a/modules/execute-tests b/modules/execute-tests
index 2213a3225a..422c1abe72 100644
--- a/modules/execute-tests
+++ b/modules/execute-tests
@@ -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
diff --git a/modules/posix_spawn-tests b/modules/posix_spawn-tests
index 451dbd1ec4..06a8434967 100644
--- a/modules/posix_spawn-tests
+++ b/modules/posix_spawn-tests
@@ -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
diff --git a/modules/posix_spawnp-tests b/modules/posix_spawnp-tests
index 04ccdbb6cd..887569c605 100644
--- a/modules/posix_spawnp-tests
+++ b/modules/posix_spawnp-tests
@@ -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
diff --git a/modules/spawn-pipe-tests b/modules/spawn-pipe-tests
index 80614a93bc..5dbd28d74a 100644
--- a/modules/spawn-pipe-tests
+++ b/modules/spawn-pipe-tests
@@ -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
index 0000000000..993f41cf4c
--- /dev/null
+++ b/tests/executable-script.sh
@@ -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.
diff --git a/tests/test-execute-script.c b/tests/test-execute-script.c
index 060f0c5fd1..aff92361ff 100644
--- a/tests/test-execute-script.c
+++ b/tests/test-execute-script.c
@@ -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__
diff --git a/tests/test-posix_spawn-script.c b/tests/test-posix_spawn-script.c
index a632841d8e..e17c3b84ff 100644
--- a/tests/test-posix_spawn-script.c
+++ b/tests/test-posix_spawn-script.c
@@ -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;
+ }
}
}
}
diff --git a/tests/test-posix_spawnp-script.c b/tests/test-posix_spawnp-script.c
index 04bf496870..b48e7914c3 100644
--- a/tests/test-posix_spawnp-script.c
+++ b/tests/test-posix_spawnp-script.c
@@ -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;
+ }
}
}
}
diff --git a/tests/test-spawn-pipe-script.c b/tests/test-spawn-pipe-script.c
index dbd28ed5ab..1bde5c1bca 100644
--- a/tests/test-spawn-pipe-script.c
+++ b/tests/test-spawn-pipe-script.c
@@ -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);
+ }
}
}