From 8202a2563b60b875abae107e9a0f145f903e841b Mon Sep 17 00:00:00 2001 From: Darren 'Tadgy' Austin Date: Sun, 17 May 2026 22:21:09 +0100 Subject: [PATCH] Work around some bugs in bash 5.2 by bouncing some data though variables. --- lumberjack | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/lumberjack b/lumberjack index 1a176a5..ba8c798 100755 --- a/lumberjack +++ b/lumberjack @@ -567,7 +567,7 @@ TEMPLATE="$2" # Main loop while :; do # Reset used variables. - unset LOG_VHOST LOG_DATA + unset LOG_VHOST LOG_DATA LINE FLAGS[timed-out]=0 # Start compression jobs if there's any in the queue. @@ -577,10 +577,7 @@ while :; do (( DEBUG == 1 )) && printf "%s: %s\\n" "$(date "+%Y%m%d %H%M%S.%N")" "enter read" >>"$DEBUG_FILE" # Read the log line, but timeout at the top of the next second if nothing is read. - # Note: The second $(...) expansion should *not* be quoted in this instance, and - # the space between $( and (( is necessary to quiet shellcheck. - # shellcheck disable=SC2046 - read -r -t "0.$(( 999999999 - 10#$(date +%N) ))" -u "$INPUTFD" $( (( FLAGS[raw] == 0 )) && printf "%s" "LOG_VHOST") LOG_DATA + read -r -t "0.$(( 999999999 - 10#$(date +%N) ))" -u "$INPUTFD" LINE ERR="$?" # If debugging, record the time of exit from read. @@ -630,6 +627,14 @@ while :; do } fi + # Extract the data from the read line. + if (( FLAGS[raw] == 0 )); then + LOG_VHOST="${LINE%% *}" + LOG_DATA="${LINE#* }" + else + LOG_DATA="$LINE" + fi + # Expand the strftime-encoded strings in the template. EXPANDED_TEMPLATE="$(printf "%($TEMPLATE)T")" @@ -741,8 +746,9 @@ while :; do # Create symlink to the currently active log file. [[ "$LINKFILE" ]] && { LINKFILE_EXPANDED="$(printf "%($LINKFILE)T")" - [[ "$(stat -L --printf="%d:%i" "$BASEDIR/${LINKFILE_EXPANDED//\{\}/$LOG_VHOST}" 2>/dev/null)" != \ - "$(stat --printf="%d:%i" "$FILENAME" 2>/dev/null)" ]] && { + STAT1="$(stat -L --printf="%d:%i" "$BASEDIR/${LINKFILE_EXPANDED//\{\}/$LOG_VHOST}" 2>/dev/null)" + STAT2="$(stat --printf="%d:%i" "$FILENAME" 2>/dev/null)" + [[ "$STAT1" != "$STAT2" ]] && { # Note: This will clobber anything that already exists with the link name. rm -rf "${BASEDIR:?}/${LINKFILE_EXPANDED//\{\}/$LOG_VHOST}" if ! ln -sfr "$FILENAME" "$BASEDIR/${LINKFILE_EXPANDED//\{\}/$LOG_VHOST}" 2>/dev/null; then