Author: ekohl
Date: Thu May 26 10:50:26 2011
New Revision: 51921
URL:
http://svn.reactos.org/svn/reactos?rev=51921&view=rev
Log:
[SERVICES]
- Add database locks to ScmAutoShutdownServices, RCreateServiceW and
REnumServicesStatusExW.
- Add experimental logging of failed service start (WIP).
Modified:
trunk/reactos/base/system/services/database.c
trunk/reactos/base/system/services/rpcserver.c
trunk/reactos/base/system/services/services.c
trunk/reactos/base/system/services/services.h
Modified: trunk/reactos/base/system/services/database.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/services/datab…
==============================================================================
--- trunk/reactos/base/system/services/database.c [iso-8859-1] (original)
+++ trunk/reactos/base/system/services/database.c [iso-8859-1] Thu May 26 10:50:26 2011
@@ -1036,6 +1036,7 @@
{
PSERVICE_GROUP Group = Service->lpGroup;
DWORD dwError = ERROR_SUCCESS;
+ LPCWSTR ErrorLogStrings[2];
DPRINT("ScmStartService() called\n");
@@ -1088,15 +1089,20 @@
Group->ServicesRunning = TRUE;
}
}
+ else
+ {
+ if (Service->dwErrorControl != SERVICE_ERROR_IGNORE)
+ {
+ ErrorLogStrings[0] = Service->lpServiceName;
+ ErrorLogStrings[1] = L"Test";
+ ScmLogError(EVENT_SERVICE_START_FAILED,
+ 2,
+ ErrorLogStrings);
+ }
+
#if 0
- else
- {
- switch (Service->ErrorControl)
- {
- case SERVICE_ERROR_NORMAL:
- /* FIXME: Log error */
- break;
-
+ switch (Service->dwErrorControl)
+ {
case SERVICE_ERROR_SEVERE:
if (IsLastKnownGood == FALSE)
{
@@ -1115,8 +1121,8 @@
}
break;
}
- }
#endif
+ }
return dwError;
}
@@ -1242,6 +1248,9 @@
DPRINT("ScmAutoShutdownServices() called\n");
+ /* Lock the service database exclusively */
+ ScmLockDatabaseExclusive();
+
ServiceEntry = ServiceListHead.Flink;
while (ServiceEntry != &ServiceListHead)
{
@@ -1251,13 +1260,17 @@
CurrentService->Status.dwCurrentState == SERVICE_START_PENDING)
{
/* shutdown service */
- ScmControlService(CurrentService, SERVICE_CONTROL_STOP);
+ DPRINT("Shutdown service: %S\n",
CurrentService->szServiceName);
+ ScmControlService(CurrentService, SERVICE_CONTROL_SHUTDOWN);
}
ServiceEntry = ServiceEntry->Flink;
}
- DPRINT("ScmGetBootAndSystemDriverState() done\n");
+ /* Unlock the service database */
+ ScmUnlockDatabase();
+
+ DPRINT("ScmAutoShutdownServices() done\n");
}
Modified: trunk/reactos/base/system/services/rpcserver.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/services/rpcse…
==============================================================================
--- trunk/reactos/base/system/services/rpcserver.c [iso-8859-1] (original)
+++ trunk/reactos/base/system/services/rpcserver.c [iso-8859-1] Thu May 26 10:50:26 2011
@@ -1181,8 +1181,11 @@
SVCCTL_HANDLEW lpMachineName,
DWORD BootAcceptable)
{
- UNIMPLEMENTED;
- return ERROR_CALL_NOT_IMPLEMENTED;
+ DPRINT1("RNotifyBootConfigStatus(%p %lu) called\n", lpMachineName,
BootAcceptable);
+ return ERROR_SUCCESS;
+
+// UNIMPLEMENTED;
+// return ERROR_CALL_NOT_IMPLEMENTED;
}
@@ -1898,9 +1901,15 @@
return ERROR_INVALID_PARAMETER;
}
+ /* Lock the service database exclusively */
+ ScmLockDatabaseExclusive();
+
lpService = ScmGetServiceEntryByName(lpServiceName);
if (lpService)
{
+ /* Unlock the service database */
+ ScmUnlockDatabase();
+
/* check if it is marked for deletion */
if (lpService->bDeleted)
return ERROR_SERVICE_MARKED_FOR_DELETE;
@@ -1910,7 +1919,12 @@
if (lpDisplayName != NULL &&
ScmGetServiceEntryByDisplayName(lpDisplayName) != NULL)
+ {
+ /* Unlock the service database */
+ ScmUnlockDatabase();
+
return ERROR_DUPLICATE_SERVICE_NAME;
+ }
if (dwServiceType & SERVICE_DRIVER)
{
@@ -1925,6 +1939,9 @@
if (dwStartType == SERVICE_BOOT_START ||
dwStartType == SERVICE_SYSTEM_START)
{
+ /* Unlock the service database */
+ ScmUnlockDatabase();
+
return ERROR_INVALID_PARAMETER;
}
}
@@ -2113,6 +2130,9 @@
DPRINT("CreateService - lpService->dwRefCount %u\n",
lpService->dwRefCount);
done:;
+ /* Unlock the service database */
+ ScmUnlockDatabase();
+
if (hServiceKey != NULL)
RegCloseKey(hServiceKey);
@@ -5079,7 +5099,8 @@
if (lpResumeIndex)
dwLastResumeCount = *lpResumeIndex;
- /* FIXME: Lock the service list shared */
+ /* Lock the service database shared */
+ ScmLockDatabaseShared();
lpService = ScmGetServiceEntryByResumeCount(dwLastResumeCount);
if (lpService == NULL)
@@ -5281,7 +5302,8 @@
}
Done:;
- /* FIXME: Unlock the service list */
+ /* Unlock the service database */
+ ScmUnlockDatabase();
DPRINT("REnumServicesStatusExW() done (Error %lu)\n", dwError);
Modified: trunk/reactos/base/system/services/services.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/services/servi…
==============================================================================
--- trunk/reactos/base/system/services/services.c [iso-8859-1] (original)
+++ trunk/reactos/base/system/services/services.c [iso-8859-1] Thu May 26 10:50:26 2011
@@ -47,6 +47,38 @@
}
+VOID
+ScmLogError(DWORD dwEventId,
+ WORD wStrings,
+ LPCWSTR *lpStrings)
+{
+ HANDLE hLog;
+
+ hLog = RegisterEventSourceW(NULL,
+ L"Service Control Manager");
+ if (hLog == NULL)
+ {
+ DPRINT1("ScmLogEvent: RegisterEventSourceW failed %d\n",
GetLastError());
+ return;
+ }
+
+ if (!ReportEventW(hLog,
+ EVENTLOG_ERROR_TYPE,
+ 0,
+ dwEventId,
+ NULL, // Sid,
+ wStrings,
+ 0,
+ lpStrings,
+ NULL))
+ {
+ DPRINT1("ScmLogEvent: ReportEventW failed %d\n", GetLastError());
+ }
+
+ DeregisterEventSource(hLog);
+}
+
+
BOOL
ScmCreateStartEvent(PHANDLE StartEvent)
{
Modified: trunk/reactos/base/system/services/services.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/services/servi…
==============================================================================
--- trunk/reactos/base/system/services/services.h [iso-8859-1] (original)
+++ trunk/reactos/base/system/services/services.h [iso-8859-1] Thu May 26 10:50:26 2011
@@ -5,6 +5,7 @@
#include <stdio.h>
#define WIN32_NO_STATUS
#include <windows.h>
+#include <netevent.h>
#define NTOS_MODE_USER
#include <ndk/ntndk.h>
#include <services/services.h>
@@ -151,6 +152,9 @@
/* services.c */
VOID PrintString(LPCSTR fmt, ...);
+VOID ScmLogError(DWORD dwEventId,
+ WORD wStrings,
+ LPCWSTR *lpStrings);
/* EOF */