Skip to content

Commit 90aae7b

Browse files
committed
Fix hijack.sh sudo() to use an array, support whitespace and behave
Overriden commands should work exactly like real commands and support whitespace and special characters exactly like the real command. I usually disable the sudo() override locally when using `set -x` to reduce trace noise considerably. The previous difference between the sudo() override and the built-in sudo() cost me couple hours twice: - WIP #897 (comment) - Merged commit 232d40a No more! Also fix the return value: 2 means SKIP. Signed-off-by: Marc Herbert <marc.herbert@intel.com>
1 parent bbcca01 commit 90aae7b

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

case-lib/hijack.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,20 +177,25 @@ SUDO_LEVEL=""
177177
# overwrite the sudo command, sudo in the script can direct using sudo command
178178
sudo()
179179
{
180+
local cmd=( "$@" )
181+
180182
func_hijack_setup_sudo_level || true
181183
local cmd
182184
case $SUDO_LEVEL in
183-
'0') cmd="$*" # as root
185+
'0') "${cmd[@]}" # as root
186+
return $?
184187
;;
185-
'1') cmd="$SUDO_CMD env 'PATH=$PATH' $*" # sudo without passwd
188+
'1') "$SUDO_CMD" env PATH="$PATH" "${cmd[@]}" # sudo without passwd
189+
return $?
186190
;;
187-
'2') cmd="echo '$SUDO_PASSWD' | $SUDO_CMD -S env 'PATH=$PATH' $*" # sudo need passwd
191+
# sudo need passwd
192+
'2') echo "$SUDO_PASSWD" | "$SUDO_CMD" --stdin env PATH="$PATH" "${cmd[@]}"
193+
return $?
188194
;;
189195
*) # without sudo permission
190196
dlogw "Need root privilege to run $*"
191-
return 2
197+
return 1
192198
esac
193-
eval "$cmd"
194199
}
195200

196201
func_hijack_setup_sudo_level()

test-case/check-ipc-flood.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ do
5050
setup_kernel_check_point
5151
dlogi "===== [$i/$loop_cnt] loop Begin ====="
5252
dlogc "sudo bash -c 'echo $lpc_loop_cnt > $ipc_flood_dfs'"
53-
sudo bash -c "'echo $lpc_loop_cnt > $ipc_flood_dfs'"
53+
sudo bash -c "echo $lpc_loop_cnt > $ipc_flood_dfs"
5454

5555
# check kernel log for each iteration to catch issues
5656
sof-kernel-log-check.sh "$KERNEL_CHECKPOINT" || die "Caught error in kernel log"

0 commit comments

Comments
 (0)