When die()ing, write message to syslog.

This commit is contained in:
Darren 'Tadgy' Austin 2026-05-22 12:17:34 +01:00
commit ba8d3b3eb7

View file

@ -68,6 +68,7 @@ die() {
# $1 The text of the error message to display on stderr. # $1 The text of the error message to display on stderr.
(( DEBUG == 1 )) && printf "%s: %s: %s\\n" "$(date "+%Y%m%d %H%M%S.%N")" "die" "$1" >>"$DEBUG_FILE" (( DEBUG == 1 )) && printf "%s: %s: %s\\n" "$(date "+%Y%m%d %H%M%S.%N")" "die" "$1" >>"$DEBUG_FILE"
syslog "err" "$1"
printf "%s: %s\\n" "$NAME" "$1" >&2 printf "%s: %s\\n" "$NAME" "$1" >&2
exit 1 exit 1
} }
@ -231,7 +232,7 @@ open_fd() {
# shellcheck disable=SC1083 # 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 )) && { (( FLAGS[${1}_open-fd-fail] == 0 )) && {
syslog "error" "failed to open log file for writing: $2" syslog "err" "failed to open log file for writing: $2"
FLAGS[${1}_open-fd-fail]=1 FLAGS[${1}_open-fd-fail]=1
} }
return 1 return 1
@ -613,7 +614,7 @@ while :; do
} }
elif (( ERR != 0 )); then elif (( ERR != 0 )); then
# Unhandled error - log the issue and continue. # Unhandled error - log the issue and continue.
syslog "error" "unhandled return code from 'read': $ERR" syslog "err" "unhandled return code from 'read': $ERR"
continue continue
fi fi
@ -621,7 +622,7 @@ while :; do
# Note: We won't make this directory ourselves - as it's the base directory it should exist on the system to start with. # Note: We won't make this directory ourselves - as it's the base directory it should exist on the system to start with.
if [[ ! -e "$BASEDIR" ]]; then if [[ ! -e "$BASEDIR" ]]; then
(( FLAGS[basedir-vanished] == 0 )) && { (( FLAGS[basedir-vanished] == 0 )) && {
syslog "error" "base directory has vanished" syslog "err" "base directory has vanished"
FLAGS[basedir-vanished]=1 FLAGS[basedir-vanished]=1
} }
continue continue
@ -635,7 +636,7 @@ while :; do
# Make sure the base path is a directory. # Make sure the base path is a directory.
if ! is_dir "$BASEDIR"; then if ! is_dir "$BASEDIR"; then
(( FLAGS[basedir-notdir] == 0 )) && { (( FLAGS[basedir-notdir] == 0 )) && {
syslog "error" "base path is no longer a directory" syslog "err" "base path is no longer a directory"
FLAGS[basedir-notdir]=1 FLAGS[basedir-notdir]=1
} }
continue continue
@ -695,7 +696,7 @@ while :; do
rm -rf "${BASEDIR:?}/${LINKFILE_EXPANDED//\{\}/$SITE}" rm -rf "${BASEDIR:?}/${LINKFILE_EXPANDED//\{\}/$SITE}"
if ! ln -sfr "$FILENAME" "$BASEDIR/${LINKFILE_EXPANDED//\{\}/$SITE}"; then if ! ln -sfr "$FILENAME" "$BASEDIR/${LINKFILE_EXPANDED//\{\}/$SITE}"; then
(( FLAGS[${SITE}_fix-link] == 0 )) && { (( FLAGS[${SITE}_fix-link] == 0 )) && {
syslog "error" "failed to fix link: $BASEDIR/${LINKFILE_EXPANDED//\{\}/$SITE}" syslog "err" "failed to fix link: $BASEDIR/${LINKFILE_EXPANDED//\{\}/$SITE}"
FLAGS[${SITE}_fix-link]=1 FLAGS[${SITE}_fix-link]=1
} }
continue continue
@ -719,7 +720,7 @@ while :; do
# If in raw mode, we need a placeholder for the FDS array element as LOG_VHOST would normally be unset. # If in raw mode, we need a placeholder for the FDS array element as LOG_VHOST would normally be unset.
if (( FLAGS[raw] == 0 )); then if (( FLAGS[raw] == 0 )); then
[[ ! "$LOG_VHOST" ]] && { [[ ! "$LOG_VHOST" ]] && {
syslog "error" "empty VirtualHost site identifier" syslog "err" "empty VirtualHost site identifier"
continue continue
} }
else else
@ -772,7 +773,7 @@ while :; do
rm -rf "${BASEDIR:?}/${LINKFILE_EXPANDED//\{\}/$LOG_VHOST}" rm -rf "${BASEDIR:?}/${LINKFILE_EXPANDED//\{\}/$LOG_VHOST}"
if ! ln -sfr "$FILENAME" "$BASEDIR/${LINKFILE_EXPANDED//\{\}/$LOG_VHOST}" 2>/dev/null; then if ! ln -sfr "$FILENAME" "$BASEDIR/${LINKFILE_EXPANDED//\{\}/$LOG_VHOST}" 2>/dev/null; then
(( FLAGS[${LOG_VHOST}_create-link] == 0 )) && { (( FLAGS[${LOG_VHOST}_create-link] == 0 )) && {
syslog "error" "failed to create link: $BASEDIR/${LINKFILE_EXPANDED//\{\}/$LOG_VHOST}" syslog "err" "failed to create link: $BASEDIR/${LINKFILE_EXPANDED//\{\}/$LOG_VHOST}"
FLAGS[${LOG_VHOST}_create-link]=1 FLAGS[${LOG_VHOST}_create-link]=1
} }
continue continue