Author: gadamopoulos Date: Tue Sep 26 09:11:51 2017 New Revision: 75973 URL: http://svn.reactos.org/svn/reactos?rev=75973&view=rev Log: [WINLOGON][WIN32K][WINSRV] -Silence a lot of debug prints in the shutdown sequence. Add some debug prints in case of error. Also print the name of the processes that get terminated. Keep the debug prints that show the parameters that are passed to SrvExitWindowsEx and WM_LOGONNOTIFY.
Modified: trunk/reactos/base/system/winlogon/sas.c trunk/reactos/win32ss/user/ntuser/ntstubs.c trunk/reactos/win32ss/user/ntuser/shutdown.c trunk/reactos/win32ss/user/winsrv/consrv/shutdown.c trunk/reactos/win32ss/user/winsrv/usersrv.cmake trunk/reactos/win32ss/user/winsrv/usersrv/shutdown.c Modified: trunk/reactos/base/system/winlogon/sas.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/winlogon/sas.c?rev=75973&r1=75972&r2=75973&view=diff ============================================================================== --- trunk/reactos/base/system/winlogon/sas.c [iso-8859-1] (original) +++ trunk/reactos/base/system/winlogon/sas.c [iso-8859-1] Tue Sep 26 09:11:51 2017 @@ -558,7 +558,7 @@ uFlags = EWX_CALLER_WINLOGON | (LSData->Flags & 0x0F); - ERR("In LogoffShutdownThread with uFlags == 0x%x; exit_in_progress == %s\n", + TRACE("In LogoffShutdownThread with uFlags == 0x%x; exit_in_progress == %s\n", uFlags, ExitReactOSInProgress ? "true" : "false"); ExitReactOSInProgress = TRUE; @@ -585,7 +585,7 @@ DWORD ret = 1; PLOGOFF_SHUTDOWN_DATA LSData = (PLOGOFF_SHUTDOWN_DATA)Parameter; - ERR("In KillComProcesses\n"); + TRACE("In KillComProcesses\n"); if (LSData->Session->UserToken != NULL && !ImpersonateLoggedOnUser(LSData->Session->UserToken)) @@ -1446,7 +1446,7 @@ } } - ERR("In LN_LOGOFF, exit_in_progress == %s\n", + TRACE("In LN_LOGOFF, exit_in_progress == %s\n", ExitReactOSInProgress ? "true" : "false"); /* Modified: trunk/reactos/win32ss/user/ntuser/ntstubs.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/ntuser/ntstubs.c?rev=75973&r1=75972&r2=75973&view=diff ============================================================================== --- trunk/reactos/win32ss/user/ntuser/ntstubs.c [iso-8859-1] (original) +++ trunk/reactos/win32ss/user/ntuser/ntstubs.c [iso-8859-1] Tue Sep 26 09:11:51 2017 @@ -722,7 +722,7 @@ { ULONG CapturedFlags = 0; - ERR("Shutdown initiated\n"); + TRACE("Shutdown initiated\n"); if (ThreadInformationLength != sizeof(ULONG)) { @@ -764,7 +764,7 @@ { NTSTATUS ShutdownStatus; - ERR("Shutdown ended\n"); + TRACE("Shutdown ended\n"); if (ThreadInformationLength != sizeof(ShutdownStatus)) { Modified: trunk/reactos/win32ss/user/ntuser/shutdown.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/ntuser/shutdown.c?rev=75973&r1=75972&r2=75973&view=diff ============================================================================== --- trunk/reactos/win32ss/user/ntuser/shutdown.c [iso-8859-1] (original) +++ trunk/reactos/win32ss/user/ntuser/shutdown.c [iso-8859-1] Tue Sep 26 09:11:51 2017 @@ -186,7 +186,7 @@ // if (hwndSAS && ( (Flags & EWX_SHUTDOWN) || RtlEqualLuid(CallerLuid, &SystemLuid)) ) if (hwndSAS) { - ERR("\tSending %s message to Winlogon\n", Notif == LN_LOGOFF ? "LN_LOGOFF" : "LN_LOGOFF_CANCELED"); + TRACE("\tSending %s message to Winlogon\n", Notif == LN_LOGOFF ? "LN_LOGOFF" : "LN_LOGOFF_CANCELED"); UserPostMessage(hwndSAS, WM_LOGONNOTIFY, Notif, (LPARAM)Param); return TRUE; } @@ -214,13 +214,13 @@ PPROCESSINFO ppi; - ERR("UserInitiateShutdown\n"); + TRACE("UserInitiateShutdown\n"); /* Get the caller's LUID */ Status = GetProcessLuid(Thread, &CallerLuid); if (!NT_SUCCESS(Status)) { - ERR("GetProcessLuid failed\n"); + ERR("UserInitiateShutdown: GetProcessLuid failed\n"); return Status; } @@ -239,7 +239,10 @@ /* Retrieve the Win32 process info */ ppi = PsGetProcessWin32Process(PsGetThreadProcess(Thread)); if (ppi == NULL) + { + ERR("UserInitiateShutdown: Failed to get win32 thread!\n"); return STATUS_INVALID_HANDLE; + } /* If the caller is not Winlogon, do some security checks */ if (PsGetThreadProcessId(Thread) != gpidLogon) @@ -254,11 +257,17 @@ /* Check whether the current process is attached to a window station */ if (ppi->prpwinsta == NULL) + { + ERR("UserInitiateShutdown: Process is not attached to a desktop\n"); return STATUS_INVALID_HANDLE; + } /* Check whether the window station of the current process can send exit requests */ if (!RtlAreAllAccessesGranted(ppi->amwinsta, WINSTA_EXITWINDOWS)) + { + ERR("UserInitiateShutdown: Caller doesn't have the rights to shutdown\n"); return STATUS_ACCESS_DENIED; + } /* * NOTE: USERSRV automatically adds the shutdown flag when we poweroff or reboot. @@ -269,7 +278,10 @@ { /* ... check whether it has shutdown privilege */ if (!HasPrivilege(&ShutdownPrivilege)) + { + ERR("UserInitiateShutdown: Caller doesn't have the rights to shutdown\n"); return STATUS_PRIVILEGE_NOT_HELD; + } } else { @@ -278,7 +290,10 @@ * window station is a non-IO one, fail the call. */ if (ppi->prpwinsta->Flags & WSS_NOIO) + { + ERR("UserInitiateShutdown: Caller doesn't have the rights to logoff\n"); return STATUS_INVALID_DEVICE_REQUEST; + } } } @@ -286,13 +301,13 @@ if (PsGetThreadProcessId(Thread) != gpidLogon) { // FIXME: HACK!! Do more checks!! - ERR("UserInitiateShutdown -- Notify Winlogon for shutdown\n"); + TRACE("UserInitiateShutdown: Notify Winlogon for shutdown\n"); NotifyLogon(hwndSAS, &CallerLuid, Flags, STATUS_SUCCESS); return STATUS_PENDING; } // If we reach this point, that means it's Winlogon that triggered the shutdown. - ERR("UserInitiateShutdown -- Winlogon is doing a shutdown\n"); + TRACE("UserInitiateShutdown: Winlogon is doing a shutdown\n"); /* * Update and save the shutdown flags globally for renotifying @@ -315,13 +330,13 @@ ULONG Flags; LUID CallerLuid; - ERR("UserEndShutdown\n"); + TRACE("UserEndShutdown called\n"); /* * FIXME: Some cleanup should be done when shutdown succeeds, * and some reset should be done when shutdown is cancelled. */ - STUB; + //STUB; Status = GetProcessLuid(Thread, &CallerLuid); if (!NT_SUCCESS(Status)) @@ -345,7 +360,7 @@ // FIXME: Should we reset gdwShutdownFlags to 0 ?? } - ERR("UserEndShutdown -- Notify Winlogon for end of shutdown\n"); + TRACE("UserEndShutdown: Notify Winlogon for end of shutdown\n"); NotifyLogon(hwndSAS, &CallerLuid, Flags, ShutdownStatus); /* Always return success */ Modified: trunk/reactos/win32ss/user/winsrv/consrv/shutdown.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/winsrv/consrv/shutdown.c?rev=75973&r1=75972&r2=75973&view=diff ============================================================================== --- trunk/reactos/win32ss/user/winsrv/consrv/shutdown.c [iso-8859-1] (original) +++ trunk/reactos/win32ss/user/winsrv/consrv/shutdown.c [iso-8859-1] Tue Sep 26 09:11:51 2017 @@ -24,12 +24,12 @@ { PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrProcess); - UNIMPLEMENTED; + //FIXME: UNIMPLEMENTED! if ( ProcessData->ConsoleHandle != NULL || ProcessData->HandleTable != NULL ) { - DPRINT1("ConsoleClientShutdown(0x%p, 0x%x, %s) - Console process [0x%x, 0x%x]\n", + DPRINT("ConsoleClientShutdown(0x%p, 0x%x, %s) - Console process [0x%x, 0x%x]\n", CsrProcess, Flags, FirstPhase ? "FirstPhase" : "LastPhase", CsrProcess->ClientId.UniqueProcess, CsrProcess->ClientId.UniqueThread); @@ -39,7 +39,7 @@ } else { - DPRINT1("ConsoleClientShutdown(0x%p, 0x%x, %s) - Non-console process [0x%x, 0x%x]\n", + DPRINT("ConsoleClientShutdown(0x%p, 0x%x, %s) - Non-console process [0x%x, 0x%x]\n", CsrProcess, Flags, FirstPhase ? "FirstPhase" : "LastPhase", CsrProcess->ClientId.UniqueProcess, CsrProcess->ClientId.UniqueThread); Modified: trunk/reactos/win32ss/user/winsrv/usersrv.cmake URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/winsrv/usersrv.cmake?rev=75973&r1=75972&r2=75973&view=diff ============================================================================== --- trunk/reactos/win32ss/user/winsrv/usersrv.cmake [iso-8859-1] (original) +++ trunk/reactos/win32ss/user/winsrv/usersrv.cmake [iso-8859-1] Tue Sep 26 09:11:51 2017 @@ -13,5 +13,5 @@ add_dependencies(usersrv xdk) add_pch(usersrv usersrv/usersrv.h USERSRV_SOURCE) #add_object_library(usersrv ${USERSRV_SOURCE}) -list(APPEND USERSRV_IMPORT_LIBS basesrv) +list(APPEND USERSRV_IMPORT_LIBS basesrv psapi) set_module_type(usersrv module UNICODE) Modified: trunk/reactos/win32ss/user/winsrv/usersrv/shutdown.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/winsrv/usersrv/shutdown.c?rev=75973&r1=75972&r2=75973&view=diff ============================================================================== --- trunk/reactos/win32ss/user/winsrv/usersrv/shutdown.c [iso-8859-1] (original) +++ trunk/reactos/win32ss/user/winsrv/usersrv/shutdown.c [iso-8859-1] Tue Sep 26 09:11:51 2017 @@ -11,6 +11,7 @@ #include "usersrv.h" #include <commctrl.h> +#include <psapi.h> #include "resource.h" @@ -222,7 +223,7 @@ /* If the shutdown is aborted, just notify the process, there is no need to wait */ if ((Context->wParam & (MCS_QUERYENDSESSION | MCS_ENDSESSION)) == 0) { - MY_DPRINT("Called WM_CLIENTSHUTDOWN with wParam == 0 ...\n"); + DPRINT("Called WM_CLIENTSHUTDOWN with wParam == 0 ...\n"); SendNotifyMessageW(Context->Wnd, WM_CLIENTSHUTDOWN, Context->wParam, Context->lParam); return QUERY_RESULT_CONTINUE; @@ -255,12 +256,12 @@ Ret = QUERY_RESULT_CONTINUE; } - MY_DPRINT("SendClientShutdown -- Return == %s\n", + DPRINT("SendClientShutdown -- Return == %s\n", Ret == QUERY_RESULT_CONTINUE ? "Continue" : "Abort"); return Ret; } - MY_DPRINT("SendClientShutdown -- Error == %s\n", + DPRINT1("SendClientShutdown -- Error == %s\n", GetLastError() == 0 ? "Timeout" : "error"); return (GetLastError() == 0 ? QUERY_RESULT_TIMEOUT : QUERY_RESULT_ERROR); @@ -374,7 +375,7 @@ NotifyContext->QueryResult = QUERY_RESULT_TIMEOUT; } - MY_DPRINT("NotifyContext->QueryResult == %d\n", NotifyContext->QueryResult); + DPRINT("NotifyContext->QueryResult == %d\n", NotifyContext->QueryResult); return (NotifyContext->QueryResult == QUERY_RESULT_CONTINUE); } @@ -672,7 +673,7 @@ goto Quit; } - DPRINT1("Caller LUID is: %lx.%lx\n", CallerLuid.HighPart, CallerLuid.LowPart); + DPRINT("Caller LUID is: %lx.%lx\n", CallerLuid.HighPart, CallerLuid.LowPart); /* Shutdown loop */ while (TRUE) @@ -681,23 +682,23 @@ Status = NtUserSetInformationThread(CsrThread->ThreadHandle, UserThreadInitiateShutdown, &Flags, sizeof(Flags)); - DPRINT1("Win32k says: %lx\n", Status); + DPRINT("Win32k says: %lx\n", Status); switch (Status) { /* We cannot wait here, the caller should start a new thread */ case STATUS_CANT_WAIT: - DPRINT1("STATUS_CANT_WAIT\n"); + DPRINT1("NtUserSetInformationThread returned STATUS_CANT_WAIT\n"); goto Quit; /* Shutdown is in progress */ case STATUS_PENDING: - DPRINT1("STATUS_PENDING\n"); + DPRINT1("NtUserSetInformationThread returned STATUS_PENDING\n"); goto Quit; /* Abort */ case STATUS_RETRY: { - DPRINT1("STATUS_RETRY\n"); + DPRINT1("NtUserSetInformationThread returned STATUS_RETRY\n"); UNIMPLEMENTED; continue; } @@ -740,7 +741,7 @@ UserThreadEndShutdown, &Status, sizeof(Status)); - DPRINT1("SrvExitWindowsEx returned 0x%08x\n", Status); + DPRINT("SrvExitWindowsEx returned 0x%08x\n", Status); Quit: /* We are done */ @@ -755,9 +756,10 @@ IN ULONG Flags, IN BOOLEAN FirstPhase) { - DPRINT1("UserClientShutdown(0x%p, 0x%x, %s) - [0x%x, 0x%x]\n", + DPRINT("UserClientShutdown(0x%p, 0x%x, %s) - [0x%x, 0x%x], ShutdownFlags: %lu\n", CsrProcess, Flags, FirstPhase ? "FirstPhase" : "LastPhase", - CsrProcess->ClientId.UniqueProcess, CsrProcess->ClientId.UniqueThread); + CsrProcess->ClientId.UniqueProcess, CsrProcess->ClientId.UniqueThread, + CsrProcess->ShutdownFlags); /* * Check for process validity @@ -767,7 +769,7 @@ if ((Flags & EWX_SHUTDOWN) == EWX_LOGOFF && (CsrProcess->ShutdownFlags & (SHUTDOWN_OTHERCONTEXT | SHUTDOWN_SYSTEMCONTEXT))) { - DPRINT1("Do not kill a system process in a logoff request!\n"); + DPRINT("Do not kill a system process in a logoff request!\n"); return CsrShutdownNonCsrProcess; } @@ -775,32 +777,35 @@ if (CsrProcess->ClientId.UniqueProcess == NtCurrentProcess() || CsrProcess->ClientId.UniqueProcess == UlongToHandle(LogonProcessId)) { - DPRINT1("Not killing %s; CsrProcess->ShutdownFlags = %lu\n", + DPRINT("Not killing %s; CsrProcess->ShutdownFlags = %lu\n", CsrProcess->ClientId.UniqueProcess == NtCurrentProcess() ? "CSRSS" : "Winlogon", CsrProcess->ShutdownFlags); return CsrShutdownNonCsrProcess; } - if (Flags & EWX_CALLER_SYSTEM) - DPRINT1("Killed by a SYSTEM process -- ShutdownFlags = %lu\n", CsrProcess->ShutdownFlags); - else - DPRINT1("Killing process with ShutdownFlags = %lu\n", CsrProcess->ShutdownFlags); - - if (CsrProcess->ShutdownFlags & SHUTDOWN_OTHERCONTEXT) - DPRINT1("This process has SHUTDOWN_OTHERCONTEXT\n"); - - if (CsrProcess->ShutdownFlags & SHUTDOWN_SYSTEMCONTEXT) - DPRINT1("This process has SHUTDOWN_SYSTEMCONTEXT\n"); - /* Notify the process for shutdown if needed */ if (!NotifyProcessForShutdown(CsrProcess, &ShutdownSettings, Flags)) { + DPRINT1("Process 0x%x aborted shutdown\n", CsrProcess->ClientId.UniqueProcess); /* Abort shutdown */ return CsrShutdownCancelled; } /* Terminate this process */ +#if DBG + { + WCHAR buffer[MAX_PATH]; + if (!GetProcessImageFileNameW(CsrProcess->ProcessHandle, buffer, MAX_PATH)) + { + DPRINT1("Terminating process %x\n", CsrProcess->ClientId.UniqueProcess); + } + else + { + DPRINT1("Terminating process %x (%S)\n", CsrProcess->ClientId.UniqueProcess, buffer); + } + } +#endif NtTerminateProcess(CsrProcess->ProcessHandle, 0); /* We are done */