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 19, 2023
1 parent fd4d012 commit 7db746b
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
3 changes: 2 additions & 1 deletion zfsbootmenu/install-helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ 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 PROMPT_COMMAND="/libexec/recovery-error-printer"
export PS1='\[\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
17 changes: 17 additions & 0 deletions zfsbootmenu/libexec/recovery-error-printer
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/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
print_kmsg_logs "err" ${prompt_ts:+${prompt_ts}}
echo
rm "/zfsbootmenu/have_errors"
fi

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

0 comments on commit 7db746b

Please sign in to comment.