Skip to content

Commit

Permalink
Improve DEBUG and DO_WITH_DEBUG output handling to also keep output o…
Browse files Browse the repository at this point in the history
…f kexec -l when BOARD is in DEBUG+TRACE mode (configuration settings menu + flash)

Signed-off-by: Thierry Laurion <[email protected]>
  • Loading branch information
tlaurion committed Apr 18, 2024
1 parent c52fd04 commit fa70cba
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion initrd/bin/kexec-boot
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ if [ "$dryrun" = "y" ]; then exit 0; fi

echo "Loading the new kernel:"
echo "$kexeccmd"
eval "$kexeccmd" \
DO_WITH_DEBUG "$kexeccmd" \
|| die "Failed to load the new kernel"

if [ "$CONFIG_DEBUG_OUTPUT" = "y" ];then
Expand Down
3 changes: 2 additions & 1 deletion initrd/bin/kexec-insert-key
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ if [ "$unseal_failed" = "y" ]; then
-n 1 \
-p "Do you wish to boot and use the LUKS Disk Recovery Key? [Y/n] " \
confirm_boot

echo

if [ "$confirm_boot" != 'y' \
-a "$confirm_boot" != 'Y' \
-a -n "$confirm_boot" ] \
Expand Down
2 changes: 1 addition & 1 deletion initrd/etc/ash_functions
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ warn() {
DEBUG() {
if [ "$CONFIG_DEBUG_OUTPUT" = "y" ]; then
# fold -s -w 960 will wrap lines at 960 characters on the last space before the limit
echo "DEBUG: $*" | fold -s -w 960 | while read line; do
printf "DEBUG: %s\n" "$@" | fold -s -w 960 | while IFS= read -r line; do
echo "$line" | tee -a /tmp/debug.log /dev/kmsg >/dev/null
done
fi
Expand Down
30 changes: 20 additions & 10 deletions initrd/etc/functions
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,28 @@ mask_param() {
# N=0 is the name of the command to be executed, N=1 is its first parameter,
# etc.
DO_WITH_DEBUG() {
if [ "$1" == "--mask-position" ]; then
mask_position="$2"
local exit_status
local cmd_output
DEBUG "PATH: $PATH"
local cmd=("$@")
if [[ "$1" == "--mask-position" ]]; then
local mask_position="$2"
shift
shift
DEBUG_ARGS=("$@")

DEBUG_ARGS[$mask_position]="$(mask_param "${DEBUG_ARGS[$mask_position]}")"
DEBUG "${DEBUG_ARGS[@]}"
else
DEBUG "$@"
cmd=("$@")
cmd[$mask_position]="$(mask_param "${cmd[$mask_position]}")"
fi
if [[ ${#cmd[@]} -eq 1 ]]; then
# If there's only one argument, try to split it into multiple arguments
read -a cmd <<< "${cmd[0]}"
fi
"$@"
DEBUG "Executing command with cmd: ${cmd[*]}"
# Sanitize the command output by removing special characters
cmd_output=$("${cmd[@]}" 2>&1 | sed 's/[&;|`$(){}<>]//g')
exit_status=$?
DEBUG "Command output: $cmd_output"
DEBUG "Command exited with status: $exit_status"
return $exit_status
}

# Trace the current script and function.
Expand Down Expand Up @@ -682,7 +692,7 @@ scan_boot_options() {

if [ -r $option_file ]; then rm $option_file; fi
for i in $(find $bootdir -name "$config"); do
DO_WITH_DEBUG kexec-parse-boot "$bootdir" "$i" >>$option_file
kexec-parse-boot "$bootdir" "$i" >>$option_file
done
# FC29/30+ may use BLS format grub config files
# https://fedoraproject.org/wiki/Changes/BootLoaderSpecByDefault
Expand Down

0 comments on commit fa70cba

Please sign in to comment.