Add debugging. Don't use -b for the call to sudo.

This commit is contained in:
Darren 'Tadgy' Austin 2021-01-24 18:59:08 +00:00
commit 40902975a8

View file

@ -317,6 +317,11 @@ syslog() {
logger --id="$$" -p "$SYSLOG_FACILITY.$1" -t "$NAME" "$1: $2" 2>/dev/null logger --id="$$" -p "$SYSLOG_FACILITY.$1" -t "$NAME" "$1: $2" 2>/dev/null
} }
toggle_debug() {
(( DEBUG == 0 )) && DEBUG="1" && return
(( DEBUG == 1 )) && DEBUG="0" && return
}
# Extended globs are required. # Extended globs are required.
shopt -s extglob shopt -s extglob
@ -336,6 +341,8 @@ ORIG_ARGS=()
# Some detaults. # Some detaults.
COMPRESSOR_ARGS=( "-9" ) COMPRESSOR_ARGS=( "-9" )
COMPRESSOR="gzip" # Use gzip by default as log processing utils can often natively read gzipped files. COMPRESSOR="gzip" # Use gzip by default as log processing utils can often natively read gzipped files.
DEBUG="0"
DEBUG_FILE="/tmp/lumberjack.$$.debug.$RANDOM"
INPUT="" INPUT=""
INPUTFD="0" INPUTFD="0"
MAXJOBS="4" MAXJOBS="4"
@ -352,6 +359,7 @@ FLAGS=([flush]=0 [raw]=0 [compress]=0 [make-parents]=0 [created-fifo]=0 [timed-o
trap 'sigchld_handler' SIGCHLD trap 'sigchld_handler' SIGCHLD
trap 'sighup_handler' SIGHUP trap 'sighup_handler' SIGHUP
trap 'syslog "info" "received SIGUSR1 ping request"' SIGUSR1 trap 'syslog "info" "received SIGUSR1 ping request"' SIGUSR1
trap 'toggle_debug' SIGUSR2
trap 'sigterm_handler' SIGTERM trap 'sigterm_handler' SIGTERM
trap 'exit_handler' EXIT trap 'exit_handler' EXIT
@ -542,9 +550,9 @@ TEMPLATE="$2"
# Apply user and setting. # Apply user and setting.
[[ -n "$RUNAS_USER" ]] && { [[ -n "$RUNAS_USER" ]] && {
SUDO="$(command -v sudox)" SUDO="$(command -v sudo)"
if [[ -n "$SUDO" ]]; then if [[ -n "$SUDO" ]]; then
exec "$SUDO" -b -u "$RUNAS_USER" -- "$0" "${ORIG_ARGS[@]}" "$BASEDIR" "$TEMPLATE" || die "failed to exec to change user" exec "$SUDO" -u "$RUNAS_USER" -- "$0" "${ORIG_ARGS[@]}" "$BASEDIR" "$TEMPLATE" || die "failed to exec to change user"
else else
die "cannot exec to change user: sudo not found" die "cannot exec to change user: sudo not found"
fi fi
@ -563,6 +571,9 @@ while :; do
# Start compression jobs if there's any in the queue. # Start compression jobs if there's any in the queue.
start_compression_jobs start_compression_jobs
# If debugging is enabled, record the time of entry into the read below.
(( DEBUG == 1 )) && printf "%s - %s\n" "$(date "+%Y%m%dT%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 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 # Note: The second $(...) expansion should *not* be quoted in this instance, and
# the space between $( and (( is necessary to quiet shellcheck. # the space between $( and (( is necessary to quiet shellcheck.
@ -570,6 +581,9 @@ while :; do
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" $( (( FLAGS[raw] == 0 )) && printf "%s" "LOG_VHOST") LOG_DATA
ERR="$?" ERR="$?"
# If debugging, record the time of exit from read.
(( DEBUG == 1 )) && printf "%s - %s\n" "$(date "+%Y%m%dT%H%M%S.%N")" "Exit read, ERR = $ERR" >>"$DEBUG_FILE"
# Determine how the read above was exited. # Determine how the read above was exited.
if (( ERR > 128 )); then if (( ERR > 128 )); then
# If 'read' timed out, set a marker. # If 'read' timed out, set a marker.