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: http://source.winehq.org/source/programs/cmd/wcmdmain.c#L1562 The "old handle" value is being set to this because of a call to GetStdHandle (you see, GetStdHandle(STD_OUTPUT_HANDLE) == INVALID_HANDLE_VALUE): http://source.winehq.org/source/programs/cmd/wcmdmain.c#L1399
So, my question is whether the call to GetStdHandle is important. If not then line 1399 can easily be simplified to: old_stdhandles[handle] = idx_stdhandles[handle]; 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.
Erich Hoover ehoover@mines.edu
On Sat, Feb 7, 2009 at 2:09 PM, Erich Hoover ehoover@mines.edu wrote:
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: http://source.winehq.org/source/programs/cmd/wcmdmain.c#L1562 The "old handle" value is being set to this because of a call to GetStdHandle (you see, GetStdHandle(STD_OUTPUT_HANDLE) == INVALID_HANDLE_VALUE): http://source.winehq.org/source/programs/cmd/wcmdmain.c#L1399
So, my question is whether the call to GetStdHandle is important. If not then line 1399 can easily be simplified to: old_stdhandles[handle] = idx_stdhandles[handle]; 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.
Erich Hoover ehoover@mines.edu
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?
Erich Hoover ehoover@mines.edu