Trap SIGINT, etc and release used resources
diff --git a/tools/build_pxe_boot.sh b/tools/build_pxe_boot.sh
index da8bbcc..ab64098 100755
--- a/tools/build_pxe_boot.sh
+++ b/tools/build_pxe_boot.sh
@@ -11,6 +11,22 @@
 OPWD=`pwd`
 PROGDIR=`dirname $0`
 
+# Clean up any resources that may be in use
+cleanup() {
+    set +o errexit
+
+    # Mop up temporary files
+    if [ -n "$MNTDIR" -a -d "$MNTDIR" ]; then
+        umount $MNTDIR
+        rmdir $MNTDIR
+    fi
+
+    # Kill ourselves to signal any calling process
+    trap 2; kill -2 $$
+}
+
+trap cleanup SIGHUP SIGINT SIGTERM
+
 mkdir -p $DEST_DIR/pxelinux.cfg
 cd $DEST_DIR
 for i in memdisk menu.c32 pxelinux.0; do