Skip to content

Commit 460bb0f

Browse files
authored
fix: solve windows build issue (#70)
1 parent 20fb256 commit 460bb0f

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

internal/core/services/server_service.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"os"
2222
"os/exec"
2323
"regexp"
24-
"runtime"
2524
"sort"
2625
"strconv"
2726
"strings"
@@ -222,11 +221,9 @@ func (s *serverService) StartForward(alias string, extraArgs []string) (int, err
222221
cmd.Stdin = devNull
223222
cmd.Stdout = devNull
224223
cmd.Stderr = devNull
225-
// Set SysProcAttr conditionally to avoid Windows-only build issues
224+
// Set SysProcAttr in an OS-specific way (see sysprocattr_* files)
226225
sysProcAttr := &syscall.SysProcAttr{}
227-
if runtime.GOOS != "windows" {
228-
sysProcAttr.Setsid = true
229-
}
226+
setDetach(sysProcAttr)
230227
cmd.SysProcAttr = sysProcAttr
231228

232229
if err := cmd.Start(); err != nil {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//go:build !windows
2+
3+
package services
4+
5+
import "syscall"
6+
7+
// setDetach configures SysProcAttr to detach the process on non-Windows platforms.
8+
func setDetach(attr *syscall.SysProcAttr) {
9+
// On Unix-like systems, Setsid creates a new session to fully detach.
10+
attr.Setsid = true
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//go:build windows
2+
3+
package services
4+
5+
import "syscall"
6+
7+
// setDetach is a no-op on Windows because syscall.SysProcAttr does not have Setsid.
8+
func setDetach(attr *syscall.SysProcAttr) {
9+
// No detachment tweak needed; Windows uses different process group semantics.
10+
}

0 commit comments

Comments
 (0)