ReactOS  0.4.13-dev-52-g0efcfec
service.c File Reference
#include <stdio.h>
#include <windows.h>
#include <winsvc.h>
#include "wine/debug.h"
Include dependency graph for service.c:

Go to the source code of this file.

Macros

#define WIN32_LEAN_AND_MEAN
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (msiexec)
 
static void KillService (void)
 
static BOOL UpdateSCMStatus (DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwServiceSpecificExitCode)
 
static void WINAPI ServiceCtrlHandler (DWORD code)
 
static DWORD WINAPI ServiceExecutionThread (LPVOID param)
 
static BOOL StartServiceThread (void)
 
static void WINAPI ServiceMain (DWORD argc, LPSTR *argv)
 
DWORD DoService (void)
 

Variables

static SERVICE_STATUS_HANDLE hstatus
 
static HANDLE thread
 
static HANDLE kill_event
 

Macro Definition Documentation

◆ WIN32_LEAN_AND_MEAN

#define WIN32_LEAN_AND_MEAN

Definition at line 21 of file service.c.

Function Documentation

◆ DoService()

DWORD DoService ( void  )

Definition at line 155 of file service.c.

156 {
157  char service_name[] = "MSIServer";
158 
159  const SERVICE_TABLE_ENTRYA service[] =
160  {
162  {NULL, NULL},
163  };
164 
165  WINE_TRACE("Starting MSIServer service\n");
166 
167  if (!StartServiceCtrlDispatcherA(service))
168  {
169  fprintf(stderr, "Failed to start MSIServer service\n");
170  return 1;
171  }
172 
173  return 0;
174 }
static void WINAPI ServiceMain(DWORD argc, LPSTR *argv)
Definition: service.c:123
static char service_name[100]
Definition: service.c:32
#define WINE_TRACE
Definition: debug.h:353
BOOL WINAPI StartServiceCtrlDispatcherA(const SERVICE_TABLE_ENTRYA *lpServiceStartTable)
Definition: sctrl.c:1024
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
smooth NULL
Definition: ftsmooth.c:416
FILE * stderr

Referenced by WinMain().

◆ KillService()

static void KillService ( void  )
static

Definition at line 36 of file service.c.

37 {
38  WINE_TRACE("Killing service\n");
40 }
#define WINE_TRACE
Definition: debug.h:353
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:679
static HANDLE kill_event
Definition: service.c:34

Referenced by ServiceCtrlHandler(), ServiceMain(), and UpdateSCMStatus().

◆ ServiceCtrlHandler()

static void WINAPI ServiceCtrlHandler ( DWORD  code)
static

Definition at line 84 of file service.c.

85 {
86  WINE_TRACE("%u\n", code);
87 
88  switch (code)
89  {
93  KillService();
94  break;
95  default:
96  fprintf(stderr, "Unhandled service control code: %u\n", code);
98  break;
99  }
100 }
#define WINE_TRACE
Definition: debug.h:353
#define NO_ERROR
Definition: dderror.h:5
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
#define SERVICE_RUNNING
Definition: winsvc.h:24
static void KillService(void)
Definition: service.c:36
static BOOL UpdateSCMStatus(DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwServiceSpecificExitCode)
Definition: service.c:42
FILE * stderr
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
#define SERVICE_STOP_PENDING
Definition: winsvc.h:23
#define SERVICE_CONTROL_SHUTDOWN
Definition: winsvc.h:40

Referenced by ServiceMain().

◆ ServiceExecutionThread()

static DWORD WINAPI ServiceExecutionThread ( LPVOID  param)
static

Definition at line 102 of file service.c.

103 {
105 
106  return 0;
107 }
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
static HANDLE kill_event
Definition: service.c:34
#define INFINITE
Definition: serial.h:102

Referenced by StartServiceThread().

◆ ServiceMain()

static void WINAPI ServiceMain ( DWORD  argc,
LPSTR argv 
)
static

Definition at line 123 of file service.c.

124 {
126  if (!hstatus)
127  {
128  fprintf(stderr, "Failed to register service ctrl handler\n");
129  return;
130  }
131 
133 
134  kill_event = CreateEventW(0, TRUE, FALSE, 0);
135  if (!kill_event)
136  {
137  fprintf(stderr, "Failed to create event\n");
138  KillService();
140  return;
141  }
142 
143  if (!StartServiceThread())
144  {
145  KillService();
147  return;
148  }
149 
153 }
#define TRUE
Definition: types.h:120
static BOOL StartServiceThread(void)
Definition: service.c:109
#define SERVICE_START_PENDING
Definition: winsvc.h:22
#define NO_ERROR
Definition: dderror.h:5
static SERVICE_STATUS_HANDLE hstatus
Definition: service.c:31
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:597
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define SERVICE_STOPPED
Definition: winsvc.h:21
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
static void WINAPI ServiceCtrlHandler(DWORD code)
Definition: service.c:84
#define SERVICE_RUNNING
Definition: winsvc.h:24
static void KillService(void)
Definition: service.c:36
static HANDLE kill_event
Definition: service.c:34
static HANDLE thread
Definition: service.c:33
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerA(LPCSTR lpServiceName, LPHANDLER_FUNCTION lpHandlerProc)
Definition: sctrl.c:700
static BOOL UpdateSCMStatus(DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwServiceSpecificExitCode)
Definition: service.c:42
FILE * stderr
#define INFINITE
Definition: serial.h:102

Referenced by DoService().

◆ StartServiceThread()

static BOOL StartServiceThread ( void  )
static

Definition at line 109 of file service.c.

110 {
111  DWORD id;
112 
113  thread = CreateThread(0, 0, ServiceExecutionThread, 0, 0, &id);
114  if (!thread)
115  {
116  fprintf(stderr, "Failed to create thread\n");
117  return FALSE;
118  }
119 
120  return TRUE;
121 }
#define TRUE
Definition: types.h:120
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
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
unsigned long DWORD
Definition: ntddk_ex.h:95
static HANDLE thread
Definition: service.c:33
static DWORD WINAPI ServiceExecutionThread(LPVOID param)
Definition: service.c:102
GLenum GLuint id
Definition: glext.h:5579
FILE * stderr

Referenced by ServiceMain().

◆ UpdateSCMStatus()

static BOOL UpdateSCMStatus ( DWORD  dwCurrentState,
DWORD  dwWin32ExitCode,
DWORD  dwServiceSpecificExitCode 
)
static

Definition at line 42 of file service.c.

44 {
46 
47  status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
48  status.dwCurrentState = dwCurrentState;
49 
50  if (dwCurrentState == SERVICE_START_PENDING
51  || dwCurrentState == SERVICE_STOP_PENDING
52  || dwCurrentState == SERVICE_STOPPED)
53  status.dwControlsAccepted = 0;
54  else
55  {
56  status.dwControlsAccepted = SERVICE_ACCEPT_STOP |
59  }
60 
61  if (dwServiceSpecificExitCode == 0)
62  {
63  status.dwWin32ExitCode = dwWin32ExitCode;
64  }
65  else
66  {
67  status.dwWin32ExitCode = ERROR_SERVICE_SPECIFIC_ERROR;
68  }
69 
70  status.dwServiceSpecificExitCode = dwServiceSpecificExitCode;
71  status.dwCheckPoint = 0;
72  status.dwWaitHint = 0;
73 
75  {
76  fprintf(stderr, "Failed to set service status\n");
77  KillService();
78  return FALSE;
79  }
80 
81  return TRUE;
82 }
#define TRUE
Definition: types.h:120
#define SERVICE_ACCEPT_STOP
Definition: winsvc.h:28
#define ERROR_SERVICE_SPECIFIC_ERROR
Definition: winerror.h:617
#define SERVICE_START_PENDING
Definition: winsvc.h:22
static SERVICE_STATUS_HANDLE hstatus
Definition: service.c:31
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:986
#define SERVICE_STOPPED
Definition: winsvc.h:21
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
static void KillService(void)
Definition: service.c:36
#define SERVICE_WIN32_OWN_PROCESS
Definition: cmtypes.h:960
#define SERVICE_ACCEPT_PAUSE_CONTINUE
Definition: winsvc.h:29
#define SERVICE_ACCEPT_SHUTDOWN
Definition: winsvc.h:30
FILE * stderr
static SERVICE_STATUS status
Definition: service.c:31
#define SERVICE_STOP_PENDING
Definition: winsvc.h:23
Definition: ps.c:97

Referenced by ServiceCtrlHandler(), and ServiceMain().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( msiexec  )

Variable Documentation

◆ hstatus

SERVICE_STATUS_HANDLE hstatus
static

Definition at line 31 of file service.c.

Referenced by ServiceMain(), and UpdateSCMStatus().

◆ kill_event

HANDLE kill_event
static

Definition at line 34 of file service.c.

Referenced by KillService(), ServiceExecutionThread(), and ServiceMain().

◆ thread

HANDLE thread
static

Definition at line 33 of file service.c.

Referenced by _beginthread(), _Function_class_(), cache_connection(), child_process(), custom_get_thread_return(), do_read(), do_wait_idle_child(), end_host_object(), file_layout_read_thread(), file_layout_write_thread(), FinishNotificationThread(), http_release_netconn(), IMM_GetThreadData(), IMM_IsCrossThreadAccess(), iskeyword(), LS_ThreadProc(), main(), mds_commit(), Netbios(), netconn_resolve(), PdhCloseQuery(), PdhCollectQueryDataEx(), PrintStackBacktrace(), PrintThread(), request_destroy(), request_wait(), rpcrt4_ncacn_http_open(), RPCRT4_new_client(), RtlDeleteTimerQueueEx(), run_thread(), ServiceMain(), SHCreateFromDesktop(), start_host_object(), start_host_object2(), start_installation(), START_TEST(), StartNotificationThread(), StartServiceThread(), sys_thread_new(), test_activateapp(), test_alertable_wait(), test_apc_deadlock(), test_bsc_marshaling(), test_call_from_message(), test_channel_hook(), test_client_security(), test_CoFreeUnusedLibraries(), test_CoRegisterPSClsid(), test_CoWaitForMultipleHandles(), test_CoWaitForMultipleHandles_thread(), test_crash_couninitialize(), test_CreateThread_basic(), test_CreateThread_stack(), test_CreateThread_suspended(), test_dde_default_app(), test_default_ime_window_creation(), test_defwinproc(), test_ExitProcess(), test_external_connection(), test_FindFirstChangeNotification(), test_GetDataHere_Proxy(), test_GetKeyState(), test_gettext(), test_GetThreadExitCode(), test_GetThreadTimes(), test_globalinterfacetable(), test_handler_marshaling(), test_ImmDefaultHwnd(), test_implicit_mta(), test_Input_mouse(), test_InSendMessage(), test_interthread_marshal_and_unmarshal(), test_keyed_events(), test_layered_window(), test_marshal_and_unmarshal_invalid(), test_marshal_channel_buffer(), test_marshal_proxy_apartment_shutdown(), test_marshal_proxy_mta_apartment_shutdown(), test_marshal_stub_apartment_shutdown(), test_message_filter(), test_MessageBox(), test_messages(), test_multithreaded_clipboard(), test_mutant(), test_no_couninitialize_client(), test_no_couninitialize_server(), test_proxy_interfaces(), test_proxy_marshal_and_unmarshal(), test_proxy_marshal_and_unmarshal2(), test_proxy_marshal_and_unmarshal_strong(), test_proxy_marshal_and_unmarshal_weak(), test_proxy_used_in_wrong_thread(), test_reader_info(), test_registered_object_thread_affinity(), test_render_with_multithread(), test_RtlIsCriticalSectionLocked(), test_RtlRegisterWait(), test_runner(), test_SendMessageTimeout(), test_set_clipboard_DRAWCLIPBOARD(), test_SetCursor(), test_SetForegroundWindow(), test_ShowCursor(), test_SuspendThread(), test_tablestrong_marshal_and_unmarshal_twice(), test_tableweak_and_normal_marshal_and_releasedata(), test_tableweak_and_normal_marshal_and_unmarshal(), test_tableweak_marshal_and_unmarshal_twice(), test_tableweak_marshal_releasedata1(), test_tableweak_marshal_releasedata2(), test_TerminateProcess(), test_TerminateThread(), test_thread_actctx(), test_thread_info(), test_thread_security(), test_thread_start_address(), test_Toolhelp(), test_two_tableweak_marshal_and_releasedata(), test_typelibmarshal(), test_WaitForInputIdle(), thread_data_server(), thread_init(), thread_next_unit(), threadFunc3(), wait_for_thread(), wave_out_test_deviceOut(), window_proc(), and write_file().