Skip to contentSkip to conversation

Med: Improve script.sh's error reporting (RHEL6)

PATCH New Lon Hohberger 1 participant 2 messages Nov 26, 2012 – Nov 29, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Med: Improve script.sh's error reporting (RHEL6)

The script agent used primarily by rgmanager had a very minimal amount of error reporting, such that it could be very confusing as to why a script resource had failed.

This patch looks for a variety of errors from the script resource.

Resolves: rhbz#773478

---
 rgmanager/src/resources/script.sh |   57 ++++++++++++++++++++++++++++++++++--
 1 files changed, 53 insertions(+), 4 deletions(-)
rgmanager/src/resources/script.sh +53 -4
index fa07f1d..be65afc 100755
@@ -94,21 +94,70 @@ meta_data()
 EOT
 }
 
+validate_or_exit()
+{
+	if [ -z "${OCF_RESKEY_file}" ]; then
+		ocf_log err "No file provided"
+		exit $OCF_ERR_ARGS      # Invalid Argument
+	fi
+
+	if ! [ -e "${OCF_RESKEY_file}" ]; then
+		ocf_log err "${OCF_RESKEY_file} does not exist"
+		exit $OCF_ERR_INSTALLED # Program not installed
+	fi
+
+	if [ -b "${OCF_RESKEY_file}" ]; then
+		ocf_log err "${OCF_RESKEY_file} is a block device"
+		exit $OCF_ERR_ARGS      # Invalid Argument
+	fi
+
+	if [ -d "${OCF_RESKEY_file}" ]; then
+		ocf_log err "${OCF_RESKEY_file} is a directory"
+		exit $OCF_ERR_ARGS      # Invalid Argument
+	fi
+
+	if [ -c "${OCF_RESKEY_file}" ]; then
+		ocf_log err "${OCF_RESKEY_file} is a character device"
+		exit $OCF_ERR_ARGS      # Invalid Argument
+	fi
+
+	if [ -p "${OCF_RESKEY_file}" ]; then
+		ocf_log err "${OCF_RESKEY_file} is a named pipe"
+		exit $OCF_ERR_ARGS      # Invalid Argument
+	fi
+
+	if [ -S "${OCF_RESKEY_file}" ]; then
+		ocf_log err "${OCF_RESKEY_file} is a socket"
+		exit $OCF_ERR_ARGS      # Invalid Argument
+	fi
+
+	if ! [ -s "${OCF_RESKEY_file}" ]; then
+		ocf_log err "${OCF_RESKEY_file} is empty"
+		exit $OCF_ERR_GENERIC   # ???
+	fi
+
+	if ! [ -x "${OCF_RESKEY_file}" ]; then
+		ocf_log err "${OCF_RESKEY_file} is not executable"
+		exit $OCF_ERR_PERM
+	fi
+
+	return 0
+}
+
 case $1 in
 	meta-data)
 		meta_data
 		exit 0
 		;;
 	validate-all)
-		exit 0 # XXX XXX XXX
+		validate_or_exit
+		exit 0
 		;;
 	*)
 		;;
 esac
 
-[ -n "${OCF_RESKEY_file}" ] || exit $OCF_ERR_ARGS      # Invalid Argument
-[ -f "${OCF_RESKEY_file}" ] || exit $OCF_ERR_INSTALLED # Program not installed
-[ -x "${OCF_RESKEY_file}" ] || exit $OCF_ERR_GENERIC   # Generic error
+validate_or_exit
 
 # Don't need to catch return codes; this one will work.
 ocf_log info "Executing ${OCF_RESKEY_file} $1"
Signature · 1 line
1.7.7.6
#1 lore raw

PATCH 1/1 Med: Improve script.sh's error reporting (RHEL6)

Quoted 6 lines · Lon Hohberger

The script agent used primarily by rgmanager had a very minimal amount of error reporting, such that it could be very confusing as to why a script resource had failed.

This patch looks for a variety of errors from the script resource.

Replaced pull request here based on Jan's comments.

https://github.com/ClusterLabs/resource-agents/pull/183

-- Lon