From f4b51b0706180d7e63715d7ea48f28aef300e44c Mon Sep 17 00:00:00 2001 From: Raphael Ludwig Date: Sun, 13 Feb 2022 23:06:21 +0100 Subject: [PATCH] Collect signals of child processes Add logging if starting of a process was not successful --- tools.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/tools.go b/tools.go index a817198..7a29af7 100644 --- a/tools.go +++ b/tools.go @@ -579,11 +579,19 @@ func launch(command string, terminal bool) { msg := fmt.Sprintf("env vars: %s; command: '%s'; args: %s\n", envVars, elements[cmdIdx], elements[1+cmdIdx:]) log.Info(msg) - cmd.SysProcAttr = &syscall.SysProcAttr { + cmd.SysProcAttr = &syscall.SysProcAttr{ Setsid: true, } - cmd.Start() + if cmd.Start() != nil { + log.Warn("Unable to launch terminal emulator!") + } else { + // Collect the exit code of the child process to prevent zombies + // if the drawer runs in resident mode + go func() { + _ = cmd.Wait() + }() + } if *resident { restoreStateAndHide() @@ -609,7 +617,15 @@ func open(filePath string, xdgOpen bool) { } log.Infof("Executing: %s", cmd) - cmd.Start() + if cmd.Start() != nil { + log.Warn("Unable to execute command!") + } else { + // Collect the exit code of the child process to prevent zombies + // if the drawer runs in resident mode + go func() { + _ = cmd.Wait() + }() + } if *resident { restoreStateAndHide()