diff --git a/zfsbootmenu/bin/logs b/zfsbootmenu/bin/logs new file mode 120000 index 000000000..6a8efeda6 --- /dev/null +++ b/zfsbootmenu/bin/logs @@ -0,0 +1 @@ +zlogtail \ No newline at end of file diff --git a/zfsbootmenu/install-helpers.sh b/zfsbootmenu/install-helpers.sh index 9b6beaa0b..5ae325c94 100644 --- a/zfsbootmenu/install-helpers.sh +++ b/zfsbootmenu/install-helpers.sh @@ -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" diff --git a/zfsbootmenu/lib/kmsg-log-lib.sh b/zfsbootmenu/lib/kmsg-log-lib.sh index d953cf425..ba6dafe85 100755 --- a/zfsbootmenu/lib/kmsg-log-lib.sh +++ b/zfsbootmenu/lib/kmsg-log-lib.sh @@ -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 @@ -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 diff --git a/zfsbootmenu/libexec/recovery-error-printer b/zfsbootmenu/libexec/recovery-error-printer new file mode 100755 index 000000000..18446198f --- /dev/null +++ b/zfsbootmenu/libexec/recovery-error-printer @@ -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}"