diff --git a/internal/core/services/server_service.go b/internal/core/services/server_service.go index 20c0fae..7926bc6 100644 --- a/internal/core/services/server_service.go +++ b/internal/core/services/server_service.go @@ -21,7 +21,6 @@ import ( "os" "os/exec" "regexp" - "runtime" "sort" "strconv" "strings" @@ -222,11 +221,9 @@ func (s *serverService) StartForward(alias string, extraArgs []string) (int, err cmd.Stdin = devNull cmd.Stdout = devNull cmd.Stderr = devNull - // Set SysProcAttr conditionally to avoid Windows-only build issues + // Set SysProcAttr in an OS-specific way (see sysprocattr_* files) sysProcAttr := &syscall.SysProcAttr{} - if runtime.GOOS != "windows" { - sysProcAttr.Setsid = true - } + setDetach(sysProcAttr) cmd.SysProcAttr = sysProcAttr if err := cmd.Start(); err != nil { diff --git a/internal/core/services/sysprocattr_unix.go b/internal/core/services/sysprocattr_unix.go new file mode 100644 index 0000000..370411a --- /dev/null +++ b/internal/core/services/sysprocattr_unix.go @@ -0,0 +1,11 @@ +//go:build !windows + +package services + +import "syscall" + +// setDetach configures SysProcAttr to detach the process on non-Windows platforms. +func setDetach(attr *syscall.SysProcAttr) { + // On Unix-like systems, Setsid creates a new session to fully detach. + attr.Setsid = true +} diff --git a/internal/core/services/sysprocattr_windows.go b/internal/core/services/sysprocattr_windows.go new file mode 100644 index 0000000..4355f37 --- /dev/null +++ b/internal/core/services/sysprocattr_windows.go @@ -0,0 +1,10 @@ +//go:build windows + +package services + +import "syscall" + +// setDetach is a no-op on Windows because syscall.SysProcAttr does not have Setsid. +func setDetach(attr *syscall.SysProcAttr) { + // No detachment tweak needed; Windows uses different process group semantics. +}