diff --git a/lumberjack b/lumberjack index ba8c798..bfa7053 100755 --- a/lumberjack +++ b/lumberjack @@ -39,7 +39,7 @@ close_fd() { [[ -z "$1" ]] && return 1 # shellcheck disable=SC1083 - { exec {FDS["$1"]}>&-; } 2>/dev/null || syslog "warn" "failed to close FD ${FDS[$1]} for $1" + { exec {FDS[$1]}>&-; } 2>/dev/null || syslog "warn" "failed to close FD ${FDS[$1]} for $1" unset "FDS[$1]" "FLAGS[${1}_template-prefix]" "FLAGS[${1}_make-dir-fail]" "FLAGS[${1}_fix-link]" } @@ -221,7 +221,7 @@ open_fd() { [[ -z "$1" || -z "$2" ]] && return 1 umask "$FILE_UMASK" # shellcheck disable=SC1083 - if ! { exec {FDS["$1"]}>>"$2"; } 2>/dev/null; then + if ! { exec {FDS[$1]}>>"$2"; } 2>/dev/null; then (( FLAGS[${1}_open-fd-fail] == 0 )) && { syslog "error" "failed to open log file for writing: $2" FLAGS[${1}_open-fd-fail]=1 @@ -567,7 +567,7 @@ TEMPLATE="$2" # Main loop while :; do # Reset used variables. - unset LOG_VHOST LOG_DATA LINE + unset LOG_VHOST LOG_DATA FLAGS[timed-out]=0 # Start compression jobs if there's any in the queue. @@ -577,7 +577,10 @@ 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. - read -r -t "0.$(( 999999999 - 10#$(date +%N) ))" -u "$INPUTFD" LINE + # 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 ERR="$?" # If debugging, record the time of exit from read. @@ -627,14 +630,6 @@ 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")" @@ -746,9 +741,8 @@ while :; do # Create symlink to the currently active log file. [[ "$LINKFILE" ]] && { LINKFILE_EXPANDED="$(printf "%($LINKFILE)T")" - 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" ]] && { + [[ "$(stat -L --printf="%d:%i" "$BASEDIR/${LINKFILE_EXPANDED//\{\}/$LOG_VHOST}" 2>/dev/null)" != \ + "$(stat --printf="%d:%i" "$FILENAME" 2>/dev/null)" ]] && { # 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