diff options
author | Sven Gothel <[email protected]> | 2021-07-06 20:54:35 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2021-07-06 20:54:35 +0200 |
commit | 40a1e675707d56c24a76b7916a98708346b2bed8 (patch) | |
tree | 2bbb765f89c47cab1c763a79216192cbe81824eb | |
parent | 06cfa422690280e3cb3d7c40bc2a38c0a621f051 (diff) |
initrd: loop_rootfs: Resolve logging, use persistent /boot/init_rootfs.log ...
Ensure loop_rootfs log output persists across boots and hence fallback,
otherwise we can't validate the 'fallback reboot' stage.
We also need to document its actions.
This takes 'quiet' into account, i.e.
- if 'quiet' or 'log_output' via 'debug' is set: just redirect to file
- else use 'tee' to copy to console as well
Further a potential 'debug' 'log_output',
i.e. '/run/initramfs/initramfs.debug',
is made persistent (appended) to '/boot/init_debug.log'.
Since Busybox shell has no Process Substitution (Bash),
we manually create a PIPE and spawn the tee or print process.
Further `tee_date` and `add_date` is being used
to print the UTC timestamp upfront.
-rwxr-xr-x | stage2/01-sys-tweaks/files/initramfs/loop_rootfs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/stage2/01-sys-tweaks/files/initramfs/loop_rootfs b/stage2/01-sys-tweaks/files/initramfs/loop_rootfs index f52ad7d..dc8fe97 100755 --- a/stage2/01-sys-tweaks/files/initramfs/loop_rootfs +++ b/stage2/01-sys-tweaks/files/initramfs/loop_rootfs @@ -176,6 +176,18 @@ fallback_rootfs() { exit 1 } +tee_date() { + ( while IFS= read -p -r line; do + printf '%s %s\n' "$(date -u +"%Y-%m-%d %H:%M:%S")" "$line" + done ) | tee -a $1 +} + +add_date() { + ( while IFS= read -r line; do + printf '%s %s\n' "$(date -u +"%Y-%m-%d %H:%M:%S")" "$line" + done ) >> $1 +} + if [ "${ROOT}" != "file" ]; then log_begin_msg "loop_rootfs skip non file ROOT ${ROOT}" log_end_msg @@ -195,6 +207,35 @@ if ! mount ${BOOT_PART} ${BOOT_DIR}; then exit 1 fi +# Make the 'debug' output file persistent, append +if [ -f /run/initramfs/initramfs.debug ]; then + add_date ${BOOT_DIR}/init_debug.log < /run/initramfs/initramfs.debug & +fi + +quiet_orig="${quiet}" +quiet=n + +# Bash Process Substitution to redir stdout/err to tee process, +# copying to file and console: +# exec &> >(tee -a ${BOOT_DIR}/initrd.log) +# +# But we ain't no bash, do a manual pipe instead +FIFO_OUT="/run/initramfs/out.fifo" +mkfifo "${FIFO_OUT}" +trap 'rm "${FIFO_OUT}"' EXIT + +if [ "${quiet_orig}" = "y" -o -n "${log_output}" ]; then + # Originally quiet was explicitly requested, only redir to file + # and leave console quiet. + # Same for debug log_output, as it redirects output already to tmpfs file. + add_date ${BOOT_DIR}/init_rootfs.log < "${FIFO_OUT}" & + # add_date ${BOOT_DIR}/init_rootfs.log < "${FIFO_ERR}" >&2 & +else + tee_date ${BOOT_DIR}/init_rootfs.log < "${FIFO_OUT}" & + # tee_date ${BOOT_DIR}/init_rootfs.log < "${FIFO_ERR}" >&2 & +fi +exec >${FIFO_OUT} 2>&1 + if [ ! -f "${CONFIG_FILE}" ]; then panic "loop_rootfs could not find ${CONFIG_FILE}." exit 1 @@ -262,5 +303,6 @@ log_success_msg "loop_rootfs attached ${OS_PREFIX}, ${ROOTFSTYPE} file ${IMAGE_F log_end_msg +quiet="${quiet_orig}" exit 0 |