From 30976f60fa42972597290b0812f24f9b6f74f4d8 Mon Sep 17 00:00:00 2001 From: KemoNine Date: Thu, 3 Sep 2020 01:04:08 -0400 Subject: [PATCH] Tweak fim kill approach so ALL sub-processes are also killed (this is really important since it's a bash script presently) --- ui/slideshow.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ui/slideshow.go b/ui/slideshow.go index 0bdd4e6..ba5e7db 100644 --- a/ui/slideshow.go +++ b/ui/slideshow.go @@ -5,6 +5,7 @@ import ( "io" "log" "os/exec" + "syscall" "time" "github.com/eiannone/keyboard" @@ -21,6 +22,8 @@ func Slideshow() { // Run slideshow 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 stdin, err := fim.StdinPipe() @@ -79,9 +82,13 @@ func Slideshow() { // Exit fim and move to the config UI 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 err := fim.Process.Kill(); err != nil { - log.Fatalf("failed to kill fim : %s", err) + 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) + } } + } break }