File tree Expand file tree Collapse file tree 3 files changed +55
-8
lines changed
Expand file tree Collapse file tree 3 files changed +55
-8
lines changed Original file line number Diff line number Diff line change 1+ //go:build !windows
2+
3+ package terminal
4+
5+ import (
6+ "os/exec"
7+ "syscall"
8+ )
9+
10+ // setSysProcAttr sets Unix-specific process attributes
11+ func setSysProcAttr (cmd * exec.Cmd ) {
12+ cmd .SysProcAttr = & syscall.SysProcAttr {Setpgid : true }
13+ }
14+
15+ // stopProcess sends signals to gracefully stop the process on Unix
16+ func stopProcess (cmd * exec.Cmd ) error {
17+ if cmd == nil || cmd .Process == nil {
18+ return nil
19+ }
20+
21+ // Send SIGTERM to stop process gracefully
22+ if err := cmd .Process .Signal (syscall .SIGTERM ); err != nil {
23+ // If SIGTERM fails, try SIGINT (Ctrl+C)
24+ cmd .Process .Signal (syscall .SIGINT )
25+ }
26+
27+ return nil
28+ }
Original file line number Diff line number Diff line change 1+ //go:build windows
2+
3+ package terminal
4+
5+ import (
6+ "os"
7+ "os/exec"
8+ )
9+
10+ // setSysProcAttr sets Windows-specific process attributes (no-op on Windows)
11+ func setSysProcAttr (cmd * exec.Cmd ) {
12+ // No equivalent on Windows - process groups work differently
13+ }
14+
15+ // stopProcess kills the process on Windows
16+ func stopProcess (cmd * exec.Cmd ) error {
17+ if cmd == nil || cmd .Process == nil {
18+ return nil
19+ }
20+
21+ // On Windows, just kill the process directly
22+ return cmd .Process .Signal (os .Kill )
23+ }
Original file line number Diff line number Diff line change 66 "os/exec"
77 "path/filepath"
88 "strconv"
9- "syscall"
109
1110 "github.com/kartoza/kartoza-screencaster/internal/config"
1211)
@@ -111,8 +110,8 @@ func (r *Recorder) Start(opts RecorderOptions) error {
111110 r .cmd .Stdout = os .Stdout
112111 r .cmd .Stderr = os .Stderr
113112
114- // Start in a new process group so we can signal it
115- r .cmd . SysProcAttr = & syscall. SysProcAttr { Setpgid : true }
113+ // Set platform-specific process attributes
114+ setSysProcAttr ( r .cmd )
116115
117116 if err := r .cmd .Start (); err != nil {
118117 return fmt .Errorf ("failed to start asciinema: %w" , err )
@@ -133,11 +132,8 @@ func (r *Recorder) Stop() error {
133132 return nil
134133 }
135134
136- // Send SIGTERM to stop asciinema gracefully
137- if err := r .cmd .Process .Signal (syscall .SIGTERM ); err != nil {
138- // If SIGTERM fails, try SIGINT (Ctrl+C)
139- r .cmd .Process .Signal (syscall .SIGINT )
140- }
135+ // Stop process using platform-specific method
136+ stopProcess (r .cmd )
141137
142138 // Wait for process to finish
143139 r .cmd .Wait ()
You can’t perform that action at this time.
0 commit comments