Whamcloud - gitweb
LU-9474 tests: fix quoting in stack_trap 90/30490/9
authorQuentin Bouget <quentin.bouget@cea.fr>
Mon, 11 Dec 2017 08:42:18 +0000 (08:42 +0000)
committerOleg Drokin <oleg.drokin@intel.com>
Fri, 9 Feb 2018 05:57:41 +0000 (05:57 +0000)
stack_trap() mishandled single quotes. This patch is not the cleanest
of fixes, but it works.

(sanity-hsm is the only test suite that uses the function, for now)

Test-Parameters: trivial testlist=sanity-hsm
Signed-off-by: Quentin Bouget <quentin.bouget@cea.fr>
Change-Id: Ia43219e57079abdbfc75485105d572bbfa85caba
Reviewed-on: https://review.whamcloud.com/30490
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: James Nunez <james.a.nunez@intel.com>
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/tests/test-framework.sh

index 85756f0..6f89cc8 100755 (executable)
@@ -5310,14 +5310,21 @@ stack_trap()
        local arg="$1"
        local sigspec="$2"
 
-       local cmd="$(trap -p $sigspec)"
+       # Use "trap -p" to get the quoting right
+       local old_trap="$(trap -p "$sigspec")"
+       # Append ";" and remove the leading "trap -- '" added by "trap -p"
+       old_trap="${old_trap:+"; ${old_trap#trap -- \'}"}"
 
-       cmd="${cmd#trap -- \'}"
-       cmd="${cmd%\'*}"
-       [ -n "$cmd" ] && cmd="; $cmd"
-       cmd="${arg}$cmd"
+       # Once again, use "trap -p" to get the quoting right
+       local new_trap="$(trap -- "$arg" "$sigspec"
+                         trap -p "$sigspec"
+                         trap -- '' "$sigspec")"
 
-       trap "$cmd" $sigspec
+       # Remove the trailing "' $sigspec" part added by "trap -p" and merge
+       #
+       # The resulting string should be safe to "eval" as it is (supposedly
+       # correctly) quoted by "trap -p"
+       eval "${new_trap%\' $sigspec}${old_trap:-"' $sigspec"}"
 }
 
 error_noexit() {