Skip to content

Add new exec package for host process containers#1233

Merged
dcantah merged 6 commits into
microsoft:masterfrom
dcantah:exec-pkg
Dec 18, 2021
Merged

Add new exec package for host process containers#1233
dcantah merged 6 commits into
microsoft:masterfrom
dcantah:exec-pkg

Conversation

@dcantah

@dcantah dcantah commented Nov 20, 2021

Copy link
Copy Markdown
Contributor

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 [email protected]

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

dcantah commented Nov 20, 2021

Copy link
Copy Markdown
Contributor Author

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.

Comment thread internal/exec/options.go Outdated
@dcantah dcantah force-pushed the exec-pkg branch 2 times, most recently from 0a2e90d to dbe2d29 Compare November 22, 2021 20:39
Comment thread internal/exec/exec.go Outdated
Comment thread internal/exec/exec.go
Comment thread internal/exec/exec.go Outdated
@helsaawy

Copy link
Copy Markdown
Contributor

lgtm

@dcantah

dcantah commented Nov 30, 2021

Copy link
Copy Markdown
Contributor Author

@ambarve PTAL

Comment thread internal/winapi/process.go Outdated
Comment thread internal/winapi/process.go Outdated
Comment thread internal/exec/exec.go
Comment thread internal/exec/exec.go Outdated
Comment thread internal/exec/exec_test.go Outdated
Comment thread internal/exec/exec_test.go
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 <[email protected]>
* Remove conpty comments
* Terminate the process if os.FindProcess doesn't work.

Signed-off-by: Daniel Canter <[email protected]>
This change adds pseudo console support to the exec package.

Signed-off-by: Daniel Canter <[email protected]>
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 <[email protected]>
@dcantah

dcantah commented Dec 16, 2021

Copy link
Copy Markdown
Contributor Author

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

Comment thread internal/exec/exec.go
Comment thread internal/exec/exec.go
Comment thread internal/exec/exec.go
Comment thread internal/exec/exec.go Outdated
Comment thread internal/exec/exec_test.go Outdated
Comment thread internal/exec/exec_test.go
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 <[email protected]>
Comment thread internal/exec/exec.go Outdated
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
Copy Markdown

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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread internal/exec/exec.go Outdated
Comment on lines +28 to +30
// Either: New() -> e.Start() -> e.Wait()
//
// or: New() -> e.Run()

Copy link
Copy Markdown

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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!

@katiewasnothere katiewasnothere left a comment

Copy link
Copy Markdown

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 <[email protected]>
@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 <[email protected]>
(cherry picked from commit 2314362)
Signed-off-by: Daniel Canter <[email protected]>
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 <[email protected]>
(cherry picked from commit 2314362)
Signed-off-by: Daniel Canter <[email protected]>
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 <[email protected]>
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