[Drbd-dev] [PATCH] drbd-utils: Remove the hardcoded local5 of logfacility

Nick Wang nwang at suse.com
Tue Nov 7 09:43:05 CET 2017


It is able to override the loglevel with --logfacility 
in crm-fence-peer.sh. However, in other scripts still 
hardcoded to "local5.info". It is confusing only redirect 
part of scripts.

Support --logfacility in notify.sh and snapshot-resync-target-lvm.sh

Signed-off-by: Nick Wang <nwang at suse.com>
CC: Lars Ellenberg <lars.ellenberg at linbit.com>
CC: Roland Kammerer <roland.kammerer at linbit.com>
CC: drbd-dev at lists.linbit.com
---
 scripts/notify.sh                     | 60 ++++++++++++++++++++++++++++-------
 scripts/snapshot-resync-target-lvm.sh | 29 +++++++++++++++--
 2 files changed, 75 insertions(+), 14 deletions(-)

diff --git a/scripts/notify.sh b/scripts/notify.sh
index c7bfb9c1..71cdbb7d 100755
--- a/scripts/notify.sh
+++ b/scripts/notify.sh
@@ -7,15 +7,54 @@
 # try to get possible output on stdout/err to syslog
 PROG=${0##*/}
 
-# Funky redirection to avoid logger feeding its own output to itself accidentally.
-# Funky double exec to avoid an intermediate sub-shell.
-# Sometimes, the sub-shell lingers around, keeps file descriptors open,
-# and logger then won't notice the main script has finished,
-# forever waiting for further input.
-# The second exec replaces the subshell, and logger will notice directly
-# when its stdin is closed once the main script exits.
-# This avoids the spurious logger processes.
-exec > >( exec 1>&- 2>&- logger -t "$PROG[$$]" -p local5.info) 2>&1
+redirect_to_logger()
+{
+	local lf=${1:-local5}
+	case $lf in
+	# do we want to exclude some?
+	auth|authpriv|cron|daemon|ftp|kern|lpr|mail|news|syslog|user|uucp|local[0-7])
+		: OK ;;
+	*)
+		echo >&2 "invalid logfacility: $lf"
+		return
+		;;
+	esac
+
+	# Funky redirection to avoid logger feeding its own output to itself accidentally.
+	# Funky double exec to avoid an intermediate sub-shell.
+	# Sometimes, the sub-shell lingers around, keeps file descriptors open,
+	# and logger then won't notice the main script has finished,
+	# forever waiting for further input.
+	# The second exec replaces the subshell, and logger will notice directly
+	# when its stdin is closed once the main script exits.
+	# This avoids the spurious logger processes.
+	exec > >( exec 1>&- 2>&- logger -t "$PROG[$$]" -p $lf.info ) 2>&1
+}
+
+if [[ $- != *x* ]]; then
+	# you may override with --logfacility below
+	redirect_to_logger local5
+fi
+
+TEMP=$(getopt -o l: --long logfacility: -- "$@")
+eval set -- "$TEMP"
+while [[ $# != 0 ]]; do
+	case $1 in
+	-l|--logfacility)
+		redirect_to_logger $2
+		shift
+		;;
+	--)
+		;;
+	*)
+		RECIPIENT=${1:-root}
+		;;
+	esac
+	shift
+done
+
+# Default to sending email to root, unless otherwise specified
+: ${RECIPIENT:=root}
 
 if [[ $DRBD_VOLUME ]]; then
 	pretty_print="$DRBD_RESOURCE/$DRBD_VOLUME (drbd$DRBD_MINOR)"
@@ -25,9 +64,6 @@ fi
 
 echo "invoked for $pretty_print"
 
-# Default to sending email to root, unless otherwise specified
-RECIPIENT=${1:-root}
-
 # check arguments specified on command line
 if [ -z "$RECIPIENT" ]; then
 	echo "You must specify a notification recipient when using this handler." >&2
diff --git a/scripts/snapshot-resync-target-lvm.sh b/scripts/snapshot-resync-target-lvm.sh
index 8eec5d13..0e6b91a8 100755
--- a/scripts/snapshot-resync-target-lvm.sh
+++ b/scripts/snapshot-resync-target-lvm.sh
@@ -21,10 +21,31 @@ if [[ -z "$DRBD_RESOURCE" || -z "$DRBD_LL_DISK" ]]; then
 fi
 
 PROG=$(basename $0)
-exec > >(exec 2>&- ; logger -t "$PROG[$$]" -p local5.info) 2>&1
+
+redirect_to_logger()
+{
+	local lf=${1:-local5}
+	case $lf in
+	# do we want to exclude some?
+	auth|authpriv|cron|daemon|ftp|kern|lpr|mail|news|syslog|user|uucp|local[0-7])
+		: OK ;;
+	*)
+		echo >&2 "invalid logfacility: $lf"
+		return
+		;;
+	esac
+
+	exec > >( exec 1>&- 2>&- logger -t "$PROG[$$]" -p $lf.info ) 2>&1
+}
+
+if [[ $- != *x* ]]; then
+	# you may override with --logfacility below
+	redirect_to_logger local5
+fi
+
 echo "invoked for $DRBD_RESOURCE/$DRBD_VOLUME (drbd$DRBD_MINOR)"
 
-TEMP=$(getopt -o p:a:nv --long percent:,additional:,disconnect-on-error,verbose -- "$@")
+TEMP=$(getopt -o p:a:l:nv --long percent:,additional:,logfacility:,disconnect-on-error,verbose -- "$@")
 
 if [ $? != 0 ]; then
 	echo "getopt failed"
@@ -88,6 +109,10 @@ while true; do
 	-v|--verbose)
 		BE_VERBOSE=1
 		;;
+	-l|--logfacility)
+		redirect_to_logger $2
+		shift
+		;;
 	--)
 		break
 		;;
-- 
2.12.0



More information about the drbd-dev mailing list