-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor ConsoleProcessList #14421
Refactor ConsoleProcessList #14421
Changes from all commits
76a1367
e1bb5ef
2aef629
6724ed1
1b967c3
c686b11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -275,27 +275,21 @@ void ProcessCtrlEvents() | |
const auto LimitingProcessId = gci.LimitingProcessId; | ||
gci.LimitingProcessId = 0; | ||
|
||
ConsoleProcessTerminationRecord* rgProcessHandleList; | ||
size_t cProcessHandleList; | ||
|
||
auto hr = gci.ProcessHandleList | ||
.GetTerminationRecordsByGroupId(LimitingProcessId, | ||
WI_IsFlagSet(gci.CtrlFlags, | ||
CONSOLE_CTRL_CLOSE_FLAG), | ||
&rgProcessHandleList, | ||
&cProcessHandleList); | ||
|
||
if (FAILED(hr) || cProcessHandleList == 0) | ||
std::vector<ConsoleProcessTerminationRecord> termRecords; | ||
const auto hr = gci.ProcessHandleList | ||
.GetTerminationRecordsByGroupId(LimitingProcessId, | ||
WI_IsFlagSet(gci.CtrlFlags, | ||
CONSOLE_CTRL_CLOSE_FLAG), | ||
termRecords); | ||
|
||
if (FAILED(hr) || termRecords.empty()) | ||
{ | ||
gci.UnlockConsole(); | ||
return; | ||
} | ||
|
||
// Copy ctrl flags. | ||
auto CtrlFlags = gci.CtrlFlags; | ||
FAIL_FAST_IF(!(!((CtrlFlags & (CONSOLE_CTRL_CLOSE_FLAG | CONSOLE_CTRL_BREAK_FLAG | CONSOLE_CTRL_C_FLAG)) && (CtrlFlags & (CONSOLE_CTRL_LOGOFF_FLAG | CONSOLE_CTRL_SHUTDOWN_FLAG))))); | ||
|
||
gci.CtrlFlags = 0; | ||
const auto CtrlFlags = std::exchange(gci.CtrlFlags, 0); | ||
|
||
gci.UnlockConsole(); | ||
|
||
|
@@ -330,10 +324,13 @@ void ProcessCtrlEvents() | |
case CONSOLE_CTRL_SHUTDOWN_FLAG: | ||
EventType = CTRL_SHUTDOWN_EVENT; | ||
break; | ||
|
||
default: | ||
return; | ||
} | ||
|
||
auto Status = STATUS_SUCCESS; | ||
for (size_t i = 0; i < cProcessHandleList; i++) | ||
for (const auto& r : termRecords) | ||
{ | ||
/* | ||
* Status will be non-successful if a process attached to this console | ||
|
@@ -347,20 +344,13 @@ void ProcessCtrlEvents() | |
if (NT_SUCCESS(Status)) | ||
{ | ||
Status = ServiceLocator::LocateConsoleControl() | ||
->EndTask(rgProcessHandleList[i].dwProcessID, | ||
->EndTask(r.dwProcessID, | ||
EventType, | ||
CtrlFlags); | ||
if (rgProcessHandleList[i].hProcess == nullptr) | ||
if (!r.hProcess) | ||
{ | ||
Status = STATUS_SUCCESS; | ||
} | ||
} | ||
|
||
if (rgProcessHandleList[i].hProcess != nullptr) | ||
{ | ||
CloseHandle(rgProcessHandleList[i].hProcess); | ||
} | ||
Comment on lines
-359
to
-362
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we still need this in the event that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made it so that the |
||
} | ||
|
||
delete[] rgProcessHandleList; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no good reason for this to fail-fast. We can just add a
default:
case to the switch case below, which I now did.