diff --git a/internal/audio/record.go b/internal/audio/record.go index cb7c65f..c65c699 100644 --- a/internal/audio/record.go +++ b/internal/audio/record.go @@ -7,6 +7,7 @@ import ( "os/exec" "path/filepath" "strings" + "syscall" "time" ) @@ -31,6 +32,8 @@ func (r Recorder) Start(ctx context.Context) (*exec.Cmd, *RecordResult, error) { args = append(args, "-ac", "1", "-ar", "16000", "-c:a", "pcm_s16le", wav) cmd := exec.CommandContext(ctx, "ffmpeg", args...) + // Put ffmpeg in its own process group so Ctrl+C only targets the daemon. + cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} if err := cmd.Start(); err != nil { _ = os.RemoveAll(tmpdir) return nil, nil, err diff --git a/internal/daemon/daemon.go b/internal/daemon/daemon.go index 4da3421..679c4f1 100644 --- a/internal/daemon/daemon.go +++ b/internal/daemon/daemon.go @@ -8,6 +8,7 @@ import ( "os/exec" "path/filepath" "sync" + "syscall" "time" "lel/internal/aiprocess" @@ -194,7 +195,7 @@ func (d *Daemon) stopAndProcess(reason string) { d.log.Printf("stopping recording (%s)", reason) if cmd.Process != nil { - _ = cmd.Process.Signal(os.Interrupt) + _ = syscall.Kill(-cmd.Process.Pid, syscall.SIGINT) } _ = audio.WaitWithTimeout(cmd, 5*time.Second)