Author: dgorbachev
Date: Thu Feb 18 03:28:48 2010
New Revision: 45605
URL:
http://svn.reactos.org/svn/reactos?rev=45605&view=rev
Log:
[UMPNPMGR] Update the service control manager's status information.
Modified:
branches/arwinss/reactos/base/services/umpnpmgr/umpnpmgr.c
Modified: branches/arwinss/reactos/base/services/umpnpmgr/umpnpmgr.c
URL:
http://svn.reactos.org/svn/reactos/branches/arwinss/reactos/base/services/u…
==============================================================================
--- branches/arwinss/reactos/base/services/umpnpmgr/umpnpmgr.c [iso-8859-1] (original)
+++ branches/arwinss/reactos/base/services/umpnpmgr/umpnpmgr.c [iso-8859-1] Thu Feb 18
03:28:48 2010
@@ -51,13 +51,12 @@
/* GLOBALS ******************************************************************/
-static VOID CALLBACK
-ServiceMain(DWORD argc, LPTSTR *argv);
-
-static SERVICE_TABLE_ENTRY ServiceTable[2] =
-{
- {TEXT("PlugPlay"), ServiceMain},
- {NULL, NULL}
+static VOID CALLBACK ServiceMain(DWORD, LPWSTR *);
+static WCHAR ServiceName[] = L"PlugPlay";
+static SERVICE_TABLE_ENTRYW ServiceTable[] =
+{
+ { ServiceName, ServiceMain },
+ { NULL, NULL }
};
static WCHAR szRootDeviceId[] = L"HTREE\\ROOT\\0";
@@ -2365,17 +2364,82 @@
return ERROR_SUCCESS;
}
-
-static VOID CALLBACK
-ServiceMain(DWORD argc, LPTSTR *argv)
+static DWORD WINAPI
+ServiceControlHandler(DWORD dwControl,
+ DWORD dwEventType,
+ LPVOID lpEventData,
+ LPVOID lpContext)
+{
+ /* FIXME */
+ DPRINT1("ServiceControlHandler() called (control code %lu)\n", dwControl);
+ return ERROR_SUCCESS;
+}
+
+static DWORD
+ServiceInit(VOID)
{
HANDLE hThread;
DWORD dwThreadId;
-
- UNREFERENCED_PARAMETER(argc);
- UNREFERENCED_PARAMETER(argv);
-
- DPRINT("ServiceMain() called\n");
+ DWORD dwError;
+ BOOLEAN OldValue;
+
+ /* We need this privilege for using CreateProcessAsUserW */
+ RtlAdjustPrivilege(SE_ASSIGNPRIMARYTOKEN_PRIVILEGE, TRUE, FALSE, &OldValue);
+
+ hInstallEvent = CreateEvent(NULL, TRUE, SetupIsActive()/*FALSE*/, NULL);
+ if (hInstallEvent == NULL)
+ {
+ dwError = GetLastError();
+ DPRINT1("Could not create the Install Event! (Error %lu)\n", dwError);
+ return dwError;
+ }
+
+ hDeviceInstallListNotEmpty = CreateEvent(NULL, FALSE, FALSE, NULL);
+ if (hDeviceInstallListNotEmpty == NULL)
+ {
+ dwError = GetLastError();
+ DPRINT1("Could not create the Event! (Error %lu)\n", dwError);
+ return dwError;
+ }
+
+ hNoPendingInstalls = CreateEventW(NULL,
+ TRUE,
+ FALSE,
+
L"Global\\PnP_No_Pending_Install_Events");
+ if (hNoPendingInstalls == NULL)
+ {
+ dwError = GetLastError();
+ DPRINT1("Could not create the Event! (Error %lu)\n", dwError);
+ return dwError;
+ }
+
+#ifdef HAVE_SLIST_ENTRY_IMPLEMENTED
+ InitializeSListHead(&DeviceInstallListHead);
+#else
+ InitializeListHead(&DeviceInstallListHead);
+#endif
+
+ dwError = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
+ L"System\\CurrentControlSet\\Enum",
+ 0,
+ KEY_ALL_ACCESS,
+ &hEnumKey);
+ if (dwError != ERROR_SUCCESS)
+ {
+ DPRINT1("Could not open the Enum Key! (Error %lu)\n", dwError);
+ return dwError;
+ }
+
+ dwError = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
+ L"System\\CurrentControlSet\\Control\\Class",
+ 0,
+ KEY_ALL_ACCESS,
+ &hClassKey);
+ if (dwError != ERROR_SUCCESS)
+ {
+ DPRINT1("Could not open the Class Key! (Error %lu)\n", dwError);
+ return dwError;
+ }
hThread = CreateThread(NULL,
0,
@@ -2383,8 +2447,11 @@
NULL,
0,
&dwThreadId);
- if (hThread != NULL)
- CloseHandle(hThread);
+ if (hThread == NULL)
+ {
+ return GetLastError();
+ }
+ CloseHandle(hThread);
hThread = CreateThread(NULL,
0,
@@ -2392,8 +2459,11 @@
NULL,
0,
&dwThreadId);
- if (hThread != NULL)
- CloseHandle(hThread);
+ if (hThread == NULL)
+ {
+ return GetLastError();
+ }
+ CloseHandle(hThread);
hThread = CreateThread(NULL,
0,
@@ -2401,88 +2471,73 @@
NULL,
0,
&dwThreadId);
- if (hThread != NULL)
- CloseHandle(hThread);
+ if (hThread == NULL)
+ {
+ return GetLastError();
+ }
+ CloseHandle(hThread);
+
+ return ERROR_SUCCESS;
+}
+
+static VOID CALLBACK
+ServiceMain(DWORD argc, LPWSTR *argv)
+{
+ SERVICE_STATUS ServiceStatus;
+ SERVICE_STATUS_HANDLE ServiceStatusHandle;
+ DWORD dwError;
+
+ UNREFERENCED_PARAMETER(argc);
+ UNREFERENCED_PARAMETER(argv);
+
+ DPRINT("ServiceMain() called\n");
+
+ ServiceStatusHandle = RegisterServiceCtrlHandlerExW(ServiceName,
+ ServiceControlHandler,
+ NULL);
+ if (!ServiceStatusHandle)
+ {
+ dwError = GetLastError();
+ DPRINT1("RegisterServiceCtrlHandlerW() failed! (Error %lu)\n",
dwError);
+ return;
+ }
+
+ ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
+ ServiceStatus.dwCurrentState = SERVICE_START_PENDING;
+ ServiceStatus.dwControlsAccepted = 0;
+ ServiceStatus.dwWin32ExitCode = NO_ERROR;
+ ServiceStatus.dwServiceSpecificExitCode = 0;
+ ServiceStatus.dwCheckPoint = 0;
+ ServiceStatus.dwWaitHint = 2000;
+
+ SetServiceStatus(ServiceStatusHandle, &ServiceStatus);
+
+ dwError = ServiceInit();
+
+ if (dwError != ERROR_SUCCESS)
+ {
+ DPRINT1("Service stopped\n");
+ ServiceStatus.dwCurrentState = SERVICE_STOPPED;
+ }
+ else
+ {
+ ServiceStatus.dwCurrentState = SERVICE_RUNNING;
+ }
+
+ SetServiceStatus(ServiceStatusHandle, &ServiceStatus);
DPRINT("ServiceMain() done\n");
}
-
int
wmain(int argc, WCHAR *argv[])
{
- BOOLEAN OldValue;
- DWORD dwError;
-
UNREFERENCED_PARAMETER(argc);
UNREFERENCED_PARAMETER(argv);
- DPRINT("Umpnpmgr: main() started\n");
-
- /* We need this privilege for using CreateProcessAsUserW */
- RtlAdjustPrivilege(SE_ASSIGNPRIMARYTOKEN_PRIVILEGE, TRUE, FALSE, &OldValue);
-
- hInstallEvent = CreateEvent(NULL, TRUE, SetupIsActive()/*FALSE*/, NULL);
- if (hInstallEvent == NULL)
- {
- dwError = GetLastError();
- DPRINT1("Could not create the Install Event! (Error %lu)\n", dwError);
- return dwError;
- }
-
- hDeviceInstallListNotEmpty = CreateEvent(NULL, FALSE, FALSE, NULL);
- if (hDeviceInstallListNotEmpty == NULL)
- {
- dwError = GetLastError();
- DPRINT1("Could not create the Event! (Error %lu)\n", dwError);
- return dwError;
- }
-
- hNoPendingInstalls = CreateEventW(NULL,
- TRUE,
- FALSE,
-
L"Global\\PnP_No_Pending_Install_Events");
- if (hNoPendingInstalls == NULL)
- {
- dwError = GetLastError();
- DPRINT1("Could not create the Event! (Error %lu)\n", dwError);
- return dwError;
- }
-
-#ifdef HAVE_SLIST_ENTRY_IMPLEMENTED
- InitializeSListHead(&DeviceInstallListHead);
-#else
- InitializeListHead(&DeviceInstallListHead);
-#endif
-
- dwError = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
- L"System\\CurrentControlSet\\Enum",
- 0,
- KEY_ALL_ACCESS,
- &hEnumKey);
- if (dwError != ERROR_SUCCESS)
- {
- DPRINT1("Could not open the Enum Key! (Error %lu)\n", dwError);
- return dwError;
- }
-
- dwError = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
- L"System\\CurrentControlSet\\Control\\Class",
- 0,
- KEY_ALL_ACCESS,
- &hClassKey);
- if (dwError != ERROR_SUCCESS)
- {
- DPRINT1("Could not open the Class Key! (Error %lu)\n", dwError);
- return dwError;
- }
-
- StartServiceCtrlDispatcher(ServiceTable);
-
- DPRINT("Umpnpmgr: main() done\n");
-
- ExitThread(0);
-
+ DPRINT1("Umpnpmgr: main() started\n");
+ StartServiceCtrlDispatcherW(ServiceTable);
+ DPRINT1("Umpnpmgr: main() done\n");
return 0;
}