Don't include 'sync ' in the semaphore name because it will end up as a
separate argument in the child process, causing it to not find the
semaphore.
Switch the child to OpenSemaphoreA() to reduce the risk of accidentally
create a new semaphore instead of opening the parent's one.
Use wait_child_process() instead of a raw WaitForSingleObject(). The
timeout is longer but the process is expected to exit immediately
anyway and this allows proper handling of child failures (such as if
there is a bug with the semaphore handling).
Signed-off-by: Francois Gouget <fgouget(a)codeweavers.com>
---
The lack of checks and the short 1s timeout that this caused mostly
masked the issue.
dlls/kernel32/tests/process.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/dlls/kernel32/tests/process.c b/dlls/kernel32/tests/process.c
index 264f737178f..e54c43ca942 100644
--- a/dlls/kernel32/tests/process.c
+++ b/dlls/kernel32/tests/process.c
@@ -2832,7 +2832,8 @@ static void test_WaitForJobObject(void)
ok(dwret == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", dwret);
sprintf(buffer, "sync kernel32-process-%x", GetCurrentProcessId());
- sem = CreateSemaphoreA(NULL, 0, 1, buffer);
+ sem = CreateSemaphoreA(NULL, 0, 1, buffer + 5);
+ ok(sem != NULL, "CreateSemaphoreA failed le=%u\n", GetLastError());
create_process(buffer, &pi);
ret = pAssignProcessToJobObject(job, pi.hProcess);
@@ -2842,10 +2843,11 @@ static void test_WaitForJobObject(void)
dwret = WaitForSingleObject(job, 100);
ok(dwret == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", dwret);
- WaitForSingleObject(pi.hProcess, 1000);
+ wait_child_process(pi.hProcess);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
CloseHandle(job);
+ CloseHandle(sem);
}
static HANDLE test_AddSelfToJob(void)
@@ -4057,9 +4059,14 @@ START_TEST(process)
}
else if (!strcmp(myARGV[2], "sync") && myARGC >= 4)
{
- HANDLE sem = CreateSemaphoreA(NULL, 0, 1, myARGV[3]);
- ok(sem != 0, "Could not get the %s semaphore: le=%u\n", myARGV[3], GetLastError());
- if (sem) WaitForSingleObject(sem, 30000);
+ HANDLE sem = OpenSemaphoreA(SYNCHRONIZE, FALSE, myARGV[3]);
+ ok(sem != 0, "OpenSemaphoreA(%s) failed le=%u\n", myARGV[3], GetLastError());
+ if (sem)
+ {
+ DWORD ret = WaitForSingleObject(sem, 30000);
+ ok(ret == WAIT_OBJECT_0, "WaitForSingleObject(%s) returned %u\n", myARGV[3], ret);
+ CloseHandle(sem);
+ }
return;
}
else if (!strcmp(myARGV[2], "exit"))
--
2.20.1