ReactOS  0.4.13-dev-698-g77671f0
services.c File Reference
#include "services.h"
#include <wincon.h>
#include <debug.h>
Include dependency graph for services.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define SCM_AUTOSTARTCOMPLETE_EVENT   L"SC_AutoStartComplete"
 

Functions

int WINAPI RegisterServicesProcess (DWORD ServicesProcessId)
 
VOID PrintString (LPCSTR fmt,...)
 
VOID ScmLogEvent (DWORD dwEventId, WORD wType, WORD wStrings, LPCWSTR *lpStrings)
 
VOID ScmWaitForLsa (VOID)
 
BOOL WINAPI ShutdownHandlerRoutine (DWORD dwCtrlType)
 
int WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd)
 

Variables

BOOL ScmInitialize = FALSE
 
BOOL ScmShutdown = FALSE
 
static HANDLE hScmShutdownEvent = NULL
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 17 of file services.c.

◆ SCM_AUTOSTARTCOMPLETE_EVENT

#define SCM_AUTOSTARTCOMPLETE_EVENT   L"SC_AutoStartComplete"

Definition at line 26 of file services.c.

Function Documentation

◆ PrintString()

VOID PrintString ( LPCSTR  fmt,
  ... 
)

Definition at line 36 of file services.c.

37 {
38 #if DBG
39  CHAR buffer[512];
40  va_list ap;
41 
42  va_start(ap, fmt);
43  vsprintf(buffer, fmt, ap);
44  va_end(ap);
45 
47 #endif
48 }
char CHAR
Definition: xmlstorage.h:175
GLuint buffer
Definition: glext.h:5915
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
int __cdecl vsprintf(char *_Dest, const char *_Format, va_list _Args)
Definition: sprintf.c:733
#define va_start(ap, A)
Definition: acmsvcex.h:91
void int int ULONGLONG int va_list * ap
Definition: winesup.h:32
Definition: dsound.c:943
void WINAPI SHIM_OBJ_NAME() OutputDebugStringA(LPCSTR lpOutputString)
Definition: ignoredbgout.c:18

◆ RegisterServicesProcess()

int WINAPI RegisterServicesProcess ( DWORD  ServicesProcessId)

Definition at line 18 of file logon.c.

19 {
20  USER_API_MESSAGE ApiMessage;
21  PUSER_REGISTER_SERVICES_PROCESS RegisterServicesProcessRequest = &ApiMessage.Data.RegisterServicesProcessRequest;
22 
23  RegisterServicesProcessRequest->ProcessId = ServicesProcessId;
24 
26  NULL,
28  sizeof(*RegisterServicesProcessRequest));
29  if (!NT_SUCCESS(ApiMessage.Status))
30  {
31  UserSetLastNTError(ApiMessage.Status);
32  return FALSE;
33  }
34 
35  return TRUE;
36 }
ULONG_PTR ServicesProcessId
Definition: register.c:20
union _USER_API_MESSAGE::@3389 Data
#define TRUE
Definition: types.h:120
#define USERSRV_SERVERDLL_INDEX
Definition: winmsg.h:15
NTSTATUS NTAPI CsrClientCallServer(IN OUT PCSR_API_MESSAGE ApiMessage, IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer OPTIONAL, IN CSR_API_NUMBER ApiNumber, IN ULONG DataLength)
Definition: connect.c:360
NTSTATUS Status
Definition: csrmsg.h:112
USER_REGISTER_SERVICES_PROCESS RegisterServicesProcessRequest
Definition: winmsg.h:104
smooth NULL
Definition: ftsmooth.c:416
#define CSR_CREATE_API_NUMBER(ServerId, ApiId)
Definition: csrmsg.h:37
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID WINAPI UserSetLastNTError(IN NTSTATUS Status)
Definition: misc.c:25

Referenced by wWinMain().

◆ ScmLogEvent()

VOID ScmLogEvent ( DWORD  dwEventId,
WORD  wType,
WORD  wStrings,
LPCWSTR lpStrings 
)

Definition at line 52 of file services.c.

56 {
57  HANDLE hLog;
58 
60  L"Service Control Manager");
61  if (hLog == NULL)
62  {
63  DPRINT1("ScmLogEvent: RegisterEventSourceW failed %lu\n", GetLastError());
64  return;
65  }
66 
67  if (!ReportEventW(hLog,
68  wType,
69  0,
70  dwEventId,
71  NULL,
72  wStrings,
73  0,
74  lpStrings,
75  NULL))
76  {
77  DPRINT1("ScmLogEvent: ReportEventW failed %lu\n", GetLastError());
78  }
79 
81 }
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
smooth NULL
Definition: ftsmooth.c:416
static HANDLE hLog
Definition: misc.cpp:15
static const WCHAR L[]
Definition: oid.c:1250
BOOL WINAPI ReportEventW(IN HANDLE hEventLog, IN WORD wType, IN WORD wCategory, IN DWORD dwEventID, IN PSID lpUserSid, IN WORD wNumStrings, IN DWORD dwDataSize, IN LPCWSTR *lpStrings, IN LPVOID lpRawData)
Definition: eventlog.c:1516
BOOL WINAPI DeregisterEventSource(IN HANDLE hEventLog)
Definition: eventlog.c:473
#define DPRINT1
Definition: precomp.h:8
HANDLE WINAPI RegisterEventSourceW(IN LPCWSTR lpUNCServerName, IN LPCWSTR lpSourceName)
Definition: eventlog.c:1295

Referenced by RControlService(), RSetServiceStatus(), ScmLoadService(), and ScmWaitForServiceConnect().

◆ ScmWaitForLsa()

VOID ScmWaitForLsa ( VOID  )

Definition at line 85 of file services.c.

86 {
87  HANDLE hEvent = CreateEventW(NULL, TRUE, FALSE, L"LSA_RPC_SERVER_ACTIVE");
88  if (hEvent == NULL)
89  {
90  DPRINT1("Failed to create or open the notification event (Error %lu)\n", GetLastError());
91  }
92  else
93  {
94  DPRINT("Wait for the LSA server!\n");
96  DPRINT("LSA server running!\n");
98  }
99 
100  DPRINT("ScmWaitForLsa() done\n");
101 }
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:597
static HANDLE hEvent
Definition: comm.c:54
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
static const WCHAR L[]
Definition: oid.c:1250
#define DPRINT1
Definition: precomp.h:8
#define INFINITE
Definition: serial.h:102

Referenced by ScmCreateServiceDatabase().

◆ ShutdownHandlerRoutine()

BOOL WINAPI ShutdownHandlerRoutine ( DWORD  dwCtrlType)

Definition at line 105 of file services.c.

106 {
107  DPRINT1("ShutdownHandlerRoutine() called\n");
108 
109  if (dwCtrlType & (CTRL_SHUTDOWN_EVENT | CTRL_LOGOFF_EVENT))
110  {
111  DPRINT1("Shutdown event received!\n");
112  ScmShutdown = TRUE;
113 
116 
117  /* Set the shutdown event */
119  }
120 
121  return TRUE;
122 }
#define TRUE
Definition: types.h:120
static HANDLE hScmShutdownEvent
Definition: services.c:30
VOID ScmAutoShutdownServices(VOID)
Definition: database.c:2272
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:679
BOOL ScmShutdown
Definition: services.c:29
#define CTRL_LOGOFF_EVENT
Definition: wincon.h:69
#define CTRL_SHUTDOWN_EVENT
Definition: wincon.h:70
#define DPRINT1
Definition: precomp.h:8
VOID ScmShutdownServiceDatabase(VOID)
Definition: database.c:1074

Referenced by wWinMain().

◆ wWinMain()

int WINAPI wWinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInstance,
LPWSTR  lpCmdLine,
int  nShowCmd 
)

This file has no copyright assigned and is placed in the Public Domain. This file is part of the w64 mingw-runtime package. No warranty is given; refer to the file DISCLAIMER.PD within this package.

Definition at line 126 of file services.c.

130 {
131  HANDLE hScmStartEvent = NULL;
132  HANDLE hScmAutoStartCompleteEvent = NULL;
134  BOOL bCanDeleteNamedPipeCriticalSection = FALSE;
135  DWORD dwError;
136 
137  DPRINT("SERVICES: Service Control Manager\n");
138 
139  /* Make us critical */
141 
142  /* We are initializing ourselves */
144 
145  /* Create the start event */
146  hScmStartEvent = CreateEventW(NULL, TRUE, FALSE, SCM_START_EVENT);
147  if (hScmStartEvent == NULL)
148  {
149  DPRINT1("SERVICES: Failed to create the start event\n");
150  goto done;
151  }
152  DPRINT("SERVICES: Created start event with handle %p.\n", hScmStartEvent);
153 
154  /* Create the auto-start complete event */
155  hScmAutoStartCompleteEvent = CreateEventW(NULL, TRUE, FALSE, SCM_AUTOSTARTCOMPLETE_EVENT);
156  if (hScmAutoStartCompleteEvent == NULL)
157  {
158  DPRINT1("SERVICES: Failed to create the auto-start complete event\n");
159  goto done;
160  }
161  DPRINT("SERVICES: created auto-start complete event with handle %p.\n", hScmAutoStartCompleteEvent);
162 
163  /* Create the shutdown event */
165  if (hScmShutdownEvent == NULL)
166  {
167  DPRINT1("SERVICES: Failed to create the shutdown event\n");
168  goto done;
169  }
170 
171  /* Initialize our communication named pipe's critical section */
173  bCanDeleteNamedPipeCriticalSection = TRUE;
174 
175 // ScmInitThreadManager();
176 
178 
179  /* FIXME: more initialization */
180 
181  /* Create the 'Last Known Good' control set */
183  if (dwError != ERROR_SUCCESS)
184  {
185  DPRINT1("SERVICES: Failed to create the 'Last Known Good' control set (Error %lu)\n", dwError);
186  goto done;
187  }
188 
189  /* Create the services database */
190  dwError = ScmCreateServiceDatabase();
191  if (dwError != ERROR_SUCCESS)
192  {
193  DPRINT1("SERVICES: Failed to create SCM database (Error %lu)\n", dwError);
194  goto done;
195  }
196 
197  /* Update the services database */
199 
200  /* Register the Service Control Manager process with the ReactOS Subsystem */
202  {
203  DPRINT1("SERVICES: Could not register SCM process\n");
204  goto done;
205  }
206 
207  /*
208  * Acquire the user service start lock until
209  * auto-start services have been started.
210  */
211  dwError = ScmAcquireServiceStartLock(TRUE, &Lock);
212  if (dwError != ERROR_SUCCESS)
213  {
214  DPRINT1("SERVICES: Failed to acquire the service start lock (Error %lu)\n", dwError);
215  goto done;
216  }
217 
218  /* Start the RPC server */
220 
221  /* Signal start event */
222  SetEvent(hScmStartEvent);
223 
224  DPRINT("SERVICES: Initialized.\n");
225 
226  /* Register event handler (used for system shutdown) */
228 
229  /*
230  * Set our shutdown parameters: we want to shutdown after the maintained
231  * services (that inherit the default shutdown level of 640).
232  */
234 
235  /* Start auto-start services */
237 
238  /* Signal auto-start complete event */
239  SetEvent(hScmAutoStartCompleteEvent);
240 
241  /* FIXME: more to do ? */
242 
243  /* Release the service start lock */
245 
246  /* Initialization finished */
248 
249  DPRINT("SERVICES: Running.\n");
250 
251  /* Wait until the shutdown event gets signaled */
253 
254 done:
256 
257  /* Delete our communication named pipe's critical section */
258  if (bCanDeleteNamedPipeCriticalSection != FALSE)
260 
261  /* Close the shutdown event */
262  if (hScmShutdownEvent != NULL)
264 
265  /* Close the auto-start complete event */
266  if (hScmAutoStartCompleteEvent != NULL)
267  CloseHandle(hScmAutoStartCompleteEvent);
268 
269  /* Close the start event */
270  if (hScmStartEvent != NULL)
271  CloseHandle(hScmStartEvent);
272 
273  DPRINT("SERVICES: Finished.\n");
274 
275  ExitThread(0);
276  return 0;
277 }
VOID ScmAutoStartServices(VOID)
Definition: database.c:2061
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
#define ERROR_SUCCESS
Definition: deptool.c:10
static HANDLE hScmShutdownEvent
Definition: services.c:30
BOOL ScmInitialize
Definition: services.c:28
DWORD ScmCreateLastKnownGoodControlSet(VOID)
Definition: controlset.c:465
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:679
DWORD ScmInitializeSecurity(VOID)
Definition: security.c:288
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:597
BOOL WINAPI SetProcessShutdownParameters(IN DWORD dwLevel, IN DWORD dwFlags)
Definition: proc.c:979
VOID ScmGetBootAndSystemDriverState(VOID)
Definition: database.c:1184
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
DWORD ScmAcquireServiceStartLock(IN BOOL IsServiceController, OUT LPSC_RPC_LOCK lpLock)
Definition: lock.c:31
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine, BOOL Add)
Definition: console.c:2111
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
VOID WINAPI ExitThread(IN DWORD uExitCode)
Definition: thread.c:326
unsigned long DWORD
Definition: ntddk_ex.h:95
VOID ScmStartRpcServer(VOID)
Definition: rpcserver.c:105
DWORD ScmReleaseServiceStartLock(IN OUT LPSC_RPC_LOCK lpLock)
Definition: lock.c:82
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG IN OUT PLONG IN LONG Increment IN PNDIS_RW_LOCK Lock
Definition: CrNtStubs.h:75
VOID ScmInitNamedPipeCriticalSection(VOID)
Definition: database.c:2331
VOID ScmDeleteNamedPipeCriticalSection(VOID)
Definition: database.c:2359
#define SHUTDOWN_NORETRY
Definition: winbase.h:429
BOOL WINAPI ShutdownHandlerRoutine(DWORD dwCtrlType)
Definition: services.c:105
DWORD ScmCreateServiceDatabase(VOID)
Definition: database.c:987
#define DPRINT1
Definition: precomp.h:8
NTSYSAPI NTSTATUS __cdecl RtlSetProcessIsCritical(_In_ BOOLEAN NewValue, _Out_opt_ PBOOLEAN OldValue, _In_ BOOLEAN NeedBreaks)
#define SCM_AUTOSTARTCOMPLETE_EVENT
Definition: services.c:26
#define INFINITE
Definition: serial.h:102
#define SCM_START_EVENT
Definition: services.h:26
VOID ScmShutdownSecurity(VOID)
Definition: security.c:309
int WINAPI RegisterServicesProcess(DWORD ServicesProcessId)
Definition: logon.c:18
DWORD WINAPI GetCurrentProcessId(VOID)
Definition: proc.c:1188

Variable Documentation

◆ hScmShutdownEvent

HANDLE hScmShutdownEvent = NULL
static

Definition at line 30 of file services.c.

Referenced by ShutdownHandlerRoutine(), and wWinMain().

◆ ScmInitialize

BOOL ScmInitialize = FALSE

Definition at line 28 of file services.c.

Referenced by ScmAutoStartServices(), ScmStartService(), and wWinMain().

◆ ScmShutdown