Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recovery shell: print zerrors since the last command was executed #561

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 --color=never -l "${levels}" ${since:+--since ${since}} 2>/dev/null )" ; then
echo "${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}"