Skip to content
Draft
Show file tree
Hide file tree
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
11 changes: 6 additions & 5 deletions internal/dind/dind.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ func Start(sessionID string) (*Instance, error) {
// Stop removes the dind container and the shared network. Errors are printed to
// stderr but not returned so that deferred calls always complete.
func (i *Instance) Stop() {
if out, err := run("docker", "stop", i.ContainerName); err != nil {
fmt.Fprintf(os.Stderr, "construct: stop dind: %v\n%s\n", err, out)
}
if out, err := run("docker", "rm", i.ContainerName); err != nil {
if out, err := run("docker", "rm", "-f", i.ContainerName); err != nil {
fmt.Fprintf(os.Stderr, "construct: rm dind: %v\n%s\n", err, out)
}
if out, err := run("docker", "network", "rm", i.NetworkName); err != nil {
Expand All @@ -103,7 +100,11 @@ func (i *Instance) waitReady() error {
}

// run executes a command and returns its combined output and any error.
// It runs in its own process group so that SIGINT from Ctrl+C is not
// forwarded to the subprocess.
func run(name string, args ...string) (string, error) {
out, err := exec.Command(name, args...).CombinedOutput()
cmd := exec.Command(name, args...)
setSysProcAttr(cmd)
out, err := cmd.CombinedOutput()
return string(out), err
}
14 changes: 14 additions & 0 deletions internal/dind/sysattr_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build !windows

package dind

import (
"os/exec"
"syscall"
)

// setSysProcAttr places the command in its own process group so that a
// SIGINT from Ctrl+C on the terminal is not forwarded to the subprocess.
func setSysProcAttr(cmd *exec.Cmd) {
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
}
9 changes: 9 additions & 0 deletions internal/dind/sysattr_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build windows

package dind

import "os/exec"

// setSysProcAttr is a no-op on Windows; process group isolation is not
// needed because Windows does not use POSIX process groups for signal delivery.
func setSysProcAttr(cmd *exec.Cmd) {}