From: Doug Lyons douglyons@douglyons.com
It's a read-only operation anyway, and trying to acquire the lock would deadlock if blocking I/O is in progress on any file during spawn().
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51647 Signed-off-by: Doug Lyons douglyons@douglyons.com Signed-off-by: Thomas Faber thomas.faber@reactos.org --- dlls/msvcrt/file.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c index fd7168991f4..e954460ea9a 100644 --- a/dlls/msvcrt/file.c +++ b/dlls/msvcrt/file.c @@ -543,7 +543,7 @@ unsigned msvcrt_create_io_inherit_block(WORD *size, BYTE **block) for (fd = 0; fd < last_fd; fd++) { /* to be inherited, we need it to be open, and that DONTINHERIT isn't set */ - fdinfo = get_ioinfo(fd); + fdinfo = get_ioinfo_nolock(fd); if ((fdinfo->wxflag & (WX_OPEN | WX_DONTINHERIT)) == WX_OPEN) { *wxflag_ptr = fdinfo->wxflag; @@ -554,7 +554,6 @@ unsigned msvcrt_create_io_inherit_block(WORD *size, BYTE **block) *wxflag_ptr = 0; *handle_ptr = INVALID_HANDLE_VALUE; } - release_ioinfo(fdinfo); wxflag_ptr++; handle_ptr++; } return TRUE;
Signed-off-by: Thomas Faber thomas.faber@reactos.org --- This comes second since the test will deadlock without the fix applied. --- dlls/msvcrt/tests/file.c | 42 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-)
diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c index 7a33ae24230..a273d8a1285 100644 --- a/dlls/msvcrt/tests/file.c +++ b/dlls/msvcrt/tests/file.c @@ -1565,6 +1565,18 @@ static void test_stdout_handle( STARTUPINFOA *startup, char *cmdline, HANDLE hst DeleteFileA( "fdopen.err" ); }
+static unsigned WINAPI read_pipe_thread(void *argument) +{ + unsigned char buffer[2]; + int ret; + int *pipefds = argument; + + ret = _read(pipefds[0], buffer, sizeof(buffer)); + ok(ret == 1, "ret = %d\n", ret); + ok(buffer[0] == 'a', "%x\n", buffer[0]); + return 0; +} + static void test_file_inherit( const char* selfname ) { int fd; @@ -1574,6 +1586,9 @@ static void test_file_inherit( const char* selfname ) STARTUPINFOA startup; SECURITY_ATTRIBUTES sa; HANDLE handles[3]; + HANDLE thread_handle; + int pipefds[2]; + intptr_t ret;
fd = open ("fdopen.tst", O_CREAT | O_RDWR | O_BINARY, _S_IREAD |_S_IWRITE); ok(fd != -1, "Couldn't create test file\n"); @@ -1582,7 +1597,8 @@ static void test_file_inherit( const char* selfname ) arg_v[2] = "inherit"; arg_v[3] = buffer; sprintf(buffer, "%d", fd); arg_v[4] = 0; - _spawnvp(_P_WAIT, selfname, arg_v); + ret = _spawnvp(_P_WAIT, selfname, arg_v); + ok(ret == 0, "_spawnvp returned %d, errno %d\n", ret, errno); ok(tell(fd) == 8, "bad position %lu expecting 8\n", tell(fd)); lseek(fd, 0, SEEK_SET); ok(read(fd, buffer, sizeof (buffer)) == 8 && memcmp(buffer, "Success", 8) == 0, "Couldn't read back the data\n"); @@ -1595,12 +1611,34 @@ static void test_file_inherit( const char* selfname ) arg_v[2] = "inherit_no"; arg_v[3] = buffer; sprintf(buffer, "%d", fd); arg_v[4] = 0; - _spawnvp(_P_WAIT, selfname, arg_v); + ret = _spawnvp(_P_WAIT, selfname, arg_v); + ok(ret == 0, "_spawnvp returned %d, errno %d\n", ret, errno); ok(tell(fd) == 0, "bad position %lu expecting 0\n", tell(fd)); ok(read(fd, buffer, sizeof (buffer)) == 0, "Found unexpected data (%s)\n", buffer); close (fd); ok(unlink("fdopen.tst") == 0, "Couldn't unlink\n");
+ /* Show that spawn works while a read is active */ + ok(_pipe(pipefds, 1, O_BINARY) == 0, "_pipe() failed\n"); + thread_handle = (HANDLE)_beginthreadex(NULL, 0, read_pipe_thread, pipefds, 0, NULL); + Sleep(100); /* try to make sure the thread is reading */ + fd = open ("fdopen.tst", O_CREAT | O_RDWR | O_BINARY, _S_IREAD |_S_IWRITE); + ok(fd != -1, "Couldn't create test file\n"); + arg_v[1] = "tests/file.c"; + arg_v[2] = "inherit"; + arg_v[3] = buffer; sprintf(buffer, "%d", fd); + arg_v[4] = 0; + ret = _spawnvp(_P_WAIT, selfname, arg_v); + ok(ret == 0, "_spawnvp returned %d, errno %d\n", ret, errno); + ok(tell(fd) == 8, "bad position %u expecting 8\n", tell(fd)); + lseek(fd, 0, SEEK_SET); + ok(read(fd, buffer, sizeof (buffer)) == 8 && memcmp(buffer, "Success", 8) == 0, "Couldn't read back the data\n"); + close (fd); + ok(unlink("fdopen.tst") == 0, "Couldn't unlink\n"); + _write(pipefds[1], "a", 1); + WaitForSingleObject(thread_handle, INFINITE); + CloseHandle(thread_handle); + /* make file handle inheritable */ sa.nLength = sizeof(sa); sa.lpSecurityDescriptor = NULL;
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=101751
Your paranoid android.
=== build (build log) ===
error: corrupt patch at line 52 Task: Patch failed to apply
=== debiant2 (build log) ===
error: corrupt patch at line 52 Task: Patch failed to apply
=== debiant2 (build log) ===
error: corrupt patch at line 52 Task: Patch failed to apply
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=101750
Your paranoid android.
=== debiant2 (build log) ===
error: patch failed: dlls/msvcrt/file.c:543 Task: Patch failed to apply
=== debiant2 (build log) ===
error: patch failed: dlls/msvcrt/file.c:543 Task: Patch failed to apply