Skip to content

Commit 254fab5

Browse files
committed
Fix the windows build
Signed-off-by: David Gageot <[email protected]>
1 parent 54cf0cf commit 254fab5

File tree

3 files changed

+36
-22
lines changed

3 files changed

+36
-22
lines changed

pkg/tools/builtin/cmd_unix.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//go:build !windows
2+
3+
package builtin
4+
5+
import (
6+
"os"
7+
"syscall"
8+
)
9+
10+
func platformSpecificSysProcAttr() *syscall.SysProcAttr {
11+
return &syscall.SysProcAttr{
12+
Setpgid: true,
13+
}
14+
}
15+
16+
func kill(proc *os.Process) error {
17+
return syscall.Kill(-proc.Pid, syscall.SIGTERM)
18+
}

pkg/tools/builtin/cmd_windows.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package builtin
2+
3+
import (
4+
"os"
5+
"syscall"
6+
)
7+
8+
func platformSpecificSysProcAttr() *syscall.SysProcAttr {
9+
return nil
10+
}
11+
12+
func kill(proc *os.Process) error {
13+
return proc.Kill()
14+
}

pkg/tools/builtin/shell.go

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"os/exec"
1010
"runtime"
1111
"sync"
12-
"syscall"
1312

1413
"github.com/docker/cagent/pkg/tools"
1514
)
@@ -54,11 +53,8 @@ func (h *shellHandler) RunShell(ctx context.Context, toolCall tools.ToolCall) (*
5453

5554
// Set up process group for proper cleanup
5655
// On Unix: create new process group so we can kill the entire tree
57-
if runtime.GOOS != "windows" {
58-
cmd.SysProcAttr = &syscall.SysProcAttr{
59-
Setpgid: true,
60-
}
61-
}
56+
cmd.SysProcAttr = platformSpecificSysProcAttr()
57+
6258
// Note: On Windows, we would set CreationFlags, but that requires
6359
// platform-specific code in a _windows.go file
6460

@@ -245,22 +241,8 @@ func (t *ShellTool) Stop(context.Context) error {
245241

246242
// Kill all tracked processes
247243
for _, proc := range t.handler.processes {
248-
if proc == nil {
249-
continue
250-
}
251-
252-
// On Unix: kill the entire process group
253-
// On Windows: terminate the process
254-
if runtime.GOOS == "windows" {
255-
// On Windows, we kill the process directly
256-
_ = proc.Kill()
257-
} else {
258-
// On Unix, kill the process group (negative PID kills the group)
259-
// We use SIGTERM first for graceful shutdown
260-
_ = syscall.Kill(-proc.Pid, syscall.SIGTERM)
261-
262-
// Note: We could add a timeout and send SIGKILL if processes don't stop,
263-
// but for now we'll just send SIGTERM
244+
if proc != nil {
245+
_ = kill(proc)
264246
}
265247
}
266248

0 commit comments

Comments
 (0)