|
|
c608c9 |
From de3c26d6333a00210de8d112cdb90dc8c2e19367 Mon Sep 17 00:00:00 2001
|
|
|
c608c9 |
From: Lars Ellenberg <lars.ellenberg@linbit.com>
|
|
|
c608c9 |
Date: Mon, 22 Sep 2014 14:58:58 +0200
|
|
|
c608c9 |
Subject: [PATCH 3/6] Fix: ocf_exit_reason: implicit format string "%s" for
|
|
|
c608c9 |
single argument version
|
|
|
c608c9 |
|
|
|
c608c9 |
Also, don't use the $msg as format string, but via "%s%s" "$cookie" "$msg".
|
|
|
c608c9 |
Or, depending on presence of % sequences in $msg,
|
|
|
c608c9 |
you'd get different output on stderr and via ha_log.
|
|
|
c608c9 |
|
|
|
c608c9 |
Without the patch:
|
|
|
c608c9 |
|
|
|
c608c9 |
( OCF_ROOT=$PWD dash -c '. heartbeat/ocf-shellfuncs.in ; ocf_exit_reason "0.x% Bugs less"' )
|
|
|
c608c9 |
dash: 372: printf: % B: invalid directive
|
|
|
c608c9 |
ocf-exit-reason:0.x
|
|
|
c608c9 |
( OCF_ROOT=$PWD dash -c '. heartbeat/ocf-shellfuncs.in ; ocf_exit_reason "0.x% bugs less"' )
|
|
|
c608c9 |
ocf-exit-reason:0.xugs less
|
|
|
c608c9 |
|
|
|
c608c9 |
With this patch:
|
|
|
c608c9 |
|
|
|
c608c9 |
( OCF_ROOT=$PWD dash -c '. heartbeat/ocf-shellfuncs.in ; ocf_exit_reason "0.x% Bugs less"' )
|
|
|
c608c9 |
ocf-exit-reason:0.x% Bugs less
|
|
|
c608c9 |
( OCF_ROOT=$PWD dash -c '. heartbeat/ocf-shellfuncs.in ; ocf_exit_reason "0.x% bugs less"' )
|
|
|
c608c9 |
ocf-exit-reason:0.x% bugs less
|
|
|
c608c9 |
---
|
|
|
c608c9 |
heartbeat/ocf-shellfuncs.in | 27 +++++++++++++++++++--------
|
|
|
c608c9 |
1 file changed, 19 insertions(+), 8 deletions(-)
|
|
|
c608c9 |
|
|
|
c608c9 |
diff --git a/heartbeat/ocf-shellfuncs.in b/heartbeat/ocf-shellfuncs.in
|
|
|
c608c9 |
index 9ba8e26..c370fca 100644
|
|
|
c608c9 |
--- a/heartbeat/ocf-shellfuncs.in
|
|
|
c608c9 |
+++ b/heartbeat/ocf-shellfuncs.in
|
|
|
c608c9 |
@@ -356,22 +356,33 @@ ocf_log() {
|
|
|
c608c9 |
ocf_exit_reason()
|
|
|
c608c9 |
{
|
|
|
c608c9 |
local cookie="$OCF_EXIT_REASON_PREFIX"
|
|
|
c608c9 |
- local fmt="$1"
|
|
|
c608c9 |
+ local fmt
|
|
|
c608c9 |
local msg
|
|
|
c608c9 |
|
|
|
c608c9 |
- if [ $# -lt 1 ]; then
|
|
|
c608c9 |
- ocf_log err "Not enough arguments [$#] to ocf_log_exit_msg."
|
|
|
c608c9 |
- fi
|
|
|
c608c9 |
+ # No argument is likely not intentional.
|
|
|
c608c9 |
+ # Just one argument implies a printf format string of just "%s".
|
|
|
c608c9 |
+ # "Least surprise" in case some interpolated string from variable
|
|
|
c608c9 |
+ # expansion or other contains a percent sign.
|
|
|
c608c9 |
+ # More than one argument: first argument is going to be the format string.
|
|
|
c608c9 |
+ case $# in
|
|
|
c608c9 |
+ 0) ocf_log err "Not enough arguments to ocf_log_exit_msg." ;;
|
|
|
c608c9 |
+ 1) fmt="%s" ;;
|
|
|
c608c9 |
+
|
|
|
c608c9 |
+ *) fmt=$1
|
|
|
c608c9 |
+ shift
|
|
|
c608c9 |
+ case $fmt in
|
|
|
c608c9 |
+ *%*) : ;; # ok, does look like a format string
|
|
|
c608c9 |
+ *) ocf_log warn "Does not look like format string: [$fmt]" ;;
|
|
|
c608c9 |
+ esac ;;
|
|
|
c608c9 |
+ esac
|
|
|
c608c9 |
+
|
|
|
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 |
+ printf >&2 "%s%s\n" "$cookie" "$msg"
|
|
|
c608c9 |
__ha_log_ignore_stderr_once="true"
|
|
|
c608c9 |
ha_log "ERROR: $msg"
|
|
|
c608c9 |
}
|
|
|
c608c9 |
--
|
|
|
c608c9 |
1.8.4.2
|
|
|
c608c9 |
|