From 99420a1830b89a8aba6350b095065d65107f7c0f Mon Sep 17 00:00:00 2001 From: Quentin Bouget Date: Mon, 11 Dec 2017 08:42:18 +0000 Subject: [PATCH] LU-9474 tests: fix quoting in stack_trap 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 Change-Id: Ia43219e57079abdbfc75485105d572bbfa85caba Reviewed-on: https://review.whamcloud.com/30490 Reviewed-by: Andreas Dilger Reviewed-by: James Nunez Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/tests/test-framework.sh | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lustre/tests/test-framework.sh b/lustre/tests/test-framework.sh index 85756f0f..6f89cc8 100755 --- a/lustre/tests/test-framework.sh +++ b/lustre/tests/test-framework.sh @@ -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() { -- 1.8.3.1