Put child processes in their own session
The core can be gracefully shutdown by sending a SIGINT to its process. However, this signal is also propagated to all child processes, i.e. the forked ffmpeg processes. They will also be stopped and might reconnect. This is not wanted. The core has to stop these processes. The child process will now get their own session ID with setsid() before replacing themselves with ffmpeg. This way they will not receive a SIGINT that was meant only for the parent.
This commit is contained in:
parent
3af049785c
commit
88605a1f1e
1
internal/.gitignore
vendored
1
internal/.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
testhelper/ignoresigint/ignoresigint
|
||||
testhelper/sigint/sigint
|
||||
testhelper/sigintwait/sigintwait
|
||||
testhelper/sigpropagate/sigpropagate
|
||||
testhelper/ffmpeg/ffmpeg
|
||||
47
internal/testhelper/sigpropagate/sigpropagate.go
Normal file
47
internal/testhelper/sigpropagate/sigpropagate.go
Normal file
@ -0,0 +1,47 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) == 1 {
|
||||
cmd := exec.Command(os.Args[0], "x")
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
|
||||
stdout, _ := cmd.StdoutPipe()
|
||||
cmd.Start()
|
||||
|
||||
go func() {
|
||||
io.Copy(os.Stdout, stdout)
|
||||
}()
|
||||
}
|
||||
|
||||
sigcount := 0
|
||||
|
||||
// Wait for interrupt signal to gracefully shutdown the app
|
||||
quit := make(chan os.Signal, 1)
|
||||
signal.Notify(quit, os.Interrupt)
|
||||
|
||||
ticker := time.NewTicker(time.Second)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-quit:
|
||||
fmt.Printf("[%d] got SIGINT\n", os.Getpid())
|
||||
sigcount++
|
||||
|
||||
if sigcount > 5 {
|
||||
return
|
||||
}
|
||||
case <-ticker.C:
|
||||
fmt.Printf("[%d] hello\n", os.Getpid())
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -564,6 +564,7 @@ func (p *process) start() error {
|
||||
}
|
||||
|
||||
p.cmd = exec.Command(p.binary, args...)
|
||||
p.cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
|
||||
p.cmd.Env = []string{}
|
||||
|
||||
p.stdout, err = p.cmd.StderrPipe()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user