Skip to content

Conversation

thaJeztah
Copy link
Member

Adds a CommandContext command, to provide the equivalent of exec.CommandContext.

@thaJeztah thaJeztah force-pushed the reexec_with_context branch from 5f9dbf9 to a80dcff Compare June 24, 2025 10:40
@thaJeztah
Copy link
Member Author

Had to remove some bits from the test, because exec.Command.Cancel was added in go1.20, and we still test against go1.18 for this module;

go: no module dependencies to download
Error: reexec/reexec_test.go:172:8: cmd.Cancel undefined (type *exec.Cmd has no field or method Cancel) (typecheck)
make: *** [Makefile:19: foreach] Error 1
			cmd.Cancel = func() error {
			    ^

doc: "context timeout",
cmdAndArgs: []string{testReExec3},
expOut: "Hello test-reexec3",
expError: "signal: killed",
Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, derp, and of course, windows has a different error;

=== RUN   TestCommandContext/context_timeout
    reexec_test.go:190: got "exit status 1", want "signal: killed"

@thaJeztah thaJeztah force-pushed the reexec_with_context branch 2 times, most recently from f99a5f7 to 42b1ba7 Compare June 24, 2025 10:56
@thaJeztah thaJeztah marked this pull request as ready for review June 24, 2025 10:57
@thaJeztah
Copy link
Member Author

Adds a CommandContext command, to provide the equivalent of
exec.CommandContext.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah thaJeztah force-pushed the reexec_with_context branch from 42b1ba7 to 7aa8514 Compare June 24, 2025 11:05
@thaJeztah thaJeztah requested a review from Copilot June 24, 2025 11:05
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a CommandContext wrapper mirroring exec.CommandContext in the reexec package, enabling context-based cancellation for re-executed commands. Key changes:

  • Added CommandContext API in reexec.go and platform-specific implementations in reexec_other.go and reexec_linux.go.
  • Updated imports and registrations to support context-aware execution.
  • Added TestCommandContext in reexec_test.go to validate context cancellation, timeouts, and argument handling.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
reexec/reexec.go Added public CommandContext function and imported context.
reexec/reexec_other.go Introduced generic commandContext implementation.
reexec/reexec_linux.go Added Linux-specific commandContext with Pdeathsig support.
reexec/reexec_test.go New TestCommandContext covering basename, full path, args, cancel, and timeout cases.
Comments suppressed due to low confidence (2)

reexec/reexec_test.go:139

  • Missing import of "path/filepath", which is required for filepath.Join. Please add "path/filepath" to the import block.
			cmdAndArgs: []string{filepath.Join("something", testReExec2)},

reexec/reexec_other.go:19

  • This commandContext is duplicated in reexec_linux.go, leading to a redeclaration error on Linux builds. Add a build tag like // +build !linux at the top of this file to restrict it to non-Linux platforms.
func commandContext(ctx context.Context, args ...string) *exec.Cmd {

@thaJeztah thaJeztah merged commit 6b0a691 into moby:main Jun 24, 2025
20 checks passed
@thaJeztah thaJeztah deleted the reexec_with_context branch June 24, 2025 11:57
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.

2 participants