From a3935fb0ad9afd48e4ac6bd68f79d5fb83a0238d Mon Sep 17 00:00:00 2001
From: Dean Troyer <dtroyer@gmail.com>
Date: Fri, 21 Mar 2014 13:00:32 -0500
Subject: [PATCH] Skip child process kills in stack.sh exit trap

Logs are still being cut off in certain circumstances, almost certainly
because the awk process handling the output for verbose logging to a file
dies/is killed early.

Don't kill child processes in the EXIT trap function in this specific case.

Change-Id: I89600b61d59f87e93ff959710d0169e49d2c9845
---
 stack.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/stack.sh b/stack.sh
index 6bf5bd7760..23f11fe005 100755
--- a/stack.sh
+++ b/stack.sh
@@ -595,7 +595,9 @@ trap exit_trap EXIT
 function exit_trap {
     local r=$?
     jobs=$(jobs -p)
-    if [[ -n $jobs ]]; then
+    # Only do the kill when we're logging through a process substitution,
+    # which currently is only to verbose logfile
+    if [[ -n $jobs && -n "$LOGFILE" && "$VERBOSE" == "True" ]]; then
         echo "exit_trap: cleaning up child processes"
         kill 2>&1 $jobs
     fi