Audit of 9af1463
This commit is contained in:
@@ -13,13 +13,12 @@ import (
|
||||
"io"
|
||||
"log/slog"
|
||||
"os"
|
||||
"os/exec"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"g.fc.run/ai/byre/internal/mcp"
|
||||
"g.fc.run/ai/byre/internal/procgroup"
|
||||
)
|
||||
|
||||
type HookFunc func(ctx context.Context, input json.RawMessage) (map[string]any, error)
|
||||
@@ -194,7 +193,7 @@ func (e Event) Result() (Result, error) {
|
||||
}
|
||||
|
||||
type Session struct {
|
||||
cmd *exec.Cmd
|
||||
cmd *procgroup.Cmd
|
||||
stdin io.WriteCloser
|
||||
events chan Event
|
||||
done chan struct{}
|
||||
@@ -255,11 +254,10 @@ func Start(ctx context.Context, opts Options) (*Session, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s.cmd = exec.Command("claude", args...)
|
||||
s.cmd = procgroup.Command("claude", args...)
|
||||
s.cmd.Dir = opts.Cwd
|
||||
s.cmd.Stderr = os.Stderr
|
||||
s.cmd.Env = buildEnv(opts)
|
||||
s.cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
||||
|
||||
s.stdin, err = s.cmd.StdinPipe()
|
||||
if err != nil {
|
||||
@@ -514,7 +512,7 @@ func (s *Session) Close() error {
|
||||
select {
|
||||
case <-s.done:
|
||||
case <-time.After(5 * time.Second):
|
||||
syscall.Kill(-s.cmd.Process.Pid, syscall.SIGKILL)
|
||||
s.cmd.Kill()
|
||||
<-s.done
|
||||
}
|
||||
|
||||
@@ -522,7 +520,7 @@ func (s *Session) Close() error {
|
||||
}
|
||||
|
||||
func (s *Session) Kill() {
|
||||
syscall.Kill(-s.cmd.Process.Pid, syscall.SIGKILL)
|
||||
s.cmd.Kill()
|
||||
<-s.done
|
||||
s.cmd.Wait()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user