Isolate ffmpeg process group

This commit is contained in:
Thales Maciel 2026-02-06 18:55:13 -03:00
parent d124bfa24c
commit 49ef349d48
2 changed files with 5 additions and 1 deletions

View file

@ -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

View file

@ -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)