From 8733687efc5d3b8d2dd1114b0f5af35c019e9093 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 25 Jul 2023 10:35:22 +0000 Subject: Add (back) check for vfork() --- unix/configure | 5 +++-- unix/tcl.m4 | 4 ++-- unix/tclConfig.h.in | 3 +++ unix/tclUnixPipe.c | 34 ++++++++++++---------------------- unix/tclUnixPort.h | 7 +++++++ 5 files changed, 27 insertions(+), 26 deletions(-) diff --git a/unix/configure b/unix/configure index bbe8df9..553fc73 100755 --- a/unix/configure +++ b/unix/configure @@ -8978,11 +8978,12 @@ echo "${ECHO_T}$ac_cv_nolto" >&6 CFLAGS_NOLTO="" fi - # Check for posix_spawnp() and friends unconditionally + # Check for vfork, posix_spawnp() and friends unconditionally -for ac_func in posix_spawnp posix_spawn_file_actions_adddup2 posix_spawnattr_setflags + +for ac_func in vfork posix_spawnp posix_spawn_file_actions_adddup2 posix_spawnattr_setflags do as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` echo "$as_me:$LINENO: checking for $ac_func" >&5 diff --git a/unix/tcl.m4 b/unix/tcl.m4 index dfa812b..06d31b8 100644 --- a/unix/tcl.m4 +++ b/unix/tcl.m4 @@ -2067,8 +2067,8 @@ dnl # preprocessing tests use only CPPFLAGS. CFLAGS_NOLTO="" fi - # Check for posix_spawnp() and friends unconditionally - AC_CHECK_FUNCS(posix_spawnp posix_spawn_file_actions_adddup2 posix_spawnattr_setflags) + # Check for vfork, posix_spawnp() and friends unconditionally + AC_CHECK_FUNCS(vfork posix_spawnp posix_spawn_file_actions_adddup2 posix_spawnattr_setflags) # 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/tclConfig.h.in b/unix/tclConfig.h.in index 87e3eb9..5a64236 100644 --- a/unix/tclConfig.h.in +++ b/unix/tclConfig.h.in @@ -279,6 +279,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H +/* Define to 1 if you have the `vfork' function. */ +#undef HAVE_VFORK + /* Define to 1 if you have the `waitpid' function. */ #undef HAVE_WAITPID diff --git a/unix/tclUnixPipe.c b/unix/tclUnixPipe.c index e040807..b85ffe0 100644 --- a/unix/tclUnixPipe.c +++ b/unix/tclUnixPipe.c @@ -14,30 +14,20 @@ #include "tclInt.h" #ifdef HAVE_POSIX_SPAWNP -#ifdef HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 -#ifdef HAVE_POSIX_SPAWNATTR_SETFLAGS -#include -#include -#define USE_POSIX_SPAWN 1 -#endif -#endif +# if defined(HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2) \ + && defined(HAVE_POSIX_SPAWNATTR_SETFLAGS) +# include +# include +# else +# undef HAVE_POSIX_SPAWNP +# endif #endif -#ifdef USE_VFORK +#ifdef HAVE_VFORK #define fork vfork #endif /* - * For now, test exec-17.1 fails (I/O setup after closing stdout) with - * posix_spawnp(), but the classic implementation (based on fork()+execvp()) - * works well under macOS. - */ - -#ifdef __APPLE__ -#undef USE_POSIX_SPAWN -#endif - -/* * The following macros convert between TclFile's and fd's. The conversion * simple involves shifting fd's up by one to ensure that no valid fd is ever * the same as NULL. @@ -431,7 +421,7 @@ TclpCreateProcess( Tcl_DString *dsArray; char **newArgv; int pid, i; -#if defined(USE_POSIX_SPAWN) +#if defined(HAVE_POSIX_SPAWNP) int childErrno; static int use_spawn = -1; #endif @@ -463,7 +453,7 @@ TclpCreateProcess( newArgv[i] = Tcl_UtfToExternalDString(NULL, argv[i], -1, &dsArray[i]); } -#if defined(USE_VFORK) || defined(USE_POSIX_SPAWN) +#if defined(HAVE_VFORK) || defined(HAVE_POSIX_SPAWNP) /* * After vfork(), do not call code in the child that changes global state, * because it is using the parent's memory space at that point and writes @@ -483,7 +473,7 @@ TclpCreateProcess( } #endif -#ifdef USE_POSIX_SPAWN +#ifdef HAVE_POSIX_SPAWNP #ifdef _CS_GNU_LIBC_VERSION if (use_spawn < 0) { char conf[32], *p; @@ -599,7 +589,7 @@ TclpCreateProcess( TclStackFree(interp, dsArray); if (pid == -1) { -#ifdef USE_POSIX_SPAWN +#ifdef HAVE_POSIX_SPAWNP errno = childErrno; #endif Tcl_SetObjResult(interp, Tcl_ObjPrintf( diff --git a/unix/tclUnixPort.h b/unix/tclUnixPort.h index c2115df..486fa23 100644 --- a/unix/tclUnixPort.h +++ b/unix/tclUnixPort.h @@ -636,6 +636,13 @@ 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 + /* + * For now, test exec-17.1 fails (I/O setup after closing stdout) with + * posix_spawnp(), but the classic implementation (based on fork()+execvp()) + * works well under macOS. + */ +# undef HAVE_POSIX_SPAWNP +# undef HAVE_VFORK #endif /* __APPLE__ */ /* -- cgit v0.12