Skip to content

Commit 3a8f33b

Browse files
committed
Fix Windows build: split syscall code into platform-specific files
1 parent 27c94d1 commit 3a8f33b

File tree

3 files changed

+55
-8
lines changed

3 files changed

+55
-8
lines changed

internal/terminal/process_unix.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
}

internal/terminal/terminal.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
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()

0 commit comments

Comments
 (0)