On Sat, Feb 7, 2009 at 2:09 PM, Erich Hoover <span dir="ltr"><<a href="mailto:ehoover@mines.edu">ehoover@mines.edu</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I tracked down an issue where an application was running into a sharing problem in WCMD_execute when it created redirects to the same file more than once. I originally hacked around this issue by changing the sharing mode for redirects, but I've now narrowed down the issue. I discovered that the file handle is not being closed when a command has completed and that this issue is caused by the "old handle" value being INVALID_HANDLE_VALUE:<br>
<a href="http://source.winehq.org/source/programs/cmd/wcmdmain.c#L1562" target="_blank">http://source.winehq.org/source/programs/cmd/wcmdmain.c#L1562</a><br>The "old handle" value is being set to this because of a call to GetStdHandle (you see, GetStdHandle(STD_OUTPUT_HANDLE) == INVALID_HANDLE_VALUE):<br>
<a href="http://source.winehq.org/source/programs/cmd/wcmdmain.c#L1399" target="_blank">http://source.winehq.org/source/programs/cmd/wcmdmain.c#L1399</a><br><br>So, my question is whether the call to GetStdHandle is important. If not then line 1399 can easily be simplified to:<br>
old_stdhandles[handle] = idx_stdhandles[handle];<br>Make this change resolves the sharing issue that I'm seeing, but if it is important to use GetStdHandle there then instead the "cleanup" code located near line 1562 needs to be more intelligent.<br>
<font color="#888888">
<br>Erich Hoover<br><a href="mailto:ehoover@mines.edu" target="_blank">ehoover@mines.edu</a><br>
</font></blockquote></div><br>Looking at this a little more it appears that
GetStdHandle(STD_OUTPUT_HANDLE) is not normally supposed to be
INVALID_HANDLE_VALUE. This appears to be happening in this case
because cmd.exe was launched in such a way that it has no input and
output handles. So, it appears to me that when cmd.exe is launched without stdin and stdout handles that no handle cleanup occurs for redirects (causing the problem I've been experiencing). Does this sound right to anyone?<br>
<br>
Erich Hoover<br><a href="mailto:ehoover@mines.edu">ehoover@mines.edu</a><br>