Blame SOURCES/bz1128933-introducing-exit-reason-support.patch

c608c9
From 0dfe07cbd9e74e0f7f3c85a42085972bf24e1d24 Mon Sep 17 00:00:00 2001
c608c9
From: David Vossel <dvossel@redhat.com>
c608c9
Date: Fri, 15 Aug 2014 10:50:06 -0500
c608c9
Subject: [PATCH] Introducing exit reason string support
c608c9
c608c9
---
c608c9
 heartbeat/ocf-shellfuncs.in | 48 ++++++++++++++++++++++++++++++++++++++++++++-
c608c9
 1 file changed, 47 insertions(+), 1 deletion(-)
c608c9
c608c9
diff --git a/heartbeat/ocf-shellfuncs.in b/heartbeat/ocf-shellfuncs.in
c608c9
index 254da57..ff7c32d 100644
c608c9
--- a/heartbeat/ocf-shellfuncs.in
c608c9
+++ b/heartbeat/ocf-shellfuncs.in
c608c9
@@ -43,6 +43,14 @@ unset LANGUAGE; export LANGUAGE
c608c9
 
c608c9
 __SCRIPT_NAME=`basename $0`
c608c9
 
c608c9
+# This is internal to shellfuncs.
c608c9
+# When set, ha_log can be used in a way that guarantees
c608c9
+# that stderr will not be printed to. This allows us to
c608c9
+# use ocf_exit_reason to print a string to stderr and use
c608c9
+# ha_log to print the same string to the other log facilities
c608c9
+# without having duplicate messages sent to stderr.
c608c9
+__ha_log_ignore_stderr_once=""
c608c9
+
c608c9
 if [ -z "$OCF_ROOT" ]; then
c608c9
     : ${OCF_ROOT=@OCF_ROOT_DIR@}
c608c9
 fi
c608c9
@@ -182,12 +190,20 @@ set_logtag() {
c608c9
 }
c608c9
 
c608c9
 ha_log() {
c608c9
+	local ignore_stderr="$__ha_log_ignore_stderr_once"
c608c9
 	local loglevel
c608c9
+
c608c9
+	# always reset this variable
c608c9
+	__ha_log_ignore_stderr_once=""
c608c9
+
c608c9
 	[ none = "$HA_LOGFACILITY" ] && HA_LOGFACILITY=""
c608c9
 	# if we're connected to a tty, then output to stderr
c608c9
 	if tty >/dev/null; then
c608c9
 		if [ "x$HA_debug" = "x0" -a "x$loglevel" = xdebug ] ; then
c608c9
 			return 0
c608c9
+		elif [ "$ignore_stderr" = "true" ]; then
c608c9
+			# something already printed this error to stderr, so ignore
c608c9
+			return 0
c608c9
 		fi
c608c9
 		if [ "$HA_LOGTAG" ]; then
c608c9
 			echo "$HA_LOGTAG: $*"
c608c9
@@ -226,7 +242,7 @@ ha_log() {
c608c9
 	  echo "$HA_LOGTAG:	"`hadate`"${*}" >> $HA_LOGFILE
c608c9
 	fi
c608c9
 	if
c608c9
-	  [ -z "$HA_LOGFACILITY" -a -z "$HA_LOGFILE" ]
c608c9
+	  [ -z "$HA_LOGFACILITY" -a -z "$HA_LOGFILE" ] && ! [ "$ignore_stderr" = "true" ]
c608c9
 	then
c608c9
 	  : appending to stderr
c608c9
 	  echo `hadate`"${*}" >&2
c608c9
@@ -331,6 +347,36 @@ ocf_log() {
c608c9
 }
c608c9
 
c608c9
 #
c608c9
+# ocf_exit_reason: print exit error string to stderr
c608c9
+# Usage:           Allows the OCF script to provide a string
c608c9
+#                  describing why the exit code was returned.
c608c9
+# Arguments:   reason - required, The string that represents why the error
c608c9
+#                       occured.
c608c9
+#
c608c9
+ocf_exit_reason()
c608c9
+{
c608c9
+	local cookie="$OCF_EXIT_REASON_PREFIX"
c608c9
+	local fmt=$1
c608c9
+	local msg
c608c9
+
c608c9
+	if [ $# -lt 1 ]; then
c608c9
+		ocf_log err "Not enough arguments [$#] to ocf_log_exit_msg."
c608c9
+	fi
c608c9
+	if [ -z "$cookie" ]; then
c608c9
+		# use a default prefix
c608c9
+		cookie="ocf-exit-reason:"
c608c9
+	fi
c608c9
+
c608c9
+	shift
c608c9
+
c608c9
+	msg=$(printf "${fmt}" "$@")
c608c9
+
c608c9
+	printf >&2 "%s${msg}\n" "$cookie"
c608c9
+	__ha_log_ignore_stderr_once="true"
c608c9
+	ha_log "ERROR: $msg"
c608c9
+}
c608c9
+
c608c9
+#
c608c9
 # ocf_deprecated: Log a deprecation warning
c608c9
 # Usage:          ocf_deprecated [param-name]
c608c9
 # Arguments:      param-name optional, name of a boolean resource
c608c9
-- 
c608c9
1.8.4.2
c608c9