Tweak fim kill approach so ALL sub-processes are also killed (this is really important since it's a bash script presently)
Some checks failed
continuous-integration/drone/tag Build is failing
Some checks failed
continuous-integration/drone/tag Build is failing
This commit is contained in:
parent
8b3827220e
commit
30976f60fa
|
@ -5,6 +5,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/eiannone/keyboard"
|
"github.com/eiannone/keyboard"
|
||||||
|
@ -21,6 +22,8 @@ func Slideshow() {
|
||||||
|
|
||||||
// Run slideshow
|
// Run slideshow
|
||||||
fim = exec.Command(CMD_FIM)
|
fim = exec.Command(CMD_FIM)
|
||||||
|
// Put fim into a process group so ALL processes that may be executed are exited when main process exits
|
||||||
|
fim.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
||||||
|
|
||||||
// Setup stdin for fim to control slideshow
|
// Setup stdin for fim to control slideshow
|
||||||
stdin, err := fim.StdinPipe()
|
stdin, err := fim.StdinPipe()
|
||||||
|
@ -79,10 +82,14 @@ func Slideshow() {
|
||||||
// Exit fim and move to the config UI
|
// Exit fim and move to the config UI
|
||||||
if event.Key == keyboard.KeyEsc || event.Key == keyboard.KeyEnter || event.Key == keyboard.KeySpace {
|
if event.Key == keyboard.KeyEsc || event.Key == keyboard.KeyEnter || event.Key == keyboard.KeySpace {
|
||||||
if fim != nil { // Just in case someone lays on exit key or similar during startup
|
if fim != nil { // Just in case someone lays on exit key or similar during startup
|
||||||
if err := fim.Process.Kill(); err != nil {
|
pgid, err := syscall.Getpgid(fim.Process.Pid)
|
||||||
|
if err == nil {
|
||||||
|
if err := syscall.Kill(-pgid, 9); err != nil {
|
||||||
log.Fatalf("failed to kill fim : %s", err)
|
log.Fatalf("failed to kill fim : %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue