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

Add new exec package for host process containers #1233

Merged
merged 6 commits into from
Dec 18, 2021

Conversation

dcantah
Copy link
Contributor

@dcantah dcantah commented Nov 20, 2021

This change adds a new exec package thats main goal is to run
external processes on Windows. Unfortunately due to a couple
things that can't be accomplished with the stdlib os/exec package,
this new package is meant to replace how processes for host process
containers are launched.

The main shortcomings for os/exec are not being able to pass in a pseudo console to use
for tty scenarios, and not being able to start a process assigned to a job object
instead of doing the Create -> Assign dance. Both of these issue are centered
around not having access to the process thread attribute list that is setup inside
of syscall.StartProcess. This is needed to be able to properly setup both cases,
as it requires calling UpdateProcThreadAttribute and passing in what's necessary
for both scenarios.

Signed-off-by: Daniel Canter dcanter@microsoft.com

@dcantah dcantah requested a review from a team as a code owner November 20, 2021 03:40
@dcantah
Copy link
Contributor Author

dcantah commented Nov 20, 2021

Don't be scared of the 347 changed files haha, 90% is just new files from bumping golang.org/x/sys in the main go.mod and in /test.

internal/exec/options.go Outdated Show resolved Hide resolved
internal/exec/exec.go Outdated Show resolved Hide resolved
internal/exec/exec.go Outdated Show resolved Hide resolved
@helsaawy
Copy link
Contributor

lgtm

@dcantah
Copy link
Contributor Author

dcantah commented Nov 30, 2021

@ambarve PTAL

internal/winapi/process.go Outdated Show resolved Hide resolved
internal/winapi/process.go Outdated Show resolved Hide resolved
internal/exec/exec.go Show resolved Hide resolved
internal/exec/exec.go Outdated Show resolved Hide resolved
internal/exec/exec_test.go Outdated Show resolved Hide resolved
internal/exec/exec_test.go Show resolved Hide resolved
This change adds a new exec package thats main goal is to run
external processes on Windows. Unfortunately due to a couple
things that can't be accomplished with the stdlib os/exec package,
this new package is meant to replace how processes for host process
containers are launched.

The main shortcomings are not being able to pass in a pseudo console to use
for tty scenarios, and not being able to start a process assigned to a job object
instead of doing the Create -> Assign dance. Both of these issue are centered
around not having access to the process thread attribute list that is setup inside
of syscall.StartProcess. This is needed to be able to properly setup both cases,
as it requires calling UpdateProcThreadAttribute and passing in what's necessary
for both scenarios.

Signed-off-by: Daniel Canter <dcanter@microsoft.com>
* Remove conpty comments
* Terminate the process if os.FindProcess doesn't work.

Signed-off-by: Daniel Canter <dcanter@microsoft.com>
This change adds pseudo console support to the exec package.

Signed-off-by: Daniel Canter <dcanter@microsoft.com>
x/sys/windows has the Proc thread attribute work we need already, so swap
to this instead of our own definitions.

Signed-off-by: Daniel Canter <dcanter@microsoft.com>
@dcantah
Copy link
Contributor Author

dcantah commented Dec 16, 2021

@katiewasnothere @anmaxvl Anyone able to take a look at this?

1. Add comment regarding thread safety
2. Add check on job object test to make sure the pids slice has at least
one element before testing what's in [0].
3. Change stdioOurEnd -> stdioPipesOurSide and
stdioProcEnd -> stdioPipesProcSide.
4. Misc. clarification comments on fields and methods.
5. Change from raw string literal in powershell test to string with carriage
return at the end.

Signed-off-by: Daniel Canter <dcanter@microsoft.com>
return fmt.Errorf("failed to create process: %w", err)
}
// Don't need the thread handle for anything.
defer windows.CloseHandle(windows.Handle(pi.Thread)) //nolint:errcheck
Copy link
Contributor

Choose a reason for hiding this comment

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

can we change this to

defer func() {
    _ = windows.CloseHandle(windows.Handle(pi.Thread))
}() 

instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 28 to 30
// Either: New() -> e.Start() -> e.Wait()
//
// or: New() -> e.Run()
Copy link
Contributor

Choose a reason for hiding this comment

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

We should add something about ExitCode and Pid, etc I think

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Copy link
Contributor

@katiewasnothere katiewasnothere left a comment

Choose a reason for hiding this comment

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

small requests otherwise lgtm

1. Add nod to using e.ExitCode() in the process lifecycle comment
2. Change to different way to defer close the thread handle to avoid
nolint comment

Signed-off-by: Daniel Canter <dcanter@microsoft.com>
@dcantah dcantah merged commit 2314362 into microsoft:master Dec 18, 2021
dcantah added a commit to dcantah/hcsshim that referenced this pull request Jan 4, 2022
* Add new exec package for host process containers

This change adds a new exec package thats main goal is to run
external processes on Windows. Unfortunately due to a couple
things that can't be accomplished with the stdlib os/exec package,
this new package is meant to replace how processes for host process
containers are launched.

The main shortcomings are not being able to pass in a pseudo console to use
for tty scenarios, and not being able to start a process assigned to a job object
instead of doing the Create -> Assign dance. Both of these issue are centered
around not having access to the process thread attribute list that is setup inside
of syscall.StartProcess. This is needed to be able to properly setup both cases,
as it requires calling UpdateProcThreadAttribute and passing in what's necessary
for both scenarios.

This change ends up bumping x/sys/windows as well to grab some fixes for the attribute list functionality.

Signed-off-by: Daniel Canter <dcanter@microsoft.com>
(cherry picked from commit 2314362)
Signed-off-by: Daniel Canter <dcanter@microsoft.com>
dcantah added a commit to dcantah/hcsshim that referenced this pull request Jan 4, 2022
* Add new exec package for host process containers

This change adds a new exec package thats main goal is to run
external processes on Windows. Unfortunately due to a couple
things that can't be accomplished with the stdlib os/exec package,
this new package is meant to replace how processes for host process
containers are launched.

The main shortcomings are not being able to pass in a pseudo console to use
for tty scenarios, and not being able to start a process assigned to a job object
instead of doing the Create -> Assign dance. Both of these issue are centered
around not having access to the process thread attribute list that is setup inside
of syscall.StartProcess. This is needed to be able to properly setup both cases,
as it requires calling UpdateProcThreadAttribute and passing in what's necessary
for both scenarios.

This change ends up bumping x/sys/windows as well to grab some fixes for the attribute list functionality.

Signed-off-by: Daniel Canter <dcanter@microsoft.com>
(cherry picked from commit 2314362)
Signed-off-by: Daniel Canter <dcanter@microsoft.com>
princepereira pushed a commit to princepereira/hcsshim that referenced this pull request Aug 29, 2024
* Add new exec package for host process containers

This change adds a new exec package thats main goal is to run
external processes on Windows. Unfortunately due to a couple
things that can't be accomplished with the stdlib os/exec package,
this new package is meant to replace how processes for host process
containers are launched.

The main shortcomings are not being able to pass in a pseudo console to use
for tty scenarios, and not being able to start a process assigned to a job object
instead of doing the Create -> Assign dance. Both of these issue are centered
around not having access to the process thread attribute list that is setup inside
of syscall.StartProcess. This is needed to be able to properly setup both cases,
as it requires calling UpdateProcThreadAttribute and passing in what's necessary
for both scenarios.

This change ends up bumping x/sys/windows as well to grab some fixes for the attribute list functionality.

Signed-off-by: Daniel Canter <dcanter@microsoft.com>
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.

4 participants