Compare commits
2 commits
417dbc80cb
...
8202a2563b
| Author | SHA1 | Date | |
|---|---|---|---|
| 8202a2563b | |||
| 31288bc429 |
1 changed files with 15 additions and 9 deletions
24
lumberjack
24
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
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue