summaryrefslogtreecommitdiffstats
path: root/unix
diff options
context:
space:
mode:
authordas <das>2006-08-02 20:04:11 (GMT)
committerdas <das>2006-08-02 20:04:11 (GMT)
commit4aab3a8c321f05ae8af6a39d0ef6a769fb3f70be (patch)
tree8abd1863d3a28052b041e310197ba5cdb554ce67 /unix
parent1cb22227799972e31fd2e85ec0bc738dd5e176be (diff)
downloadtcl-4aab3a8c321f05ae8af6a39d0ef6a769fb3f70be.zip
tcl-4aab3a8c321f05ae8af6a39d0ef6a769fb3f70be.tar.gz
tcl-4aab3a8c321f05ae8af6a39d0ef6a769fb3f70be.tar.bz2
* unix/tclUnixPipe.c (TclpCreateProcess): for USE_VFORK: ensure standard
channels are initialized before vfork() so that the child doesn't potentially corrupt global state in the parent's address space.
Diffstat (limited to 'unix')
-rw-r--r--unix/tclUnixPipe.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/unix/tclUnixPipe.c b/unix/tclUnixPipe.c
index 8a20bcc..c177f67 100644
--- a/unix/tclUnixPipe.c
+++ b/unix/tclUnixPipe.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclUnixPipe.c,v 1.34 2006/07/20 06:17:39 das Exp $
+ * RCS: @(#) $Id: tclUnixPipe.c,v 1.35 2006/08/02 20:04:11 das Exp $
*/
#include "tclInt.h"
@@ -428,6 +428,23 @@ TclpCreateProcess(
newArgv[i] = Tcl_UtfToExternalDString(NULL, argv[i], -1, &dsArray[i]);
}
+#ifdef USE_VFORK
+ /*
+ * 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
+ * might corrupt the parent: so ensure standard channels are initialized in
+ * the parent, otherwise SetupStdFile() might initialize them in the child.
+ */
+ if (!inputFile) {
+ Tcl_GetStdChannel(TCL_STDIN);
+ }
+ if (!outputFile) {
+ Tcl_GetStdChannel(TCL_STDOUT);
+ }
+ if (!errorFile) {
+ Tcl_GetStdChannel(TCL_STDERR);
+ }
+#endif
pid = fork();
if (pid == 0) {
int joinThisError = errorFile && (errorFile == outputFile);