ReactOS 0.4.15-dev-5666-gc548b97
service.c
Go to the documentation of this file.
1/*
2 * msiexec.exe implementation
3 *
4 * Copyright 2007 Google (James Hawkins)
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#define WIN32_LEAN_AND_MEAN
22
23#include <stdio.h>
24#include <windows.h>
25#include <winsvc.h>
26
27#include "wine/debug.h"
28
30
32
35
36static void KillService(void)
37{
38 WINE_TRACE("Killing service\n");
40}
41
42static BOOL UpdateSCMStatus(DWORD dwCurrentState, DWORD dwWin32ExitCode,
43 DWORD dwServiceSpecificExitCode)
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");
78 return FALSE;
79 }
80
81 return TRUE;
82}
83
85{
86 WINE_TRACE("%u\n", code);
87
88 switch (code)
89 {
94 break;
95 default:
96 fprintf(stderr, "Unhandled service control code: %u\n", code);
98 break;
99 }
100}
101
103{
105
106 return 0;
107}
108
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}
122
124{
126 if (!hstatus)
127 {
128 fprintf(stderr, "Failed to register service ctrl handler\n");
129 return;
130 }
131
133
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}
154
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 SERVICE_STATUS_HANDLE(WINAPI *pRegisterServiceCtrlHandlerExA)(LPCSTR
static char service_name[100]
static int argc
Definition: ServiceArgs.c:12
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
static HANDLE kill_event
Definition: service.c:34
static BOOL StartServiceThread(void)
Definition: service.c:109
static void WINAPI ServiceMain(DWORD argc, LPSTR *argv)
Definition: service.c:123
static DWORD WINAPI ServiceExecutionThread(LPVOID param)
Definition: service.c:102
static void KillService(void)
Definition: service.c:36
static BOOL UpdateSCMStatus(DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwServiceSpecificExitCode)
Definition: service.c:42
DWORD DoService(void)
Definition: service.c:155
static SERVICE_STATUS_HANDLE hstatus
Definition: service.c:31
static void WINAPI ServiceCtrlHandler(DWORD code)
Definition: service.c:84
static HANDLE thread
Definition: service.c:33
#define NO_ERROR
Definition: dderror.h:5
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
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:137
#define INFINITE
Definition: serial.h:102
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLfloat param
Definition: glext.h:5796
GLuint id
Definition: glext.h:5910
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
#define argv
Definition: mplay32.c:18
BOOL WINAPI StartServiceCtrlDispatcherA(const SERVICE_TABLE_ENTRYA *lpServiceStartTable)
Definition: sctrl.c:1035
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerA(LPCSTR lpServiceName, LPHANDLER_FUNCTION lpHandlerProc)
Definition: sctrl.c:710
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:997
#define WINE_TRACE
Definition: debug.h:354
Definition: inflate.c:139
Definition: ps.c:97
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:651
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
#define WINAPI
Definition: msvc.h:6
#define ERROR_SERVICE_SPECIFIC_ERROR
Definition: winerror.h:617
#define SERVICE_STOPPED
Definition: winsvc.h:21
#define SERVICE_ACCEPT_STOP
Definition: winsvc.h:28
#define SERVICE_STOP_PENDING
Definition: winsvc.h:23
#define SERVICE_CONTROL_SHUTDOWN
Definition: winsvc.h:40
#define SERVICE_START_PENDING
Definition: winsvc.h:22
#define SERVICE_RUNNING
Definition: winsvc.h:24
#define SERVICE_ACCEPT_PAUSE_CONTINUE
Definition: winsvc.h:29
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
#define SERVICE_ACCEPT_SHUTDOWN
Definition: winsvc.h:30
#define SERVICE_WIN32_OWN_PROCESS
Definition: cmtypes.h:962
char * LPSTR
Definition: xmlstorage.h:182