From d880550d56911af6fdba25b4863bc8e49d4df29f Mon Sep 17 00:00:00 2001 From: neumann Date: Tue, 25 Jul 2023 09:01:51 +0000 Subject: Prefer vfork() over posix_spawnp() In essence, older versions of the posix_spawn(p) implementation under glibc have the problem not returning the correct error number in case the spawn call fails. This is e.g. a problem with CentOS 7, which uses GNU libc 2.17, which was released 2012-12-25. This has the consequence that on such systems, Tcl is not error message compliant to versions without posix_spawn. The versions of vfork() do not face this problem and show similar performance characteristics like with posix_spawnp() (spawn time in essence independent of memory footprint size). This change was tested with macOS 13.4, Ubuntu 20.04, CentOS 7.9 and OpenBSD 7.2. --- unix/tcl.m4 | 1 + unix/tclUnixPort.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/unix/tcl.m4 b/unix/tcl.m4 index dfa812b..9d2c38c 100644 --- a/unix/tcl.m4 +++ b/unix/tcl.m4 @@ -2069,6 +2069,7 @@ dnl # preprocessing tests use only CPPFLAGS. # Check for posix_spawnp() and friends unconditionally AC_CHECK_FUNCS(posix_spawnp posix_spawn_file_actions_adddup2 posix_spawnattr_setflags) + AC_CHECK_FUNCS([vfork]) # FIXME: This subst was left in only because the TCL_DL_LIBS # entry in tclConfig.sh uses it. It is not clear why someone diff --git a/unix/tclUnixPort.h b/unix/tclUnixPort.h index c2115df..ea4beac 100644 --- a/unix/tclUnixPort.h +++ b/unix/tclUnixPort.h @@ -636,6 +636,20 @@ extern char ** environ; defined(HAVE_WEAK_IMPORT) && MAC_OS_X_VERSION_MIN_REQUIRED < 1050 # warning "Weak import of 64-bit CoreFoundation is not supported, will not run on Mac OS X < 10.5." # endif +# if defined(HAVE_POSIX_SPAWNP) +/* + * Under macOS, test exec-17.1 fails (I/O setup after closing stdout) with + * posix_spawnp(), but the classic implementation (based on fork()+execvp()) + * works without the severe performance implications with large memory + * footprints. So, deactivate HAVE_POSIX_SPAWNP + */ +# undef HAVE_POSIX_SPAWNP +# endif +#else +# if defined(HAVE_POSIX_SPAWNP) && defined(HAVE_VFORK) +# define USE_VFORK +# undef HAVE_POSIX_SPAWNP +# endif #endif /* __APPLE__ */ /* -- cgit v0.12