diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 24c25697..ba1507d7 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -16,7 +16,7 @@ builds: - "-X github.com/stacklok/toolhive/pkg/versions.BuildDate={{ .Date }}" goos: - linux -# - windows + - windows - darwin goarch: - amd64 diff --git a/pkg/lifecycle/manager.go b/pkg/lifecycle/manager.go index 6bc2a12b..0752cb01 100644 --- a/pkg/lifecycle/manager.go +++ b/pkg/lifecycle/manager.go @@ -7,7 +7,6 @@ import ( "fmt" "os" "os/exec" - "syscall" "github.com/adrg/xdg" @@ -312,9 +311,7 @@ func (*defaultManager) RunContainerDetached(runConfig *runner.RunConfig) error { // Detach the process from the terminal detachedCmd.Stdin = nil - detachedCmd.SysProcAttr = &syscall.SysProcAttr{ - Setsid: true, // Create a new session - } + detachedCmd.SysProcAttr = getSysProcAttr() // Start the detached process if err := detachedCmd.Start(); err != nil { diff --git a/pkg/lifecycle/sysproc_unix.go b/pkg/lifecycle/sysproc_unix.go new file mode 100644 index 00000000..f770e8ab --- /dev/null +++ b/pkg/lifecycle/sysproc_unix.go @@ -0,0 +1,15 @@ +//go:build !windows +// +build !windows + +package lifecycle + +import ( + "syscall" +) + +// getSysProcAttr returns the platform-specific SysProcAttr for detaching processes +func getSysProcAttr() *syscall.SysProcAttr { + return &syscall.SysProcAttr{ + Setsid: true, // Create a new session (Unix only) + } +} diff --git a/pkg/lifecycle/sysproc_windows.go b/pkg/lifecycle/sysproc_windows.go new file mode 100644 index 00000000..c236aaba --- /dev/null +++ b/pkg/lifecycle/sysproc_windows.go @@ -0,0 +1,17 @@ +//go:build windows +// +build windows + +package lifecycle + +import ( + "syscall" +) + +// getSysProcAttr returns the platform-specific SysProcAttr for detaching processes +func getSysProcAttr() *syscall.SysProcAttr { + return &syscall.SysProcAttr{ + // Windows doesn't have Setsid + // Instead, use CreationFlags with CREATE_NEW_PROCESS_GROUP and DETACHED_PROCESS + CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP | 0x00000008, // 0x00000008 is DETACHED_PROCESS + } +} \ No newline at end of file