From a16523a72fa3ea9ef2e6cdb3edad7138b4b3eda8 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 21 Apr 2011 12:03:32 +0200 Subject: [PATCH] begin to add code to kill subprocesses on exit Signed-off-by: Nico Schottelius --- bin/cdist-mass-deploy | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bin/cdist-mass-deploy b/bin/cdist-mass-deploy index defbf109..3ca43d43 100755 --- a/bin/cdist-mass-deploy +++ b/bin/cdist-mass-deploy @@ -25,6 +25,23 @@ [ $# -ge 1 ] || __cdist_usage "[-p] [target host ]" set -u +# trap __cdist_tmp_removal EXIT +trap killandclean EXIT + +killandclean() +{ + # i may have been altered outside, just use the current offset + while [ "$i" -gt 0 ]; do + eval pid=\$pid_$i + kill "$pid" + i=$((i-1)) + done + + # Ensure tmp stuff is being removed + __cdist_tmp_removal +} + + filter() { awk -v host=$1 '{ print "[" host "] " $0 }'