summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2023-07-26 08:03:45 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2023-07-26 08:03:45 (GMT)
commit862ae1266cd494baaed59be9a1d74b66de7eaa6a (patch)
tree78dd153eaa3500aeb5e47f99f543a02f3ec171ad
parentffe298076d5004777f81e9776ba6f76affcf2f2f (diff)
parentb985fb89654fa2129bfc4cfa20853b10d7cc7184 (diff)
downloadtcl-862ae1266cd494baaed59be9a1d74b66de7eaa6a.zip
tcl-862ae1266cd494baaed59be9a1d74b66de7eaa6a.tar.gz
tcl-862ae1266cd494baaed59be9a1d74b66de7eaa6a.tar.bz2
Merge 8.6
-rwxr-xr-xunix/configure27
-rw-r--r--unix/tcl.m43
-rw-r--r--unix/tclConfig.h.in9
-rw-r--r--unix/tclUnixPipe.c77
-rw-r--r--unix/tclUnixPort.h10
5 files changed, 97 insertions, 29 deletions
diff --git a/unix/configure b/unix/configure
index 78b4a21..426954a 100755
--- a/unix/configure
+++ b/unix/configure
@@ -7329,7 +7329,32 @@ printf "%s\n" "#define HAVE_STDBOOL_H 1" >>confdefs.h
fi
- #AC_CHECK_FUNCS([posix_spawnp])
+ # Check for vfork, posix_spawnp() and friends unconditionally
+ ac_fn_c_check_func "$LINENO" "vfork" "ac_cv_func_vfork"
+if test "x$ac_cv_func_vfork" = xyes
+then :
+ printf "%s\n" "#define HAVE_VFORK 1" >>confdefs.h
+
+fi
+ac_fn_c_check_func "$LINENO" "posix_spawnp" "ac_cv_func_posix_spawnp"
+if test "x$ac_cv_func_posix_spawnp" = xyes
+then :
+ printf "%s\n" "#define HAVE_POSIX_SPAWNP 1" >>confdefs.h
+
+fi
+ac_fn_c_check_func "$LINENO" "posix_spawn_file_actions_adddup2" "ac_cv_func_posix_spawn_file_actions_adddup2"
+if test "x$ac_cv_func_posix_spawn_file_actions_adddup2" = xyes
+then :
+ printf "%s\n" "#define HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 1" >>confdefs.h
+
+fi
+ac_fn_c_check_func "$LINENO" "posix_spawnattr_setflags" "ac_cv_func_posix_spawnattr_setflags"
+if test "x$ac_cv_func_posix_spawnattr_setflags" = xyes
+then :
+ printf "%s\n" "#define HAVE_POSIX_SPAWNATTR_SETFLAGS 1" >>confdefs.h
+
+fi
+
# 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/tcl.m4 b/unix/tcl.m4
index e3325b1..ecfec69 100644
--- a/unix/tcl.m4
+++ b/unix/tcl.m4
@@ -1877,7 +1877,8 @@ dnl # preprocessing tests use only CPPFLAGS.
AC_CHECK_HEADER(stdbool.h, [AC_DEFINE(HAVE_STDBOOL_H, 1, [Do we have <stdbool.h>?])],)
- #AC_CHECK_FUNCS([posix_spawnp])
+ # 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 904fd8a..560d564 100644
--- a/unix/tclConfig.h.in
+++ b/unix/tclConfig.h.in
@@ -181,9 +181,15 @@
/* Define to 1 if you have the `OSSpinLockLock' function. */
#undef HAVE_OSSPINLOCKLOCK
+/* Define to 1 if you have the `posix_spawnattr_setflags' function. */
+#undef HAVE_POSIX_SPAWNATTR_SETFLAGS
+
/* Define to 1 if you have the `posix_spawnp' function. */
#undef HAVE_POSIX_SPAWNP
+/* Define to 1 if you have the `posix_spawn_file_actions_adddup2' function. */
+#undef HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2
+
/* Should we use pselect()? */
#undef HAVE_PSELECT
@@ -298,6 +304,9 @@
/* Define to 1 if you have the <unistd.h> 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 dd477cc..92cd168 100644
--- a/unix/tclUnixPipe.c
+++ b/unix/tclUnixPipe.c
@@ -14,10 +14,17 @@
#include "tclInt.h"
#ifdef HAVE_POSIX_SPAWNP
-# include <spawn.h>
+# if defined(HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2) \
+ && defined(HAVE_POSIX_SPAWNATTR_SETFLAGS) \
+ && !defined(HAVE_VFORK)
+# include <unistd.h>
+# include <spawn.h>
+# else
+# undef HAVE_POSIX_SPAWNP
+# endif
#endif
-#ifdef USE_VFORK
+#ifdef HAVE_VFORK
#define fork vfork
#endif
@@ -417,6 +424,7 @@ TclpCreateProcess(
int pid, i;
#if defined(HAVE_POSIX_SPAWNP)
int childErrno;
+ static int use_spawn = -1;
#endif
errPipeIn = NULL;
@@ -446,7 +454,7 @@ TclpCreateProcess(
newArgv[i] = Tcl_UtfToExternalDString(NULL, argv[i], TCL_INDEX_NONE, &dsArray[i]);
}
-#if defined(USE_VFORK) || defined(HAVE_POSIX_SPAWNP)
+#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
@@ -467,28 +475,52 @@ TclpCreateProcess(
#endif
#ifdef HAVE_POSIX_SPAWNP
- {
+#ifdef _CS_GNU_LIBC_VERSION
+ if (use_spawn < 0) {
+ char conf[32], *p;
+ int major = 0, minor = 0;
+
+ use_spawn = 0;
+ memset(conf, 0, sizeof(conf));
+ confstr(_CS_GNU_LIBC_VERSION, conf, sizeof(conf));
+ p = strchr(conf, ' '); /* skip "glibc" */
+ if (p != NULL) {
+ ++p;
+ if (sscanf(p, "%d.%d", &major, &minor) > 1) {
+ if ((major > 2) || ((major == 2) && (minor >= 24))) {
+ use_spawn = 1;
+ }
+ }
+ }
+ }
+#endif
+ status = -1;
+ if (use_spawn) {
posix_spawn_file_actions_t actions;
posix_spawnattr_t attr;
+ sigset_t sigs;
posix_spawn_file_actions_init(&actions);
posix_spawnattr_init(&attr);
-
- posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGDEF|
-# ifdef POSIX_SPAWN_USEVFORK
- POSIX_SPAWN_USEVFORK
-# else
- 0
-# endif
- );
+ sigfillset(&sigs);
+ sigdelset(&sigs, SIGKILL);
+ sigdelset(&sigs, SIGSTOP);
+
+ posix_spawnattr_setflags(&attr,
+ POSIX_SPAWN_SETSIGDEF
+#ifdef POSIX_SPAWN_USEVFORK
+ | POSIX_SPAWN_USEVFORK
+#endif
+ );
+ posix_spawnattr_setsigdefault(&attr, &sigs);
posix_spawn_file_actions_adddup2(&actions, GetFd(inputFile), 0);
posix_spawn_file_actions_adddup2(&actions, GetFd(outputFile), 1);
posix_spawn_file_actions_adddup2(&actions, GetFd(errorFile), 2);
- status = posix_spawnp(&pid, newArgv[0], &actions, &attr, newArgv, environ);
- childErrno = status;
-
+ status = posix_spawnp(&pid, newArgv[0], &actions, &attr,
+ newArgv, environ);
+ childErrno = errno;
posix_spawn_file_actions_destroy(&actions);
posix_spawnattr_destroy(&attr);
@@ -498,11 +530,13 @@ TclpCreateProcess(
* - pid == -1: error
* - pid > 0: parent process
*
- * Mimic fork semantics to minimize changes below
+ * Mimic fork semantics to minimize changes below,
+ * but retry with fork() as last ressort.
*/
- if (status != 0) {
- pid = -1;
- }
+ }
+ if (status != 0) {
+ pid = fork();
+ childErrno = errno;
}
#else
pid = fork();
@@ -558,12 +592,9 @@ TclpCreateProcess(
if (pid == -1) {
#ifdef HAVE_POSIX_SPAWNP
errno = childErrno;
- Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "couldn't execute \"%s\": %s", argv[0], Tcl_PosixError(interp)));
-#else
+#endif
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"couldn't fork child process: %s", Tcl_PosixError(interp)));
-#endif
goto error;
}
diff --git a/unix/tclUnixPort.h b/unix/tclUnixPort.h
index 8d35229..f9fd702 100644
--- a/unix/tclUnixPort.h
+++ b/unix/tclUnixPort.h
@@ -612,11 +612,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 quite OK.
- */
+ /*
+ * 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__ */
/*