Skip to content

Commit

Permalink
recovery shell: print zerrors since the last command was executed
Browse files Browse the repository at this point in the history
  • Loading branch information
zdykstra committed Dec 18, 2023
1 parent be37517 commit c188dc8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions zfsbootmenu/bin/logs
2 changes: 1 addition & 1 deletion zfsbootmenu/install-helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ create_zbm_profiles() {
[ -f /etc/profile ] && source /etc/profile
[ -f /lib/zfsbootmenu-completions.sh ] && source /lib/zfsbootmenu-completions.sh
export PS1="\[\033[0;33m\]zfsbootmenu\[\033[0m\] \w > "
export PS1='\$( /libexec/recovery-error-printer )\[\033[0;33m\]zfsbootmenu\[\033[0m\] \w > '
alias clear="tput clear"
alias reset="tput reset"
Expand Down
12 changes: 8 additions & 4 deletions zfsbootmenu/lib/kmsg-log-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ zerror() {
}

# arg1: comma-separated log levels to print
# arg2: optional date that messages must be timestamped after
# prints: all logs at that level
# returns: nothing

Expand All @@ -98,14 +99,17 @@ print_kmsg_logs() {
return
fi

# Try to use feature flags found in dmesg from util-linux
if output="$( dmesg --notime -f user --color=always -l "${levels}" 2>/dev/null )" ; then
echo -e "${output}"
since="${2}"

# dmesg from dmesg-util can helpfully do --since, but only if it's also allowed to print the time out
# so always print the time, optionally set --since, and filter the timestamp after
if output="$( dmesg -f user -l "${levels}" ${since:+--since ${since}} 2>/dev/null )" ; then
echo -e "${output}" | sed 's/^\[.*\]\ //'
else
# Both util-linux and Busybox dmesg support the -r flag. However, the log level that is
# reported by Busybox dmesg is larger than that reported by util-linux dmesg. Busybox dmesg
# is too bare-bones to do much of anything, so we just need to grep for both integers at
# a given log level, then refly on matching ZFSBootMenu for info and lower, and ZBM for debug.
# a given log level, then rely on matching ZFSBootMenu for info and lower, and ZBM for debug.

IFS=',' read -r -a levels_array <<<"${levels}"
for level in "${levels_array[@]}"; do
Expand Down
18 changes: 18 additions & 0 deletions zfsbootmenu/libexec/recovery-error-printer
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

PROMPT_TS_FILE="${BASE}/errors_since"

[ -f "${PROMPT_TS_FILE}" ] && read -r prompt_ts < "${PROMPT_TS_FILE}"

# shellcheck disable=SC1091
source /lib/kmsg-log-lib.sh || exit 0

if [ -f "${BASE}/have_errors" ]; then
echo -e -n "\n"
print_kmsg_logs "err" ${prompt_ts:+${prompt_ts}}
# trailing newlines are eaten by the prompt, so add a no-op carriage return
echo -n -e "\n\r"
rm "/zfsbootmenu/have_errors"
fi

printf '%(%Y-%m-%dT%H:%M:%S)T' > "${PROMPT_TS_FILE}"

0 comments on commit c188dc8

Please sign in to comment.