Skip to content

Add special handling for running the detached process on Windows #455

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

Merged
merged 3 commits into from
May 23, 2025
Merged
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
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ builds:
- "-X github.com/stacklok/toolhive/pkg/versions.BuildDate={{ .Date }}"
goos:
- linux
# - windows
- windows
- darwin
goarch:
- amd64
Expand Down
5 changes: 1 addition & 4 deletions pkg/lifecycle/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"os"
"os/exec"
"syscall"

"github.com/adrg/xdg"

Expand Down Expand Up @@ -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 {
Expand Down
15 changes: 15 additions & 0 deletions pkg/lifecycle/sysproc_unix.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
17 changes: 17 additions & 0 deletions pkg/lifecycle/sysproc_windows.go
Original file line number Diff line number Diff line change
@@ -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
}
}
Loading