Skip to content

Commit

Permalink
Only use setpgid on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Aug 21, 2023
1 parent afb8e1a commit 6becc81
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions cmd/bbctl/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os/exec"
"os/signal"
"path/filepath"
"runtime"
"strings"
"sync"
"syscall"
Expand Down Expand Up @@ -209,9 +210,12 @@ func runBridge(ctx *cli.Context) error {
}

cmd := makeCmd(ctx.Context, bridgeDir, bridgeCmd, bridgeArgs...)
cmd.SysProcAttr = &syscall.SysProcAttr{
// Don't pass through signals to the bridge, we'll send a sigterm when we want to stop it.
Setpgid: true,
if runtime.GOOS == "linux" {
cmd.SysProcAttr = &syscall.SysProcAttr{
// Don't pass through signals to the bridge, we'll send a sigterm when we want to stop it.
// Causes weird issues on macOS, so limited to Linux.
Setpgid: true,
}
}
var as *appservice.AppService
var wg sync.WaitGroup
Expand Down Expand Up @@ -253,7 +257,8 @@ func runBridge(ctx *cli.Context) error {
as.StopWebsocket(appservice.ErrWebsocketManualStop)
}
proc := cmd.Process
if proc != nil {
// On non-Linux, assume setpgid wasn't set, so the signal will be automatically sent to both processes.
if proc != nil && runtime.GOOS == "linux" {
err := proc.Signal(syscall.SIGTERM)
if err != nil {
log.Printf("Failed to send SIGTERM to bridge: %v", err)
Expand Down

0 comments on commit 6becc81

Please sign in to comment.