From 3bd63cad35a26567638a4d64a0b68ea3b0c91caa Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Sat, 18 Feb 2012 22:29:46 +0000 Subject: [PATCH] [KERNEL32]: Try to connect to the Console Server when initializing console support. For normal apps, won't do anything since ConnectionInfo == NULL (to hack around the fact there's no server in ReactOS for this), but for DLLs running inside of CSRSS, because we now support Server-to-Server, the call will detect that and not fail. This fixes the "failed to give us console" error when kernel32 inside of csrss tries to get a console (which it shouldn't). There's still user32 to cleanup. svn path=/trunk/; revision=55684 --- reactos/dll/win32/kernel32/client/dllmain.c | 38 ++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/reactos/dll/win32/kernel32/client/dllmain.c b/reactos/dll/win32/kernel32/client/dllmain.c index ec45934e29b..b0068fefe00 100644 --- a/reactos/dll/win32/kernel32/client/dllmain.c +++ b/reactos/dll/win32/kernel32/client/dllmain.c @@ -68,7 +68,10 @@ BasepInitConsole(VOID) PRTL_USER_PROCESS_PARAMETERS Parameters = NtCurrentPeb()->ProcessParameters; LPCWSTR ExeName; STARTUPINFO si; - + WCHAR SessionDir[256]; + ULONG SessionId = NtCurrentPeb()->SessionId; + BOOLEAN InServer; + WCHAR lpTest[MAX_PATH]; GetModuleFileNameW(NULL, lpTest, MAX_PATH); DPRINT("BasepInitConsole for : %S\n", lpTest); @@ -136,6 +139,38 @@ BasepInitConsole(VOID) /* Now use the proper console handle */ Request.Data.AllocConsoleRequest.Console = Parameters->ConsoleHandle; + + /* Setup the right Object Directory path */ + if (!SessionId) + { + /* Use the raw path */ + wcscpy(SessionDir, WIN_OBJ_DIR); + } + else + { + /* Use the session path */ + swprintf(SessionDir, + L"%ws\\%ld%ws", + SESSION_DIR, + SessionId, + WIN_OBJ_DIR); + } + + /* Connect to the base server */ + DPRINT("Connecting to CSR...\n"); + Status = CsrClientConnectToServer(SessionDir, + 2, + NULL, + NULL, + &InServer); + if (!NT_SUCCESS(Status)) + { + DPRINT1("Failed to connect to CSR (Status %lx)\n", Status); + return FALSE; + } + + /* Nothing to do for server-to-server */ + if (InServer) return TRUE; /* * Normally, we should be connecting to the Console CSR Server... @@ -156,6 +191,7 @@ BasepInitConsole(VOID) return TRUE; } + /* Nothing to do if not a console app */ if (NotConsole) return TRUE; /* We got the handles, let's set them */