From 7710b9ab1fb9f9e216ccb4446aefd4b1473f3667 Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Mon, 7 Feb 2022 22:17:07 -0500 Subject: [PATCH 1/2] configure: Ensure that posix_spawnp reports ENOENT correctly It turns out that POSIX allows implementations to report errors "lazily" by exiting the spawned process with code 127. In particular, OpenBSD's implementation returns successfully if the requested executable doesn't exist. This severely hampers our ability to report errors accurately. In this patch we add a `configure` test for sensible error-reporting from `posix_spawnp` and disable it if the test fails. Fixes #224. --- cbits/posix/posix_spawn.c | 2 +- configure.ac | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/cbits/posix/posix_spawn.c b/cbits/posix/posix_spawn.c index 89adc2ec..edd76c13 100644 --- a/cbits/posix/posix_spawn.c +++ b/cbits/posix/posix_spawn.c @@ -5,7 +5,7 @@ #include #include -#if !defined(HAVE_POSIX_SPAWNP) +#if !defined(USE_POSIX_SPAWN) ProcHandle do_spawn_posix (char *const args[], char *workingDirectory, char **environment, diff --git a/configure.ac b/configure.ac index 56f10c45..8c7c034f 100644 --- a/configure.ac +++ b/configure.ac @@ -31,6 +31,39 @@ AC_CHECK_DECLS([POSIX_SPAWN_SETPGROUP],[],[],[ #include ]) +if test "$ac_cv_func_posix_spawnp" = "yes"; then + dnl On OpenBSD posix_spawnp doesn't report ENOENT when + dnl the user attempts to spawn a process with a non-existent + dnl executable. Don't attempt to use such posix_spawn + dnl implementations to ensure errors are reported correctly. + dnl See #224. + + AC_MSG_CHECKING(whether posix_spawn reports errors sensibly) + AC_RUN_IFELSE( + [AC_LANG_PROGRAM([ + #include + #include + #include + #include + ], [[ + pid_t pid; + char *prog = "__nonexistent_program__"; + char *args[] = {prog, NULL}; + char *env[] = {NULL}; + + // This should fail with ENOENT + int ret = posix_spawnp(&pid, prog, NULL, NULL, args, env); + bool okay = ret == ENOENT; + return !okay; + ]] + )], + [AC_DEFINE([USE_POSIX_SPAWN], [], [posix_spawn should be used]) + AC_MSG_RESULT(yes)], + [AC_MSG_RESULT([no, falling back to fork/exec])] + ) +fi + + FP_CHECK_CONSTS([SIG_DFL SIG_IGN]) AC_OUTPUT From 66c26ca7b279d976b7871e8291c6ae053520e6d1 Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Mon, 7 Feb 2022 23:13:49 -0500 Subject: [PATCH 2/2] Bump version to 1.6.14.0 --- changelog.md | 7 ++++++- process.cabal | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 8f5b8041..106dc436 100644 --- a/changelog.md +++ b/changelog.md @@ -1,8 +1,13 @@ # Changelog for [`process` package](http://hackage.haskell.org/package/process) -## Unreleased +## 1.6.14.0 *February 2022* * posix: Ensure that `errno` is set after `posix_spawnp` fails [#228](https://github.com/haskell/process/pull/228) +* Don't use `posix_spawn` on platforms where it does not report `ENOENT` in caes where the + requested executable does not exist [#224](https://github.com/haskell/process/issues/224) +* Ensure that `find_executable` correctly-locates executables when a change in + working directory is requested [#219](https://github.com/haskell/process/issues/219) +* Fix capitalization error allowing `execvpe` to be used when available. ## 1.6.13.2 *July 2021* diff --git a/process.cabal b/process.cabal index 8742f29a..8f3f21cb 100644 --- a/process.cabal +++ b/process.cabal @@ -1,5 +1,5 @@ name: process -version: 1.6.13.2 +version: 1.6.14.0 -- NOTE: Don't forget to update ./changelog.md license: BSD3 license-file: LICENSE