From fd48c477a4298daa6ceb76753f81016a9d184417 Mon Sep 17 00:00:00 2001 From: Bernard Ladenthin Date: Sat, 1 Aug 2026 15:04:39 +0200 Subject: [PATCH 1/3] Fix building against glibc older than 2.29 posix_spawn_file_actions_addchdir_np arrived in glibc 2.29, so subprocess_create_ex fails to compile and link on older systems such as manylinux2014. Add a SUBPROCESS_HAVE_CWD probe, report a requested cwd as ENOSYS where the call is unavailable, and skip the cwd test there. --- subprocess.h | 14 ++++++++++++++ test/test_shared.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/subprocess.h b/subprocess.h index 5e80902..c88646d 100644 --- a/subprocess.h +++ b/subprocess.h @@ -274,6 +274,18 @@ subprocess_weak int subprocess_alive(struct subprocess_s *const process); #include #endif +/* Whether subprocess_create_ex can honour process_cwd. glibc only gained + posix_spawn_file_actions_addchdir_np in 2.29. */ +#if defined(__GLIBC__) +#if __GLIBC_PREREQ(2, 29) +#define SUBPROCESS_HAVE_CWD 1 +#else +#define SUBPROCESS_HAVE_CWD 0 +#endif +#else +#define SUBPROCESS_HAVE_CWD 1 +#endif + #if defined(_WIN32) #include @@ -1207,6 +1219,8 @@ int subprocess_create_ex(const char *const commandLine[], int options, if (process_cwd) { #if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED >= 260000 posix_error = posix_spawn_file_actions_addchdir(&actions, process_cwd); +#elif !SUBPROCESS_HAVE_CWD + posix_error = ENOSYS; #else #if defined(__APPLE__) && defined(__clang__) #pragma clang diagnostic push diff --git a/test/test_shared.h b/test/test_shared.h index a694ed6..b6a9706 100644 --- a/test/test_shared.h +++ b/test/test_shared.h @@ -1116,6 +1116,7 @@ SUBPROCESS_TEST(environment, specify_environment) { ASSERT_EQ(0, subprocess_destroy(&process)); } +#if SUBPROCESS_HAVE_CWD SUBPROCESS_TEST(create_ex, subprocess_cwd) { char current_path[4096]; char target_path[4096]; @@ -1156,6 +1157,7 @@ SUBPROCESS_TEST(create_ex, subprocess_cwd) { ASSERT_EQ(0, subprocess_destroy(&process)); } +#endif #if !defined(_MSC_VER) SUBPROCESS_TEST(executable_resolve, no_slashes_with_environment) { From 620ce442567657429578d2da7d1278c428d0066e Mon Sep 17 00:00:00 2001 From: Bernard Ladenthin Date: Sat, 1 Aug 2026 15:54:05 +0200 Subject: [PATCH 2/3] Allow overriding SUBPROCESS_HAVE_CWD and document it musl gained posix_spawn_file_actions_addchdir_np in 1.1.24 but exposes no version macro, so the detection cannot cover older releases. Skip it when the macro is already defined, letting those users set it themselves. --- README.md | 6 ++++++ subprocess.h | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e03e98b..7ee711d 100644 --- a/README.md +++ b/README.md @@ -179,6 +179,12 @@ pass `NULL` to inherit the parent's current working directory. On Windows, custom environment entries and the current working directory string are interpreted as UTF-8. +Not every platform can honour a custom working directory. Where it cannot, +`SUBPROCESS_HAVE_CWD` is defined to `0` and passing a non-`NULL` working +directory fails with `ENOSYS`; this currently affects glibc older than 2.29. +Define `SUBPROCESS_HAVE_CWD` yourself to override the detection, for instance +on musl older than 1.1.24. + Note though that you **cannot** specify `subprocess_option_inherit_environment` with a custom environment. If you want to merge some custom environment with the parent process environment then it is up to you as the user to query the original diff --git a/subprocess.h b/subprocess.h index c88646d..dc0153c 100644 --- a/subprocess.h +++ b/subprocess.h @@ -275,7 +275,9 @@ subprocess_weak int subprocess_alive(struct subprocess_s *const process); #endif /* Whether subprocess_create_ex can honour process_cwd. glibc only gained - posix_spawn_file_actions_addchdir_np in 2.29. */ + posix_spawn_file_actions_addchdir_np in 2.29. Define this yourself to + override the detection, for instance on musl older than 1.1.24. */ +#if !defined(SUBPROCESS_HAVE_CWD) #if defined(__GLIBC__) #if __GLIBC_PREREQ(2, 29) #define SUBPROCESS_HAVE_CWD 1 @@ -285,6 +287,7 @@ subprocess_weak int subprocess_alive(struct subprocess_s *const process); #else #define SUBPROCESS_HAVE_CWD 1 #endif +#endif #if defined(_WIN32) From 6900aedc4e56a68fd496d9d9d3c9497e292138a3 Mon Sep 17 00:00:00 2001 From: Bernard Ladenthin Date: Sat, 8 Aug 2026 01:13:40 +0200 Subject: [PATCH 3/3] Fix building against macOS older than 10.15 posix_spawn_file_actions_addchdir_np arrived in macOS 10.15, so older SDKs neither declare nor export it and subprocess_create_ex fails to compile, as reported for MacPorts on PowerPC in #108. A newer SDK paired with an older deployment target does compile, but warns and leaves the binary referencing a symbol the target system does not have. Extend the SUBPROCESS_HAVE_CWD probe with a Darwin arm. It deliberately omits a defined() guard on MAC_OS_X_VERSION_MIN_REQUIRED: an absent macro folds to 0, so a toolchain that does not supply it answers "no cwd" rather than calling a function that may not be there. That also gives the right answer on iOS, tvOS and watchOS, where the SDKs mark the call unavailable outright. --- README.md | 7 ++++--- subprocess.h | 8 ++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7ee711d..a9ec17b 100644 --- a/README.md +++ b/README.md @@ -181,9 +181,10 @@ interpreted as UTF-8. Not every platform can honour a custom working directory. Where it cannot, `SUBPROCESS_HAVE_CWD` is defined to `0` and passing a non-`NULL` working -directory fails with `ENOSYS`; this currently affects glibc older than 2.29. -Define `SUBPROCESS_HAVE_CWD` yourself to override the detection, for instance -on musl older than 1.1.24. +directory fails with `ENOSYS`; this currently affects glibc older than 2.29, +macOS older than 10.15, and iOS, tvOS and watchOS, where Apple marks the +underlying call unavailable. Define `SUBPROCESS_HAVE_CWD` yourself to override +the detection, for instance on musl older than 1.1.24. Note though that you **cannot** specify `subprocess_option_inherit_environment` with a custom environment. If you want to merge some custom environment with the diff --git a/subprocess.h b/subprocess.h index dc0153c..a81f45a 100644 --- a/subprocess.h +++ b/subprocess.h @@ -275,8 +275,10 @@ subprocess_weak int subprocess_alive(struct subprocess_s *const process); #endif /* Whether subprocess_create_ex can honour process_cwd. glibc only gained - posix_spawn_file_actions_addchdir_np in 2.29. Define this yourself to - override the detection, for instance on musl older than 1.1.24. */ + posix_spawn_file_actions_addchdir_np in 2.29, and macOS in 10.15; the SDKs + mark it unavailable on iOS, tvOS and watchOS, where the undefined version + macro folds to 0 and so answers correctly. Define this yourself to override + the detection, for instance on musl older than 1.1.24. */ #if !defined(SUBPROCESS_HAVE_CWD) #if defined(__GLIBC__) #if __GLIBC_PREREQ(2, 29) @@ -284,6 +286,8 @@ subprocess_weak int subprocess_alive(struct subprocess_s *const process); #else #define SUBPROCESS_HAVE_CWD 0 #endif +#elif defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED < 101500 +#define SUBPROCESS_HAVE_CWD 0 #else #define SUBPROCESS_HAVE_CWD 1 #endif