From: SourceForge.net <no...@so...> - 2005-04-18 14:50:34
|
Patches item #1184104, was opened at 2005-04-15 21:20 Message generated for change (Comment added) made by dgp You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=312997&aid=1184104&group_id=12997 Category: None Group: None Status: Open Resolution: None Priority: 5 Submitted By: Nobody/Anonymous (nobody) Assigned to: Nobody/Anonymous (nobody) Summary: Child Process Wish.exe Refuses to Close STDIO Channels Initial Comment: The problem lies in tkConsole/Tk_InitConsoleChannels() within ShouldUseConsoleChannel(). When wish.exe is started by double-clicking in Windows Explorer, or by typing "wish" on the command line, it is detached from the calling process' stdio channels. When ShouldUseConsoleChannel() is called, it returns 1, bailing out early at handle==INVALID_HANDLE_VALUE, ==0, or FILE_TYPE_UNKNOWN. However, if the parent process does NOT relinquish control of stdio channels, as with using CreateProcess() and inheritable pipes assigned to the child's stdio, then ShouldUseConsoleChannel() makes it all the way to the call to Tcl_GetStdChannel(), which increments the refCount. By the end of initialization, refCount is at 3. When [close] is called on a given channel, DetachChannel() decrements refCount to 2. CheckForStdChannelsBeingClosed() sees a refCount of 2, and refuses to set refCount to 0, [incorrectly] presuming that a second interp has the stdio channel open. The fix is to decrement the refCount immediately if Tcl_GetStdChannel() is reached. ---------------------------------------------------------------------- >Comment By: Don Porter (dgp) Date: 2005-04-18 10:50 Message: Logged In: YES user_id=80530 If you submit a new report while logged in, you'll be able to attach the patch. ---------------------------------------------------------------------- Comment By: MKS (m_schrumpf) Date: 2005-04-16 09:51 Message: Logged In: YES user_id=1260469 Define "start again." You want to close/abandon this report, and then I resubmit? ---------------------------------------------------------------------- Comment By: Don Porter (dgp) Date: 2005-04-16 00:35 Message: Logged In: YES user_id=80530 what a shame you weren't logged in when you posted the original report. Then you could have attached the file. Want to start again? ---------------------------------------------------------------------- Comment By: MKS (m_schrumpf) Date: 2005-04-15 23:52 Message: Logged In: YES user_id=1260469 (Sorry about the first, poorly-formatted pasted-in patch. That's what happens when you move a text file from Windows to Unix without checking the EOL characters.) ---------------------------------------------------------------------- Comment By: Nobody/Anonymous (nobody) Date: 2005-04-15 23:45 Message: Logged In: NO --- tkConsole.c Mon Aug 05 00:30:38 2002 +++ tkConsole.c Fri Apr 15 16:14:25 2005 @@ -12,6 +12,9 @@ * * RCS: @(#) $Id: tkConsole.c,v 1.18 2002/08/05 04:30:38 dgp Exp $ */ + +#include "tclPort.h" +#include "tclIO.h" #include "tk.h" #include <string.h> @@ -115,6 +118,8 @@ int mode; char *bufMode; HANDLE handle; + Tcl_Channel chan; + ChannelState *statePtr; switch (type) { case TCL_STDIN: @@ -186,9 +191,24 @@ } } else if (fileType == FILE_TYPE_UNKNOWN) { return 1; - } else if (Tcl_GetStdChannel(type) == NULL) { + } else if ((chan = Tcl_GetStdChannel(type)) == NULL) { return 1; } + /* + * Tcl_GetStdChannel is only called if wish.exe was started + * from a parent process that grabs pipes to stdio channels + * (i.e. using CreateProcess() with inheritable pipes assigned + * to the child's stdio). + * A succesful call to Tcl_GetStdChannel increments refCount, + * which leaves the total count at 2 when calling + * CheckForStdChannelsBeingClosed(), preventing wish.exe from + * actually closing the IO handles when [close] is called on + * the last instance of a channel. + * Since the parent process is probably expecting these to be + * closed when wish.exe calls [close], decrement the count here. + */ + statePtr = ((Channel *) (chan))->state; + statePtr->refCount--; return 0; } @@ -197,7 +217,7 @@ * Mac should always use a console channel, Unix should if it's trying to */ -#define ShouldUseConsoleChannel(chan) (1) +#define ShouldUseConsoleChannel(type) (1) #endif /* ---------------------------------------------------------------------- Comment By: Nobody/Anonymous (nobody) Date: 2005-04-15 23:43 Message: Logged In: NO Patch file attachment didn't upload: --- tkConsole.c Mon Aug 05 00:30:38 2002 +++ tkConsole.c Fri Apr 15 16:14:25 2005 @@ -12,6 +12,9 @@ * * RCS: @(#) $Id: tkConsole.c,v 1.18 2002/08/05 04:30:38 dgp Exp $ */ + +#include "tclPort.h" +#include "tclIO.h" #include "tk.h" #include <string.h> @@ -115,6 +118,8 @@ int mode; char *bufMode; HANDLE handle; + Tcl_Channel chan; + ChannelState *statePtr; switch (type) { case TCL_STDIN: @@ -186,9 +191,24 @@ } } else if (fileType == FILE_TYPE_UNKNOWN) { return 1; - } else if (Tcl_GetStdChannel(type) == NULL) { + } else if ((chan = Tcl_GetStdChannel(type)) == NULL) { return 1; } + /* + * Tcl_GetStdChannel is only called if wish.exe was started + * from a parent process that grabs pipes to stdio channels + * (i.e. using CreateProcess() with inheritable pipes assigned + * to the child's stdio). + * A succesful call to Tcl_GetStdChannel increments refCount, + * which leaves the total count at 2 when calling + * CheckForStdChannelsBeingClosed(), preventing wish.exe from + * actually closing the IO handles when [close] is called on + * the last instance of a channel. + * Since the parent process is probably expecting these to be + * closed when wish.exe calls [close], decrement the count here. + */ + statePtr = ((Channel *) (chan))->state; + statePtr->refCount--; return 0; } @@ -197,7 +217,7 @@ * Mac should always use a console channel, Unix should if it's trying to */ -#define ShouldUseConsoleChannel(chan) (1) +#define ShouldUseConsoleChannel(type) (1) #endif /* ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=312997&aid=1184104&group_id=12997 |