aboutsummaryrefslogtreecommitdiffstats
path: root/testing/simplesnap/0002-trap-do-not-define-ECODE-at-setup.patch
diff options
context:
space:
mode:
Diffstat (limited to 'testing/simplesnap/0002-trap-do-not-define-ECODE-at-setup.patch')
-rw-r--r--testing/simplesnap/0002-trap-do-not-define-ECODE-at-setup.patch41
1 files changed, 41 insertions, 0 deletions
diff --git a/testing/simplesnap/0002-trap-do-not-define-ECODE-at-setup.patch b/testing/simplesnap/0002-trap-do-not-define-ECODE-at-setup.patch
new file mode 100644
index 0000000000..d15735afa7
--- /dev/null
+++ b/testing/simplesnap/0002-trap-do-not-define-ECODE-at-setup.patch
@@ -0,0 +1,41 @@
+From cfa251c80c31ea9b3a2993ec204061cdd4c06ef4 Mon Sep 17 00:00:00 2001
+From: Henrik Riomar <henrik.riomar@gmail.com>
+Date: Mon, 18 Jun 2018 19:26:30 +0200
+Subject: [PATCH] trap: do not define ECODE at setup
+
+We need to delay defining ECODE until we call the trap
+
+Before this change (set -x output):
++ trap 'ECODE=0; dotlockfile -u "/mypool2/simplesnap/storage01/.lock"; exit ' EXIT INT TERM
+
+After:
++ trap 'ECODE=$?; dotlockfile -u /mypool2/simplesnap/storage01/.lock; exit $ECODE' EXIT INT TERM
+---
+ simplesnap | 5 +++--
+ 1 file changed, 3 insertions(+), 2 deletions(-)
+
+diff --git a/simplesnap b/simplesnap
+index 63fc0c2..fb9c4d2 100755
+--- a/simplesnap
++++ b/simplesnap
+@@ -239,14 +239,15 @@ if [ ! -d "${MOUNTPOINT}/${HOST}" ]; then
+ fi
+
+ LOCKFILE="${MOUNTPOINT}/${HOST}/.lock"
++printf -v EVAL_SAFE_LOCKFILE '%q' "$LOCKFILE"
+
+ if [ x"$LOCKMETHOD" = x"dotlockfile" ] && ${LOCKMETHOD} -r 0 -l -p "${LOCKFILE}" ; then
+ logit "Lock obtained at ${LOCKFILE} with dotlockfile"
+- trap "ECODE=$?; dotlockfile -u \"${LOCKFILE}\"; exit $ECODE" EXIT INT TERM
++ trap 'ECODE=$?; dotlockfile -u '"${EVAL_SAFE_LOCKFILE}"'; exit $ECODE' EXIT INT TERM
+ elif [ x"$LOCKMETHOD" = x"mkdir" ]; then
+ ${LOCKMETHOD} "${LOCKFILE}" || exiterror "Could not obtain lock at ${LOCKFILE}; if $0 is not already running, rmdir that path."
+ logit "Lock obtained at ${LOCKFILE} with mkdir"
+- trap "ECODE=$?; rmdir \"${LOCKFILE}\"" EXIT INT TERM
++ trap 'ECODE=$?; rmdir '"${EVAL_SAFE_LOCKFILE}"'; exit $ECODE' EXIT INT TERM
+ else
+ exiterror "Could not obtain lock at ${LOCKFILE}; $0 likely already running."
+ fi
+--
+2.17.1
+