From 055e3ffadca7fb5b75a8625de2005f40c888afa9 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Wed, 30 Jul 2014 17:23:52 +0200 Subject: [PATCH] Using only one cleanup function with abort switch. --- backmeupscotty | 16 +++++++--------- backmeupscotty-example | 9 +++------ 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/backmeupscotty b/backmeupscotty index 257c192..88a8739 100644 --- a/backmeupscotty +++ b/backmeupscotty @@ -111,19 +111,17 @@ function prepare { } function cleanup_abort { - scottyinfo "No cleanup_abort function was defined." -} - -function _cleanup_abort { scottyerror "Caught exit signal! Cleaning up..." - cleanup_abort + cleanup ABORT if [ $(jobs -p) ]; then scottyerror TERMinating remaining child processes... kill $(jobs -p) fi + deleteLock + exit } @@ -132,7 +130,8 @@ function prepare { } function cleanup_normal { - scottyinfo "No cleanup_normal function was defined." + cleanup + deleteLock } function printhelp { @@ -167,13 +166,12 @@ function backmeupscotty { exit 0 fi - trap _cleanup_abort EXIT + trap cleanup_abort EXIT prepare scottysync - cleanup_normal - trap deleteLock EXIT + trap cleanup_normal EXIT exit 0 } diff --git a/backmeupscotty-example b/backmeupscotty-example index 44d97cd..a028abe 100755 --- a/backmeupscotty-example +++ b/backmeupscotty-example @@ -12,14 +12,11 @@ SYNC_EXC="/gack,/gugu/*" function prepare { echo "prepare" + sleep 5 } -function cleanup_normal { - echo "cleanup" -} - -function cleanup_abort { - echo "cleanup_abort" +function cleanup { + [ -z "$1" ] && echo "normal cleanup" || echo "abort cleanup" } backmeupscotty $@ -- 2.39.5