[PATCH aiaiai 1/3] aiaiai-email-test-patchset: correct hook calling to actually grab error

Jacob Keller jacob.e.keller at intel.com
Mon Apr 7 15:05:16 PDT 2014


We can't grab the $? value from inside an if block, as the if statement
already changed the return code. Instead, we just call the hook script
without an error section, and then check for errors afterwards. This
corrects an issue where the return code would always be 0, even if the
command failed.

Signed-off-by: Jacob Keller <jacob.e.keller at intel.com>
---
 email/aiaiai-email-test-patchset | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/email/aiaiai-email-test-patchset b/email/aiaiai-email-test-patchset
index 037695740ad5..0a33c51bc87a 100755
--- a/email/aiaiai-email-test-patchset
+++ b/email/aiaiai-email-test-patchset
@@ -288,19 +288,22 @@ hookscript="$(readlink -ev -- $cfg_email_hook)"
 if [ -f "$hookscript" ] && [ -x "$hookscript" ]; then
 	# Hook points to an executable file, so we run it
 	verbose "Executing \"$hookscript\""
-	if ! "$hookscript" "$cfgfile" "$mbox" > "$hookoutput"; then
-		hookret=$?
 
-		# Error code 127 is an expected output of the hook, and
-		# indicates that we should reject this patch. The reply email
-		# will be sent to the user, and the hook is expected to have
-		# outputted the rejection indication. As a precaution, the
-		# rejection email will include a list of projects supported.
-		if [ "$hookret" -eq "127" ]; then
-			error_hook_rejected_patch < "$hookoutput"
-		else
-			error_internal_error_occurred
-		fi
+	# Grab the error code here, using an || section to prevent exit on
+	# command failure. Otherwise, the non-zero exit code from the hook
+	# script would crash aiaiai-email-test-patchset
+	"$hookscript" "$cfgfile" "$mbox" > "$hookoutput" || hookret=$?
+
+	# Error code 127 is an expected output of the hook, and
+	# indicates that we should reject this patch. The reply email
+	# will be sent to the user, and the hook is expected to have
+	# outputted the rejection indication. As a precaution, the
+	# rejection email will include a list of projects supported.
+	if [ "$hookret" -eq "127" ]; then
+		error_hook_rejected_patch < "$hookoutput"
+	elif [ "$hookret" -ne "0" ]; then
+		verbose "Hook exited with error code \"$hookret\"..."
+		error_internal_error_occurred
 	fi
 fi
 
-- 
1.8.3.1




More information about the aiaiai mailing list