Skip to content
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

Give the root PID ownership of the pseudoconsole window #14196

Merged
6 commits merged into from
Dec 1, 2022

Conversation

DHowett
Copy link
Member

@DHowett DHowett commented Oct 12, 2022

This is a partial fix for the Get-Credential issue. While investigating it, I found that the pseudoconsole window is not marked as being "owned" (in NTUSER) by the PID/TID of the console application that is "hosted" "in" it. Doing this does not (and cannot) fix Get-Credential failing in DefTerm scenarios.

ConsoleSetWindowOwner is one of the operations that can be done by a conhost to any window, and so the RemoteConsoleControl can call through to the Win32 ConsoleControl to pull it off.

I chose to add SetWindowOwner to the IConsoleControl interface instead of moving ConsoleControl::Control into the interface to reduce the amount of churn and better separate interface responsibilities.

References #14119

@DHowett
Copy link
Member Author

DHowett commented Oct 12, 2022

There's a TODO yet to be done: make sure that ownership changes when the root process exits. Terminal doesn't care about that right now, but other ConPTY clients don't have the same requirements as Terminal.

@DHowett DHowett changed the title Give the root PID owhership of the pseudoconsole window Give the root PID ownership of the pseudoconsole window Oct 12, 2022
This is a partial fix for the Get-Credential issue. While investigating
it, I found that the pseudoconsole window is not marked as being "owned"
(in NTUSER) by the PID/TID of the console application that is "hosted"
"in" it. Doing this does not (and cannot) fix `Get-Credential` failing
in DefTerm scenarios.

ConsoleSetWindowOwner is one of the operations that can be done by a
conhost to any window, and so the RemoteConsoleControl can call through
to the Win32 ConsoleControl to pull it off.

I chose to add SetWindowOwner to the IConsoleControl interface instead
of moving ConsoleControl::Control into the interface to reduce the
amount of churn and better separate interface responsibilities.

References #14119
@DHowett DHowett force-pushed the dev/duhowett/looking_for_an_owner_plz_adopt_me branch from e051751 to f0f74d7 Compare October 12, 2022 20:53
Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fine. Probably. ROOT_PROCESS_ID should be the same as GetFirstProcess()

@@ -78,7 +78,13 @@ VOID SetConsoleWindowOwner(const HWND hwnd, _Inout_opt_ ConsoleProcessHandle* pP
else
{
// Find a process to own the console window. If there are none then let's use conhost's.
pProcessData = gci.ProcessHandleList.GetFirstProcess();
pProcessData = gci.ProcessHandleList.FindProcessInList(ConsoleProcessList::ROOT_PROCESS_ID);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line feels like a scary change that might stealth break something we can't immagine

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I went through all the callers of this function. They either provide the root process, OR there is no root process... at which point, a random process is selected. The oldest one still connected.

I think it's safe to say "the root process IS the oldest, and we should default to that if we can. Otherwise, we can choose the NEXT oldest"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah btw, GetFirstProcess() returns the newest process and not the oldest. See: #14421 (comment)

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@zadjii-msft zadjii-msft added the AutoMerge Marked for automatic merge by the bot when requirements are met label Dec 1, 2022
@ghost
Copy link

ghost commented Dec 1, 2022

Hello @zadjii-msft!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@DHowett DHowett removed the AutoMerge Marked for automatic merge by the bot when requirements are met label Dec 1, 2022
@ghost ghost merged commit 62ffa4b into main Dec 1, 2022
@ghost ghost deleted the dev/duhowett/looking_for_an_owner_plz_adopt_me branch December 1, 2022 22:22
DHowett added a commit that referenced this pull request Dec 12, 2022
This is a partial fix for the Get-Credential issue. While investigating it, I found that the pseudoconsole window is not marked as being "owned" (in NTUSER) by the PID/TID of the console application that is "hosted" "in" it. Doing this does not (and cannot) fix `Get-Credential` failing in DefTerm scenarios.

ConsoleSetWindowOwner is one of the operations that can be done by a conhost to any window, and so the RemoteConsoleControl can call through to the Win32 ConsoleControl to pull it off.

I chose to add SetWindowOwner to the IConsoleControl interface instead of moving ConsoleControl::Control into the interface to reduce the amount of churn and better separate interface responsibilities.

References #14119

(cherry picked from commit 62ffa4b)
Service-Card-Id: 87207850
Service-Version: 1.15
DHowett added a commit that referenced this pull request Dec 12, 2022
This is a partial fix for the Get-Credential issue. While investigating it, I found that the pseudoconsole window is not marked as being "owned" (in NTUSER) by the PID/TID of the console application that is "hosted" "in" it. Doing this does not (and cannot) fix `Get-Credential` failing in DefTerm scenarios.

ConsoleSetWindowOwner is one of the operations that can be done by a conhost to any window, and so the RemoteConsoleControl can call through to the Win32 ConsoleControl to pull it off.

I chose to add SetWindowOwner to the IConsoleControl interface instead of moving ConsoleControl::Control into the interface to reduce the amount of churn and better separate interface responsibilities.

References #14119

(cherry picked from commit 62ffa4b)
Service-Card-Id: 87207849
Service-Version: 1.16
@ghost
Copy link

ghost commented Dec 14, 2022

🎉Windows Terminal v1.15.3465.0 and v1.15.3466.0 has been released which incorporates this pull request.:tada:

Handy links:

@ghost
Copy link

ghost commented Dec 14, 2022

🎉Windows Terminal Preview v1.16.3463.0 and v1.16.3464.0 has been released which incorporates this pull request.:tada:

Handy links:

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants