+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.
errno = ENAMETOOLONG;
break;
+ case ERROR_BAD_FORMAT:
+ case ERROR_BAD_EXE_FORMAT:
+ errno = ENOEXEC;
+ break;
+
default:
errno = EINVAL;
break;
tests/test-execute-child.c
tests/test-execute-script.c
tests/executable-script
+tests/executable-script.sh
tests/executable-shell-script
tests/macros.h
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
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
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
--- /dev/null
+printf 'Halle '
+printf "Potta"
+# This script is intentionally not immediately recognizable as a shell script.
+# Don't add a #! header in the first line.
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__
== 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;
+ }
}
}
}
== 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;
+ }
}
}
}
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);
+ }
}
}