Cleaned up trap handling:
authorThomas Arendsen Hein <thomas@intevation.de>
Thu, 04 Aug 2005 17:43:05 +0100
changeset 831 232d0616a80ab7e21b97a74e910654e341b71df9
parent 830 ca080d28d0af34c7870fbbbd5797563d759c61f1
child 832 b65773f7db4161aaa7340ecd32d69e0dacac4d9a
push id1
push usergszorc@mozilla.com
push dateWed, 18 Mar 2015 16:34:57 +0000
Cleaned up trap handling: - Use numbers instead of signal names - No need to explicitly call "cleanup_exit RC" to exit with return code RC.
hgeditor
hgmerge
--- a/hgeditor
+++ b/hgeditor
@@ -19,21 +19,21 @@ case "${EDITOR}" in
         EDITOR="$EDITOR -f -o"
         ;;
 esac
 
 
 HGTMP=""
 cleanup_exit() {
     rm -rf "$HGTMP"
-    exit $1
 }
 
 # Remove temporary files even if we get interrupted
-trap "cleanup_exit 255" TERM KILL INT QUIT ABRT
+trap "cleanup_exit" 0 # normal exit
+trap "exit 255" 1 2 3 6 15 # HUP INT QUIT ABRT TERM
 
 HGTMP="${TMPDIR-/tmp}/hgeditor.$RANDOM.$RANDOM.$RANDOM.$$"
 (umask 077 && mkdir "$HGTMP") || {
     echo "Could not create temporary directory! Exiting." 1>&2
     exit 1
 }
 
 (
@@ -46,22 +46,22 @@ HGTMP="${TMPDIR-/tmp}/hgeditor.$RANDOM.$
 echo > "$HGTMP/msg"
 if [ "$SIGN" == "1" ]; then
     MANIFEST=`grep '^HG: manifest hash' "$1" | cut -b 19-`
     echo -e "\nmanifest hash: $MANIFEST" >> "$HGTMP/msg"
 fi
 grep -vE '^(HG: manifest hash .*)?$' "$1" >> "$HGTMP/msg"
 
 CHECKSUM=`md5sum "$HGTMP/msg"`
-$EDITOR "$HGTMP/msg" "$HGTMP/diff" || cleanup_exit $?
-echo "$CHECKSUM" | md5sum -c >/dev/null 2>&1 && cleanup_exit 13
+$EDITOR "$HGTMP/msg" "$HGTMP/diff" || exit $?
+echo "$CHECKSUM" | md5sum -c >/dev/null 2>&1 && exit 13
 
 if [ "$SIGN" == "1" ]; then
     {
         head -n 1 "$HGTMP/msg"
         echo
         grep -v "^HG:" "$HGTMP/msg" | gpg -t -a -u "${HGUSER}" --clearsign
     } > "$HGTMP/msg.gpg" && mv "$HGTMP/msg.gpg" "$1"
 else
     mv "$HGTMP/msg" "$1"
 fi
 
-cleanup_exit $?
+exit $?
--- a/hgmerge
+++ b/hgmerge
@@ -52,34 +52,34 @@ if type diff3 > /dev/null 2>&1; then
     echo "conflicts detected in $LOCAL"
     diff3 -m "$LOCAL.orig" "$BASE" "$OTHER" > "$LOCAL" || $EDITOR "$LOCAL"
     exit 0
 fi
 
 HGTMP=""
 cleanup_exit() {
     rm -rf "$HGTMP"
-    exit $1
 }
 
 # attempt to manually merge with diff and patch
 if type diff > /dev/null 2>&1 && type patch > /dev/null 2>&1; then
     # Remove temporary files even if we get interrupted
-    trap "cleanup_exit 1" TERM KILL INT QUIT ABRT
+    trap "cleanup_exit" 0 # normal exit
+    trap "exit 1" 1 2 3 6 15 # HUP INT QUIT ABRT TERM
 
     HGTMP="${TMPDIR-/tmp}/hgmerge.$RANDOM.$RANDOM.$RANDOM.$$"
     (umask 077 && mkdir "$HGTMP") || {
 	echo "Could not create temporary directory! Exiting." 1>&2
 	exit 1
     }
 
     diff -u "$BASE" "$OTHER" > "$HGTMP/diff"
     if patch "$LOCAL" < "$HGTMP/diff"; then
-	cleanup_exit 0
+	exit 0
     else
 	# If rejects are empty after using the editor, merge was ok
-	$EDITOR "$LOCAL" "$LOCAL.rej" && test -s "$LOCAL.rej" || cleanup_exit 0
+	$EDITOR "$LOCAL" "$LOCAL.rej" && test -s "$LOCAL.rej" || exit 0
     fi
-    cleanup_exit 1
+    exit 1
 fi
 
 echo "hgmerge: unable to find merge, tkdiff, kdiff3, or diff+patch!"
 exit 1