Whamcloud - gitweb
LU-9474 tests: fix quoting in stack_trap 58/34158/2
authorQuentin Bouget <quentin.bouget@cea.fr>
Fri, 1 Feb 2019 08:05:39 +0000 (00:05 -0800)
committerOleg Drokin <green@whamcloud.com>
Fri, 15 Feb 2019 01:28:40 +0000 (01:28 +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)

This patch is back-ported from the following one:
Lustre-commit: 99420a1830b89a8aba6350b095065d65107f7c0f
Lustre-change: https://review.whamcloud.com/30490

Test-Parameters: trivial testlist=sanity-hsm

Signed-off-by: Quentin Bouget <quentin.bouget@cea.fr>
Change-Id: Ia43219e57079abdbfc75485105d572bbfa85caba
Reviewed-on: https://review.whamcloud.com/34158
Tested-by: Jenkins
Reviewed-by: James Nunez <jnunez@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/tests/test-framework.sh

index 5237a05..593c123 100755 (executable)
@@ -5304,14 +5304,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() {