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

Remove job object and startup suspended behavior #2198

Merged
merged 1 commit into from
Aug 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 11 additions & 31 deletions src/cascadia/TerminalConnection/ConhostConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,35 +79,6 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
extraEnvVars.emplace(L"WT_SESSION", pwszGuid);
}

THROW_IF_FAILED(
CreateConPty(cmdline,
startingDirectory,
static_cast<short>(_initialCols),
static_cast<short>(_initialRows),
&_inPipe,
&_outPipe,
&_signalPipe,
&_piConhost,
CREATE_SUSPENDED,
extraEnvVars));

_hJob.reset(CreateJobObjectW(nullptr, nullptr));
THROW_LAST_ERROR_IF_NULL(_hJob);

// We want the conhost and all associated descendant processes
// to be terminated when the tab is closed. GUI applications
// spawned from the shell tend to end up in their own jobs.
JOBOBJECT_EXTENDED_LIMIT_INFORMATION jobExtendedInformation{};
jobExtendedInformation.BasicLimitInformation.LimitFlags =
JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;

THROW_IF_WIN32_BOOL_FALSE(SetInformationJobObject(_hJob.get(),
JobObjectExtendedLimitInformation,
&jobExtendedInformation,
sizeof(jobExtendedInformation)));

THROW_IF_WIN32_BOOL_FALSE(AssignProcessToJobObject(_hJob.get(), _piConhost.hProcess));

// Create our own output handling thread
// Each connection needs to make sure to drain the output from its backing host.
_hOutputThread.reset(CreateThread(nullptr,
Expand All @@ -119,8 +90,17 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation

THROW_LAST_ERROR_IF_NULL(_hOutputThread);

// Wind up the conhost! We only do this after we've got everything in place.
THROW_LAST_ERROR_IF(-1 == ResumeThread(_piConhost.hThread));
THROW_IF_FAILED(
CreateConPty(cmdline,
startingDirectory,
static_cast<short>(_initialCols),
static_cast<short>(_initialRows),
&_inPipe,
&_outPipe,
&_signalPipe,
&_piConhost,
0,
extraEnvVars));

_connected = true;
}
Expand Down