aboutsummaryrefslogtreecommitdiffstats
path: root/testing/simplesnap/0002-trap-do-not-define-ECODE-at-setup.patch
blob: d15735afa77f915697db2d171c439f2993675a88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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