1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5/*============================================================
6**
7** Source: childprocess.c
8**
9** Purpose: Test to ensure that OpenEventW() works when
10** opening an event created by another process. The test
11** program launches this program as a child, which creates
12** a named, initially-unset event. The child waits up to
13** 10 seconds for the parent process to open that event
14** and set it, and returns PASS if the event was set or FAIL
15** otherwise. The parent process checks the return value
16** from the child to verify that the opened event was
17** properly used across processes.
18**
19** Dependencies: PAL_Initialize
20** PAL_Terminate
21** CreateEventW
22** WaitForSingleObject
23** CloseHandle
24**
25**
26**=========================================================*/
27
28#include <palsuite.h>
29
30int __cdecl main( int argc, char **argv )
31{
32 /* local variables */
33 HANDLE hEvent = NULL;
34 WCHAR wcName[] = {'P','A','L','R','o','c','k','s','\0'};
35 LPWSTR lpName = wcName;
36
37 int result = PASS;
38
39 /* initialize the PAL */
40 if( PAL_Initialize(argc, argv) != 0 )
41 {
42 return( FAIL );
43 }
44
45
46 /* open a handle to the event created in the child process */
47 hEvent = OpenEventW( EVENT_ALL_ACCESS, /* we want all rights */
48 FALSE, /* no inherit */
49 lpName );
50
51 if( hEvent == NULL )
52 {
53 /* ERROR */
54 Trace( "ERROR:%lu:OpenEventW() call failed\n", GetLastError() );
55 result = FAIL;
56 goto parentwait;
57 }
58
59 /* set the event -- should take effect in the child process */
60 if( ! SetEvent( hEvent ) )
61 {
62 /* ERROR */
63 Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() );
64 result = FAIL;
65 }
66
67parentwait:
68 /* close the event handle */
69 if( ! CloseHandle( hEvent ) )
70 {
71 /* ERROR */
72 Fail( "ERROR:%lu:CloseHandle() call failed in child\n",
73 GetLastError());
74 }
75
76 /* terminate the PAL */
77 PAL_TerminateEx(result);
78
79 /* return success or failure */
80 return result;
81}
82