Author: gbrunmar
Date: Sun Oct 28 17:13:03 2007
New Revision: 29929
URL:
http://svn.reactos.org/svn/reactos?rev=29929&view=rev
Log:
Made each service have its own pipe name as done in Windows
Modified:
trunk/reactos/base/system/services/database.c
trunk/reactos/dll/win32/advapi32/service/sctrl.c
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 (original)
+++ trunk/reactos/base/system/services/database.c Sun Oct 28 17:13:03 2007
@@ -6,6 +6,7 @@
* COPYRIGHT: Copyright 2002-2006 Eric Kohl
* Copyright 2006 Hervé Poussineau <hpoussin(a)reactos.org>
* Copyright 2007 Ged Murphy <gedmurphy(a)reactos.org>
+ * Gregor Brunmar <gregor.brunmar(a)home.se>
*
*/
@@ -692,9 +693,11 @@
STARTUPINFOW StartupInfo;
UNICODE_STRING ImagePath;
ULONG Type;
+ DWORD ServiceCurrent = 0;
BOOL Result;
NTSTATUS Status;
DWORD dwError = ERROR_SUCCESS;
+ WCHAR NtControlPipeName[MAX_PATH + 1];
RtlInitUnicodeString(&ImagePath, NULL);
@@ -723,8 +726,45 @@
DPRINT("ImagePath: '%S'\n", ImagePath.Buffer);
DPRINT("Type: %lx\n", Type);
- /* Create '\\.\pipe\net\NtControlPipe' instance */
- Service->ControlPipeHandle =
CreateNamedPipeW(L"\\\\.\\pipe\\net\\NtControlPipe",
+ /* Get the service number */
+ RtlZeroMemory(&QueryTable,
+ sizeof(QueryTable));
+
+ QueryTable[0].Name = L"";
+ QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_REQUIRED;
+ QueryTable[0].EntryContext = &ServiceCurrent;
+
+ Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,
+ L"ServiceCurrent",
+ QueryTable,
+ NULL,
+ NULL);
+
+ if (Status == STATUS_OBJECT_NAME_NOT_FOUND)
+ {
+ /* TODO: Create registry entry with correct write access */
+ }
+ else if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("RtlQueryRegistryValues() failed (Status %lx)\n", Status);
+ return RtlNtStatusToDosError(Status);
+ }
+ else
+ {
+ ServiceCurrent++;
+ }
+
+ Status = RtlWriteRegistryValue(RTL_REGISTRY_CONTROL, L"ServiceCurrent",
L"", REG_DWORD, &ServiceCurrent, sizeof(ServiceCurrent));
+
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("RtlWriteRegistryValue() failed (Status %lx)\n", Status);
+ return RtlNtStatusToDosError(Status);
+ }
+
+ /* Create '\\.\pipe\net\NtControlPipeXXX' instance */
+ swprintf(NtControlPipeName, L"\\\\.\\pipe\\net\\NtControlPipe%u",
ServiceCurrent);
+ Service->ControlPipeHandle = CreateNamedPipeW(NtControlPipeName,
PIPE_ACCESS_DUPLEX,
PIPE_TYPE_MESSAGE |
PIPE_READMODE_MESSAGE | PIPE_WAIT,
100,
@@ -732,7 +772,7 @@
4,
30000,
NULL);
- DPRINT("CreateNamedPipeW() done\n");
+ DPRINT1("CreateNamedPipeW(%S) done\n", NtControlPipeName);
if (Service->ControlPipeHandle == INVALID_HANDLE_VALUE)
{
DPRINT1("Failed to create control pipe!\n");
Modified: trunk/reactos/dll/win32/advapi32/service/sctrl.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/service…
==============================================================================
--- trunk/reactos/dll/win32/advapi32/service/sctrl.c (original)
+++ trunk/reactos/dll/win32/advapi32/service/sctrl.c Sun Oct 28 17:13:03 2007
@@ -5,6 +5,7 @@
* PURPOSE: Service control manager functions
* COPYRIGHT: Copyright 1999 Emanuele Aliberti
* Copyright 2007 Ged Murphy <gedmurphy(a)reactos.org>
+ * Gregor Brunmar <gregor.brunmar(a)home.se>
*
*/
@@ -197,14 +198,40 @@
{
DWORD dwBytesWritten;
DWORD dwState;
-
- if (!WaitNamedPipeW(L"\\\\.\\pipe\\net\\NtControlPipe", 15000))
- {
- DPRINT1("WaitNamedPipe() failed (Error %lu)\n", GetLastError());
+ DWORD dwServiceCurrent = 0;
+ NTSTATUS Status;
+ WCHAR NtControlPipeName[MAX_PATH + 1];
+ RTL_QUERY_REGISTRY_TABLE QueryTable[2];
+
+ /* Get the service number and create the named pipe */
+ RtlZeroMemory(&QueryTable,
+ sizeof(QueryTable));
+
+ QueryTable[0].Name = L"";
+ QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_REQUIRED;
+ QueryTable[0].EntryContext = &dwServiceCurrent;
+
+ Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,
+ L"ServiceCurrent",
+ QueryTable,
+ NULL,
+ NULL);
+
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("RtlQueryRegistryValues() failed (Status %lx)\n", Status);
+ return RtlNtStatusToDosError(Status);
+ }
+
+ swprintf(NtControlPipeName, L"\\\\.\\pipe\\net\\NtControlPipe%u",
dwServiceCurrent);
+
+ if (!WaitNamedPipeW(NtControlPipeName, 15000))
+ {
+ DPRINT1("WaitNamedPipe(%S) failed (Error %lu)\n", NtControlPipeName,
GetLastError());
return ERROR_FAILED_SERVICE_CONTROLLER_CONNECT;
}
- *hPipe = CreateFileW(L"\\\\.\\pipe\\net\\NtControlPipe",
+ *hPipe = CreateFileW(NtControlPipeName,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,