ReactOS  0.4.12-dev-375-g61fed54
ServiceArgs.c File Reference
#include "precomp.h"
Include dependency graph for ServiceArgs.c:

Go to the source code of this file.

Functions

static void send_msg (const char *type, const char *msg)
 
static void service_ok (int cnd, const char *msg,...)
 
static VOID WINAPI service_handler (DWORD ctrl)
 
static void service_main_common (void)
 
static void WINAPI service_mainA (DWORD service_argc, char **service_argv)
 
static void WINAPI service_mainW (DWORD service_argc, WCHAR **service_argv)
 
static void service_process (BOOLEAN unicode)
 
static SC_HANDLE register_service (PCWSTR extra_args)
 
static DWORD WINAPI pipe_thread (void *arg)
 
static void test_startA (SC_HANDLE service_handle, int service_argc, const char **service_argv)
 
static void test_startW (SC_HANDLE service_handle, int service_argc, const WCHAR **service_argv)
 
static void test_runner (BOOLEAN unicode, PCWSTR extra_args, int service_argc, void *service_argv)
 
 START_TEST (ServiceArgs)
 

Variables

static char ** argv
 
static int argc
 
static HANDLE pipe_handle = INVALID_HANDLE_VALUE
 
static char service_nameA [100]
 
static WCHAR service_nameW [100]
 
static WCHAR named_pipe_name [100]
 
static SC_HANDLE scm_handle
 
static SERVICE_STATUS_HANDLE service_handle
 

Function Documentation

◆ pipe_thread()

static DWORD WINAPI pipe_thread ( void arg)
static

Definition at line 252 of file ServiceArgs.c.

253 {
254  char buf[512];
255  DWORD read;
256  BOOL res;
257 
259  ok(res || GetLastError() == ERROR_PIPE_CONNECTED, "ConnectNamedPipe failed: %lu\n", GetLastError());
260 
261  while (1)
262  {
263  res = ReadFile(pipe_handle, buf, sizeof(buf), &read, NULL);
264  if (!res)
265  {
267  "ReadFile failed: %lu\n", GetLastError());
268  break;
269  }
270 
271  if (!strncmp(buf, "TRACE:", 6))
272  {
273  trace("service trace: %s\n", buf+6);
274  }
275  else if (!strncmp(buf, "OK:", 3))
276  {
277  ok(1, "service: %s\n", buf+3);
278  }
279  else if (!strncmp(buf, "FAIL:", 5))
280  {
281  ok(0, "service: %s\n", buf+5);
282  }
283  else
284  {
285  ok(0, "malformed service message: %s\n", buf);
286  }
287  }
288 
290  //trace("pipe disconnected\n");
291  return 0;
292 }
#define trace(...)
Definition: kmt_test.h:217
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
smooth NULL
Definition: ftsmooth.c:416
#define ok(value,...)
Definition: CComObject.cpp:34
unsigned int BOOL
Definition: ntddk_ex.h:94
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ERROR_BROKEN_PIPE
Definition: winerror.h:183
#define ERROR_PIPE_CONNECTED
Definition: winerror.h:352
BOOL WINAPI DisconnectNamedPipe(HANDLE hNamedPipe)
Definition: npipe.c:961
static HANDLE pipe_handle
Definition: ServiceArgs.c:14
GLuint res
Definition: glext.h:9613
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
BOOL WINAPI ConnectNamedPipe(IN HANDLE hNamedPipe, IN LPOVERLAPPED lpOverlapped)
Definition: npipe.c:701
_CRTIMP int __cdecl read(_In_ int _FileHandle, _Out_writes_bytes_(_MaxCharCount) void *_DstBuf, _In_ unsigned int _MaxCharCount)

Referenced by test_runner().

◆ register_service()

static SC_HANDLE register_service ( PCWSTR  extra_args)
static

Definition at line 226 of file ServiceArgs.c.

227 {
228  WCHAR service_cmd[MAX_PATH+150];
229  SC_HANDLE service;
230 
231  GetModuleFileNameW(NULL, service_cmd, MAX_PATH);
232 
233  StringCbCatW(service_cmd, sizeof(service_cmd), L" ServiceArgs ");
234  StringCbCatW(service_cmd, sizeof(service_cmd), service_nameW);
235  StringCbCatW(service_cmd, sizeof(service_cmd), extra_args);
236 
237  trace("service_cmd \"%ls\"\n", service_cmd);
238 
241  service_cmd, NULL, NULL, NULL, NULL, NULL);
242  if (!service && GetLastError() == ERROR_ACCESS_DENIED)
243  {
244  skip("Not enough access right to create service\n");
245  return NULL;
246  }
247 
248  ok(service != NULL, "CreateService failed: %lu\n", GetLastError());
249  return service;
250 }
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:607
#define trace(...)
Definition: kmt_test.h:217
#define SERVICE_ERROR_IGNORE
Definition: cmtypes.h:979
SC_HANDLE WINAPI CreateServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, LPCWSTR lpDisplayName, DWORD dwDesiredAccess, DWORD dwServiceType, DWORD dwStartType, DWORD dwErrorControl, LPCWSTR lpBinaryPathName, LPCWSTR lpLoadOrderGroup, LPDWORD lpdwTagId, LPCWSTR lpDependencies, LPCWSTR lpServiceStartName, LPCWSTR lpPassword)
Definition: scm.c:808
static SC_HANDLE scm_handle
Definition: ServiceArgs.c:20
__wchar_t WCHAR
Definition: xmlstorage.h:180
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define SERVICE_ALL_ACCESS
Definition: winsvc.h:62
STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:342
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
smooth NULL
Definition: ftsmooth.c:416
#define SERVICE_WIN32_OWN_PROCESS
Definition: cmtypes.h:960
#define ok(value,...)
Definition: CComObject.cpp:34
#define MAX_PATH
Definition: compat.h:26
static const WCHAR L[]
Definition: oid.c:1087
#define skip(...)
Definition: CString.cpp:57
static WCHAR service_nameW[100]
Definition: ServiceArgs.c:16
#define SERVICE_DEMAND_START
Definition: cmtypes.h:976

Referenced by test_runner().

◆ send_msg()

static void send_msg ( const char type,
const char msg 
)
static

Definition at line 23 of file ServiceArgs.c.

24 {
25  DWORD written = 0;
26  char buf[512];
27 
28  StringCbPrintfA(buf, sizeof(buf), "%s:%s", type, msg);
29  WriteFile(pipe_handle, buf, strlen(buf)+1, &written, NULL);
30 }
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
UINT msg
Definition: msvc.h:92
smooth NULL
Definition: ftsmooth.c:416
STRSAFEAPI StringCbPrintfA(STRSAFE_LPSTR pszDest, size_t cbDest, STRSAFE_LPCSTR pszFormat,...)
Definition: strsafe.h:547
unsigned long DWORD
Definition: ntddk_ex.h:95
static HANDLE pipe_handle
Definition: ServiceArgs.c:14

Referenced by service_ok().

◆ service_handler()

static VOID WINAPI service_handler ( DWORD  ctrl)
static

Definition at line 58 of file ServiceArgs.c.

59 {
61 
62  status.dwServiceType = SERVICE_WIN32;
63  status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
64  status.dwWin32ExitCode = 0;
65  status.dwServiceSpecificExitCode = 0;
66  status.dwCheckPoint = 0;
67  status.dwWaitHint = 0;
68 
69  switch(ctrl)
70  {
72  status.dwCurrentState = SERVICE_STOP_PENDING;
73  status.dwControlsAccepted = 0;
75  default:
76  status.dwCurrentState = SERVICE_RUNNING;
78  }
79 }
#define SERVICE_ACCEPT_STOP
Definition: winsvc.h:28
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:986
#define SERVICE_RUNNING
Definition: winsvc.h:24
#define ctrl
Definition: input.c:1669
#define SERVICE_WIN32
Definition: cmtypes.h:962
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
static SERVICE_STATUS status
Definition: service.c:31
static SERVICE_STATUS_HANDLE service_handle
Definition: ServiceArgs.c:21
#define SERVICE_STOP_PENDING
Definition: winsvc.h:23
Definition: ps.c:97

Referenced by service_main_common().

◆ service_main_common()

static void service_main_common ( void  )
static

Definition at line 81 of file ServiceArgs.c.

82 {
84  BOOL res;
85 
87  service_ok(service_handle != NULL, "RegisterServiceCtrlHandler failed: %lu\n", GetLastError());
88  if (!service_handle)
89  return;
90 
91  status.dwServiceType = SERVICE_WIN32;
92  status.dwCurrentState = SERVICE_RUNNING;
93  status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
94  status.dwWin32ExitCode = 0;
95  status.dwServiceSpecificExitCode = 0;
96  status.dwCheckPoint = 0;
97  status.dwWaitHint = 10000;
99  service_ok(res, "SetServiceStatus(SERVICE_RUNNING) failed: %lu", GetLastError());
100 
101  Sleep(100);
102 
103  status.dwCurrentState = SERVICE_STOPPED;
104  status.dwControlsAccepted = 0;
106  service_ok(res, "SetServiceStatus(SERVICE_STOPPED) failed: %lu", GetLastError());
107 }
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
#define SERVICE_ACCEPT_STOP
Definition: winsvc.h:28
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerW(LPCWSTR lpServiceName, LPHANDLER_FUNCTION lpHandlerProc)
Definition: sctrl.c:732
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:986
#define SERVICE_STOPPED
Definition: winsvc.h:21
#define SERVICE_RUNNING
Definition: winsvc.h:24
smooth NULL
Definition: ftsmooth.c:416
#define SERVICE_ACCEPT_SHUTDOWN
Definition: winsvc.h:30
unsigned int BOOL
Definition: ntddk_ex.h:94
static void service_ok(int cnd, const char *msg,...)
Definition: ServiceArgs.c:46
static VOID WINAPI service_handler(DWORD ctrl)
Definition: ServiceArgs.c:58
#define SERVICE_WIN32
Definition: cmtypes.h:962
static WCHAR service_nameW[100]
Definition: ServiceArgs.c:16
GLuint res
Definition: glext.h:9613
static SERVICE_STATUS status
Definition: service.c:31
static SERVICE_STATUS_HANDLE service_handle
Definition: ServiceArgs.c:21
Definition: ps.c:97

Referenced by service_mainA(), and service_mainW().

◆ service_mainA()

static void WINAPI service_mainA ( DWORD  service_argc,
char **  service_argv 
)
static

Definition at line 124 of file ServiceArgs.c.

125 {
126  int i;
127  char *next_arg;
128  char *next_arg_aligned;
129 
130  service_ok(service_argc == argc - 3, "service_argc = %d, expected %d", service_argc, argc - 3);
131  if (service_argc == argc - 3)
132  {
133  service_ok(!strcmp(service_argv[0], service_nameA), "service_argv[0] = %s, expected %s", service_argv[0], service_nameA);
134  service_ok(service_argv[0] == (char *)&service_argv[service_argc] ||
135  service_argv[1] == (char *)&service_argv[service_argc] ||
136  service_argv[1] == (char *)(((ULONG_PTR)&service_argv[service_argc] + 7) & ~7), "service_argv[0] = %p, [1] = %p, expected one of them to be %p", service_argv[0], service_argv[1], &service_argv[service_argc]);
137  //service_trace("service_argv[0] = %p", service_argv[0]);
138  next_arg_aligned = next_arg = NULL;
139  for (i = 1; i < service_argc; i++)
140  {
141  //service_trace("service_argv[%d] = %p", i, service_argv[i]);
142  service_ok(!strcmp(service_argv[i], argv[i + 3]), "service_argv[%d] = %s, expected %s", i, service_argv[i], argv[i + 3]);
143  service_ok(next_arg == NULL ||
144  service_argv[i] == next_arg ||
145  service_argv[i] == next_arg_aligned, "service_argv[%d] = %p, expected %p or %p", i, service_argv[i], next_arg, next_arg_aligned);
146  next_arg = service_argv[i];
147  next_arg += 2 * (strlen(next_arg) + 1);
148  next_arg_aligned = (char *)(((ULONG_PTR)next_arg + 3) & ~3);
149  }
150  }
151 
153 }
static int argc
Definition: ServiceArgs.c:12
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static void service_main_common(void)
Definition: ServiceArgs.c:81
static char ** argv
Definition: ServiceArgs.c:11
uint32_t ULONG_PTR
Definition: typedefs.h:63
GLenum GLclampf GLint i
Definition: glfuncs.h:14
smooth NULL
Definition: ftsmooth.c:416
static void service_ok(int cnd, const char *msg,...)
Definition: ServiceArgs.c:46
char * next_arg(char *src, char needle)
Definition: rdesktop.c:1174
static char service_nameA[100]
Definition: ServiceArgs.c:15
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469

Referenced by service_process().

◆ service_mainW()

static void WINAPI service_mainW ( DWORD  service_argc,
WCHAR **  service_argv 
)
static

Definition at line 155 of file ServiceArgs.c.

156 {
157  int i;
158  WCHAR argW[32];
159  WCHAR *next_arg;
160  WCHAR *next_arg_aligned;
161 
162  service_ok(service_argc == argc - 3, "service_argc = %d, expected %d", service_argc, argc - 3);
163  if (service_argc == argc - 3)
164  {
165  service_ok(!wcscmp(service_argv[0], service_nameW), "service_argv[0] = %ls, expected %ls", service_argv[0], service_nameW);
166  service_ok(service_argv[0] == (WCHAR *)&service_argv[service_argc] ||
167  service_argv[1] == (WCHAR *)&service_argv[service_argc] ||
168  service_argv[1] == (WCHAR *)(((ULONG_PTR)&service_argv[service_argc] + 7) & ~7), "service_argv[0] = %p, [1] = %p, expected one of them to be %p", service_argv[0], service_argv[1], &service_argv[service_argc]);
169  //service_trace("service_argv[0] = %p", service_argv[0]);
170  next_arg_aligned = next_arg = NULL;
171  for (i = 1; i < service_argc; i++)
172  {
173  //service_trace("service_argv[%d] = %p", i, service_argv[i]);
174  MultiByteToWideChar(CP_ACP, 0, argv[i + 3], -1, argW, _countof(argW));
175  service_ok(!wcscmp(service_argv[i], argW), "service_argv[%d] = %ls, expected %ls", i, service_argv[i], argW);
176  service_ok(next_arg == NULL ||
177  service_argv[i] == next_arg ||
178  service_argv[i] == next_arg_aligned, "service_argv[%d] = %p, expected %p or %p", i, service_argv[i], next_arg, next_arg_aligned);
179  next_arg = service_argv[i];
180  next_arg += wcslen(next_arg) + 1;
181  next_arg_aligned = (WCHAR *)(((ULONG_PTR)next_arg + 3) & ~3);
182  }
183  }
184 
186 }
static int argc
Definition: ServiceArgs.c:12
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define CP_ACP
Definition: compat.h:99
#define _countof(array)
Definition: fontsub.cpp:30
static void service_main_common(void)
Definition: ServiceArgs.c:81
static char ** argv
Definition: ServiceArgs.c:11
uint32_t ULONG_PTR
Definition: typedefs.h:63
GLenum GLclampf GLint i
Definition: glfuncs.h:14
smooth NULL
Definition: ftsmooth.c:416
static void service_ok(int cnd, const char *msg,...)
Definition: ServiceArgs.c:46
char * next_arg(char *src, char needle)
Definition: rdesktop.c:1174
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define MultiByteToWideChar
Definition: compat.h:100
static WCHAR service_nameW[100]
Definition: ServiceArgs.c:16
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by service_process().

◆ service_ok()

static void service_ok ( int  cnd,
const char msg,
  ... 
)
static

Definition at line 46 of file ServiceArgs.c.

47 {
49  char buf[512];
50 
52  StringCbVPrintfA(buf, sizeof(buf), msg, valist);
53  va_end(valist);
54 
55  send_msg(cnd ? "OK" : "FAIL", buf);
56 }
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define va_end(ap)
Definition: acmsvcex.h:90
UINT msg
Definition: msvc.h:92
char * va_list
Definition: acmsvcex.h:78
STRSAFEAPI StringCbVPrintfA(STRSAFE_LPSTR pszDest, size_t cbDest, STRSAFE_LPCSTR pszFormat, va_list argList)
Definition: strsafe.h:502
#define va_start(ap, A)
Definition: acmsvcex.h:91
static __ms_va_list valist
Definition: printf.c:59
static void send_msg(const char *type, const char *msg)
Definition: ServiceArgs.c:23

Referenced by report_service_status(), service_main(), service_main_common(), service_mainA(), service_mainW(), service_process(), start_service(), test_tcp(), and test_udp().

◆ service_process()

static void service_process ( BOOLEAN  unicode)
static

Definition at line 188 of file ServiceArgs.c.

189 {
190  BOOL res;
191 
192  SERVICE_TABLE_ENTRYA servtblA[] =
193  {
195  { NULL, NULL }
196  };
197  SERVICE_TABLE_ENTRYW servtblW[] =
198  {
200  { NULL, NULL }
201  };
202 
204  if (!res)
205  return;
206 
209  return;
210 
211  //service_trace("Starting...");
212  if (unicode)
213  {
214  res = StartServiceCtrlDispatcherW(servtblW);
215  service_ok(res, "StartServiceCtrlDispatcherW failed: %lu\n", GetLastError());
216  }
217  else
218  {
219  res = StartServiceCtrlDispatcherA(servtblA);
220  service_ok(res, "StartServiceCtrlDispatcherA failed: %lu\n", GetLastError());
221  }
222 
224 }
#define CloseHandle
Definition: compat.h:398
BOOL WINAPI WaitNamedPipeW(LPCWSTR lpNamedPipeName, DWORD nTimeOut)
Definition: npipe.c:458
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define NMPWAIT_USE_DEFAULT_WAIT
Definition: winbase.h:134
BOOL WINAPI StartServiceCtrlDispatcherW(const SERVICE_TABLE_ENTRYW *lpServiceStartTable)
Definition: sctrl.c:1123
BOOL WINAPI StartServiceCtrlDispatcherA(const SERVICE_TABLE_ENTRYA *lpServiceStartTable)
Definition: sctrl.c:1024
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
#define OPEN_EXISTING
Definition: compat.h:426
unsigned int BOOL
Definition: ntddk_ex.h:94
static void service_ok(int cnd, const char *msg,...)
Definition: ServiceArgs.c:46
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
static void WINAPI service_mainW(DWORD service_argc, WCHAR **service_argv)
Definition: ServiceArgs.c:155
static WCHAR named_pipe_name[100]
Definition: ServiceArgs.c:17
static HANDLE pipe_handle
Definition: ServiceArgs.c:14
static char service_nameA[100]
Definition: ServiceArgs.c:15
static void WINAPI service_mainA(DWORD service_argc, char **service_argv)
Definition: ServiceArgs.c:124
#define CreateFileW
Definition: compat.h:400
static WCHAR service_nameW[100]
Definition: ServiceArgs.c:16
GLuint res
Definition: glext.h:9613

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( ServiceArgs  )

Definition at line 382 of file ServiceArgs.c.

383 {
385 
387  ok(scm_handle != NULL, "OpenSCManager failed: %lu\n", GetLastError());
388  if (!scm_handle)
389  {
390  skip("Failed to open service control manager. Skipping test\n");
391  return;
392  }
393 
394  if (argc < 3)
395  {
396  char *service_argvA[10];
397  WCHAR *service_argvW[10];
398 
399  test_runner(FALSE, L" A", 0, NULL);
400  test_runner(FALSE, L" W", 0, NULL);
401  test_runner(TRUE, L" A", 0, NULL);
402  test_runner(TRUE, L" W", 0, NULL);
403 
404  service_argvA[0] = "x";
405  service_argvW[0] = L"x";
406  test_runner(FALSE, L" A x", 1, service_argvA);
407  test_runner(FALSE, L" W x", 1, service_argvA);
408  test_runner(TRUE, L" A x", 1, service_argvW);
409  test_runner(TRUE, L" W x", 1, service_argvW);
410 
411  service_argvA[1] = "y";
412  service_argvW[1] = L"y";
413  test_runner(FALSE, L" A x y", 2, service_argvA);
414  test_runner(FALSE, L" W x y", 2, service_argvA);
415  test_runner(TRUE, L" A x y", 2, service_argvW);
416  test_runner(TRUE, L" W x y", 2, service_argvW);
417 
418  service_argvA[0] = "ab";
419  service_argvW[0] = L"ab";
420  test_runner(FALSE, L" A ab y", 2, service_argvA);
421  test_runner(FALSE, L" W ab y", 2, service_argvA);
422  test_runner(TRUE, L" A ab y", 2, service_argvW);
423  test_runner(TRUE, L" W ab y", 2, service_argvW);
424 
425  service_argvA[0] = "abc";
426  service_argvW[0] = L"abc";
427  test_runner(FALSE, L" A abc y", 2, service_argvA);
428  test_runner(FALSE, L" W abc y", 2, service_argvA);
429  test_runner(TRUE, L" A abc y", 2, service_argvW);
430  test_runner(TRUE, L" W abc y", 2, service_argvW);
431 
432  service_argvA[0] = "abcd";
433  service_argvW[0] = L"abcd";
434  test_runner(FALSE, L" A abcd y", 2, service_argvA);
435  test_runner(FALSE, L" W abcd y", 2, service_argvA);
436  test_runner(TRUE, L" A abcd y", 2, service_argvW);
437  test_runner(TRUE, L" W abcd y", 2, service_argvW);
438 
439  service_argvA[0] = "abcde";
440  service_argvW[0] = L"abcde";
441  test_runner(FALSE, L" A abcde y", 2, service_argvA);
442  test_runner(FALSE, L" W abcde y", 2, service_argvA);
443  test_runner(TRUE, L" A abcde y", 2, service_argvW);
444  test_runner(TRUE, L" W abcde y", 2, service_argvW);
445 
446  service_argvA[0] = "abcdef";
447  service_argvW[0] = L"abcdef";
448  test_runner(FALSE, L" A abcdef y", 2, service_argvA);
449  test_runner(FALSE, L" W abcdef y", 2, service_argvA);
450  test_runner(TRUE, L" A abcdef y", 2, service_argvW);
451  test_runner(TRUE, L" W abcdef y", 2, service_argvW);
452 
453  service_argvA[0] = "abcdefg";
454  service_argvW[0] = L"abcdefg";
455  test_runner(FALSE, L" A abcdefg y", 2, service_argvA);
456  test_runner(FALSE, L" W abcdefg y", 2, service_argvA);
457  test_runner(TRUE, L" A abcdefg y", 2, service_argvW);
458  test_runner(TRUE, L" W abcdefg y", 2, service_argvW);
459 
460  service_argvA[0] = "";
461  service_argvW[0] = L"";
462  test_runner(FALSE, L" A \"\" y", 2, service_argvA);
463  test_runner(FALSE, L" W \"\" y", 2, service_argvA);
464  test_runner(TRUE, L" A \"\" y", 2, service_argvW);
465  test_runner(TRUE, L" W \"\" y", 2, service_argvW);
466  }
467  else
468  {
471  StringCbPrintfW(named_pipe_name, sizeof(named_pipe_name), L"\\\\.\\pipe\\%ls_pipe", service_nameW);
472  if (!strcmp(argv[3], "A"))
474  else
476  }
477 
479 }
static void test_runner(BOOLEAN unicode, PCWSTR extra_args, int service_argc, void *service_argv)
Definition: ServiceArgs.c:334
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
static SC_HANDLE scm_handle
Definition: ServiceArgs.c:20
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define CP_ACP
Definition: compat.h:99
#define _countof(array)
Definition: fontsub.cpp:30
static void service_process(BOOLEAN unicode)
Definition: ServiceArgs.c:188
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
static char ** argv
Definition: ServiceArgs.c:11
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:577
smooth NULL
Definition: ftsmooth.c:416
STRSAFEAPI StringCbPrintfW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:557
#define ok(value,...)
Definition: CComObject.cpp:34
int winetest_get_mainargs(char ***pargv)
static const WCHAR L[]
Definition: oid.c:1087
static WCHAR named_pipe_name[100]
Definition: ServiceArgs.c:17
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2011
#define skip(...)
Definition: CString.cpp:57
static char service_nameA[100]
Definition: ServiceArgs.c:15
#define SC_MANAGER_ALL_ACCESS
Definition: winsvc.h:13
#define MultiByteToWideChar
Definition: compat.h:100
static WCHAR service_nameW[100]
Definition: ServiceArgs.c:16
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469

◆ test_runner()

static void test_runner ( BOOLEAN  unicode,
PCWSTR  extra_args,
int  service_argc,
void service_argv 
)
static

Definition at line 334 of file ServiceArgs.c.

335 {
336  HANDLE thread;
337  SC_HANDLE service_handle;
338  BOOL res;
339 
340  StringCbPrintfW(service_nameW, sizeof(service_nameW), L"WineTestService%lu", GetTickCount());
342  //trace("service_name: %ls\n", service_nameW);
343  StringCbPrintfW(named_pipe_name, sizeof(named_pipe_name), L"\\\\.\\pipe\\%ls_pipe", service_nameW);
344 
346  PIPE_TYPE_MESSAGE|PIPE_READMODE_MESSAGE|PIPE_WAIT, 10, 2048, 2048, 10000, NULL);
347  ok(pipe_handle != INVALID_HANDLE_VALUE, "CreateNamedPipe failed: %lu\n", GetLastError());
349  return;
350 
352  ok(thread != NULL, "CreateThread failed: %lu\n", GetLastError());
353  if (!thread)
354  goto Quit;
355 
356  service_handle = register_service(extra_args);
357  if (!service_handle)
358  goto Quit;
359 
360  //trace("starting...\n");
361 
362  if (unicode)
363  test_startW(service_handle, service_argc, service_argv);
364  else
365  test_startA(service_handle, service_argc, service_argv);
366 
368  ok(res, "DeleteService failed: %lu\n", GetLastError());
369 
371 
372  ok(WaitForSingleObject(thread, 10000) == WAIT_OBJECT_0, "Timeout waiting for thread\n");
373 
374 Quit:
375  if (thread)
377 
380 }
#define CloseHandle
Definition: compat.h:398
#define WideCharToMultiByte
Definition: compat.h:101
#define PIPE_TYPE_MESSAGE
Definition: winbase.h:168
#define CP_ACP
Definition: compat.h:99
#define _countof(array)
Definition: fontsub.cpp:30
static DWORD WINAPI pipe_thread(void *arg)
Definition: ServiceArgs.c:252
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:445
#define PIPE_WAIT
Definition: winbase.h:171
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI DeleteService(SC_HANDLE hService)
Definition: scm.c:916
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
static void test_startW(SC_HANDLE service_handle, int service_argc, const WCHAR **service_argv)
Definition: ServiceArgs.c:314
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:577
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:112
static void test_startA(SC_HANDLE service_handle, int service_argc, const char **service_argv)
Definition: ServiceArgs.c:294
smooth NULL
Definition: ftsmooth.c:416
STRSAFEAPI StringCbPrintfW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:557
#define ok(value,...)
Definition: CComObject.cpp:34
unsigned int BOOL
Definition: ntddk_ex.h:94
#define WAIT_OBJECT_0
Definition: winbase.h:387
static HANDLE thread
Definition: service.c:33
static const WCHAR L[]
Definition: oid.c:1087
static WCHAR named_pipe_name[100]
Definition: ServiceArgs.c:17
#define PIPE_READMODE_MESSAGE
Definition: winbase.h:170
static HANDLE pipe_handle
Definition: ServiceArgs.c:14
#define PIPE_ACCESS_INBOUND
Definition: winbase.h:165
static char service_nameA[100]
Definition: ServiceArgs.c:15
static WCHAR service_nameW[100]
Definition: ServiceArgs.c:16
GLuint res
Definition: glext.h:9613
HANDLE WINAPI CreateNamedPipeW(LPCWSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD nMaxInstances, DWORD nOutBufferSize, DWORD nInBufferSize, DWORD nDefaultTimeOut, LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: npipe.c:246
static SERVICE_STATUS_HANDLE service_handle
Definition: ServiceArgs.c:21
static SC_HANDLE register_service(PCWSTR extra_args)
Definition: ServiceArgs.c:226

Referenced by START_TEST().

◆ test_startA()

static void test_startA ( SC_HANDLE  service_handle,
int  service_argc,
const char **  service_argv 
)
static

Definition at line 294 of file ServiceArgs.c.

295 {
297  BOOL res;
298 
299  res = StartServiceA(service_handle, service_argc, service_argv);
300  ok(res, "StartService failed: %lu\n", GetLastError());
301  if (!res)
302  return;
303 
304  do
305  {
306  Sleep(100);
307  ZeroMemory(&status, sizeof(status));
309  } while (res && status.dwCurrentState != SERVICE_STOPPED);
310  ok(res, "QueryServiceStatus failed: %lu\n", GetLastError());
311  ok(status.dwCurrentState == SERVICE_STOPPED, "status.dwCurrentState = %lx\n", status.dwCurrentState);
312 }
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1635
#define SERVICE_STOPPED
Definition: winsvc.h:21
#define ok(value,...)
Definition: CComObject.cpp:34
BOOL WINAPI StartServiceA(SC_HANDLE hService, DWORD dwNumServiceArgs, LPCSTR *lpServiceArgVectors)
Definition: scm.c:2885
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL WINAPI QueryServiceStatus(SC_HANDLE hService, LPSERVICE_STATUS lpServiceStatus)
Definition: scm.c:2788
GLuint res
Definition: glext.h:9613
static SERVICE_STATUS status
Definition: service.c:31
static SERVICE_STATUS_HANDLE service_handle
Definition: ServiceArgs.c:21
Definition: ps.c:97

Referenced by test_runner().

◆ test_startW()

static void test_startW ( SC_HANDLE  service_handle,
int  service_argc,
const WCHAR **  service_argv 
)
static

Definition at line 314 of file ServiceArgs.c.

315 {
317  BOOL res;
318 
319  res = StartServiceW(service_handle, service_argc, service_argv);
320  ok(res, "StartService failed: %lu\n", GetLastError());
321  if (!res)
322  return;
323 
324  do
325  {
326  Sleep(100);
327  ZeroMemory(&status, sizeof(status));
329  } while (res && status.dwCurrentState != SERVICE_STOPPED);
330  ok(res, "QueryServiceStatus failed: %lu\n", GetLastError());
331  ok(status.dwCurrentState == SERVICE_STOPPED, "status.dwCurrentState = %lx\n", status.dwCurrentState);
332 }
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1635
#define SERVICE_STOPPED
Definition: winsvc.h:21
#define ok(value,...)
Definition: CComObject.cpp:34
BOOL WINAPI StartServiceW(SC_HANDLE hService, DWORD dwNumServiceArgs, LPCWSTR *lpServiceArgVectors)
Definition: scm.c:2923
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL WINAPI QueryServiceStatus(SC_HANDLE hService, LPSERVICE_STATUS lpServiceStatus)
Definition: scm.c:2788
GLuint res
Definition: glext.h:9613
static SERVICE_STATUS status
Definition: service.c:31
static SERVICE_STATUS_HANDLE service_handle
Definition: ServiceArgs.c:21
Definition: ps.c:97

Referenced by test_runner().

Variable Documentation

◆ argc

int argc
static

Definition at line 12 of file ServiceArgs.c.

Referenced by __declspec(), __getmainargs(), __GetMainArgs(), __wgetmainargs(), _CorExeMain(), _getopt_initialize(), _getopt_internal(), _main(), _tmain(), _tWinMain(), account(), ActiveXObject_value(), add_route(), AddService(), array_access(), Array_concat(), Array_indexOf(), Array_join(), Array_push(), Array_slice(), Array_sort(), Array_splice(), array_to_args(), Array_unshift(), ArrayConstr_isArray(), ArrayConstr_value(), BGStartCmd(), BlankArgument(), BookmarkCmd(), BoolConstr_value(), call_function(), CatCmd(), cd(), change_command(), ChdirCmd(), check_option(), ChmodCmd(), cmd_copy(), cmd_date(), cmd_mkdir(), cmd_mklink(), cmd_move(), cmd_replace(), cmd_setlocal(), cmd_time(), cmd_type(), cmdAccounts(), cmdComputer(), cmdConfig(), cmdContinue(), CmdDebugService(), cmdGroup(), cmdHelp(), cmdHelpMsg(), cmdLocalGroup(), cmdPause(), cmdStart(), cmdStatistics(), cmdStop(), cmdUse(), cmdUser(), CommandAttrib(), CommandChoice(), CommandDumpSector(), CommandFree(), CommandLineToArgv(), CommandLineToArgvT(), CommandLineToArgvW(), CommandPartInfo(), CommandTimer(), construct_function(), convert_add_cmd_line(), convert_params(), create_command(), CreateMain(), Date_setDate(), Date_setFullYear(), Date_setHours(), Date_setMilliseconds(), Date_setMinutes(), Date_setMonth(), Date_setSeconds(), Date_setTime(), Date_setUTCDate(), Date_setUTCFullYear(), Date_setUTCHours(), Date_setUTCMilliseconds(), Date_setUTCMinutes(), Date_setUTCMonth(), Date_setUTCSeconds(), Date_setYear(), Date_toLocaleTimeString(), date_utc(), DateConstr_parse(), DateConstr_UTC(), DateConstr_value(), DbgGdiKdbgCliCallback(), DebugCmd(), del_route(), delete(), delete_command(), DeleteCmd(), DirtyMain(), DiskFreeMain(), DismountMain(), disp_call(), disp_call_value(), DispatchEx_InvokeEx(), DisplayApplet(), do_attribute_tag_format(), do_chmod(), do_umask(), doChild(), doCrash(), document_write(), doDebugger(), domacro(), DoParse(), doproxy(), DriveTypeMain(), EchoCmd(), error_constr(), ErrorConstr_value(), EvalErrorConstr_value(), exec_source(), exprval_call(), FindHandler(), FsInfoMain(), Function_apply(), Function_call(), Function_invoke(), Function_value(), FunctionConstr_value(), get(), get_extrac_args(), get_pnames(), get_strarg(), get_utf8_args(), GetArgument(), GetCmd(), getit(), getopt(), getopt_long(), getopt_long_only(), getwhoisserver(), HandleDumpAttributes(), HandleImageArg(), HardLinkMain(), help(), help_main(), HelpCmd(), Host_Echo(), HostsCmd(), HTMLImageElementFactory_value(), idle(), ImageFile_ParseCmdline(), init(), InstallWindowsNt(), InteractiveConsole(), interp_assign_call(), interp_new(), InterpretCmd(), invoke_prop_func(), invoke_source(), invoke_value_proc(), isCmdWithArg(), jsdisp_call(), jsdisp_call_name(), jsdisp_call_value(), JSGlobal_decodeURI(), JSGlobal_decodeURIComponent(), JSGlobal_encodeURI(), JSGlobal_encodeURIComponent(), JSGlobal_escape(), JSGlobal_eval(), JSGlobal_isFinite(), JSGlobal_isNaN(), JSGlobal_parseFloat(), JSGlobal_parseInt(), JSGlobal_unescape(), JSON_parse(), JSON_stringify(), KdbCommand_Gdi_dumpht(), lcd(), list_main(), ListCmd(), LocalChdirCmd(), LocalChmodCmd(), LocalListCmd(), LocalMkdirCmd(), LocalPageCmd(), LocalRenameCmd(), LocalRmCmd(), LocalRmdirCmd(), LookupCmd(), ls(), macdef(), main(), makedir(), Math_abs(), Math_acos(), Math_asin(), Math_atan(), Math_atan2(), Math_ceil(), Math_cos(), Math_exp(), Math_floor(), Math_log(), Math_max(), Math_min(), Math_pow(), Math_round(), Math_sin(), Math_sqrt(), Math_tan(), mdelete(), mget(), MkdirCmd(), mls(), MlsCmd(), modtime(), mput(), MSVCRT20__getmainargs(), MSVCRT20__wgetmainargs(), newer(), no_stop_main(), NPP_New(), NtfsInfoMain(), NtProcessStartup(), Number_toExponential(), Number_toFixed(), Number_toPrecision(), Number_toString(), NumberConstr_value(), Object_defineProperty(), Object_getOwnPropertyDescriptor(), Object_hasOwnProperty(), Object_propertyIsEnumerable(), ObjectConstr_value(), ok_argsA_imp(), ok_argsW_imp(), OpenCmd(), optionInit(), optionParse(), PageCmd(), PageHeap_ParseCmdline(), parse_cmdlineargs(), parse_switches(), ParseArguments(), CCABManager::ParseCmdline(), ParseCmdline(), ParseCmdLine(), ParseCommandLine(), CConfiguration::ParseParameters(), pre_cpp_init(), prepare_test(), process_arguments(), TConfig::Process_Params(), process_switches(), ProcessCmdLine(), ProcessCommandLine(), put(), PutCmd(), QueryMain(), quote(), QuoteCmd(), RangeErrorConstr_value(), ReferenceErrorConstr_value(), reg_export(), regdump(), reget(), RegExp_exec(), RegExp_test(), RegExpConstr_value(), RegExpErrorConstr_value(), removedir(), renamefile(), rep_call(), restart(), RGlobCmd(), RmdirCmd(), rmthelp(), RmtHelpCmd(), rmtstatus(), RStartServiceA(), RStartServiceW(), RunInstallReactOS(), SchedServiceMain(), ScmLoadService(), ScmSendStartCommand(), ScmStartService(), ScmStartUserModeService(), select_main(), SelectDisk(), SelectPartition(), service_main(), service_mainA(), service_mainW(), ServiceMain(), ServiceStart(), SetCmd(), setdebug(), SetMain(), setnmap(), setntrans(), setpeer(), settype(), setup_scope(), shell(), ShellCmd(), site(), SiteCmd(), sizecmd(), SpoolGetCmd(), SpoolPutCmd(), START_TEST(), StartOneService(), startup(), StatisticsMain(), String_anchor(), String_charAt(), String_charCodeAt(), String_concat(), String_fontcolor(), String_fontsize(), String_indexOf(), String_lastIndexOf(), String_link(), String_match(), String_replace(), String_search(), String_slice(), String_split(), String_substr(), String_substring(), StringConstr_fromCharCode(), StringConstr_value(), SyntaxErrorConstr_value(), system_icmp(), test___getmainargs(), test__environ(), test__wenviron(), test_pipes_child(), ThemeServiceMain(), tokenizeCommand(), TypeCmd(), TypeErrorConstr_value(), update_loglevel(), URIErrorConstr_value(), UseCmdParameters(), user(), userlist(), VBArray_getItem(), VBArray_lbound(), VBArray_ubound(), VBArrayConstr_value(), verify_xpointers(), VolumeInfoMain(), VolumeMain(), WinMain(), wmain(), and wWinMain().

◆ argv

char** argv
static

Definition at line 11 of file ServiceArgs.c.

Referenced by service_mainA(), service_mainW(), and START_TEST().

◆ named_pipe_name

WCHAR named_pipe_name[100]
static

Definition at line 17 of file ServiceArgs.c.

Referenced by service_process(), START_TEST(), and test_runner().

◆ pipe_handle

HANDLE pipe_handle = INVALID_HANDLE_VALUE
static

Definition at line 14 of file ServiceArgs.c.

Referenced by pipe_thread(), send_msg(), service_process(), and test_runner().

◆ scm_handle

◆ service_handle

SERVICE_STATUS_HANDLE service_handle
static

◆ service_nameA

char service_nameA[100]
static

Definition at line 15 of file ServiceArgs.c.

Referenced by service_mainA(), service_process(), START_TEST(), and test_runner().

◆ service_nameW