# HG changeset patch # User Alex Zeffertt # Date 1271952487 -3600 # Node ID 7668718020d60b5dfef8b799f531ffe14523c239 # Parent 3505e73ba3a0c3df493d4380acd8e87e359e96dd CA-37151: If a SIGTERM/SIGINT is received during metadata backup we should tidy up properly This means run cleanup() if the signal is received and in cleanup block the signal so that a second SIGTERM/SIGINT doesn't cause a problem. Also, in cleanup(), if we have an uninitialised vdi (e.g. because we've just created it but have not yet mkfs'd it) then we ought to delete the vdi. Signed-off-by: Alex Zeffertt diff -r 3505e73ba3a0 -r 7668718020d6 scripts/xe-backup-metadata --- a/scripts/xe-backup-metadata Thu Apr 22 17:02:43 2010 +0100 +++ b/scripts/xe-backup-metadata Thu Apr 22 17:08:07 2010 +0100 @@ -2,6 +2,8 @@ # Script which backups metadata into a VDI # Citrix Systems Inc, 2008 +trap "cleanup" TERM INT + if [ ! -e /etc/xensource-inventory ]; then echo Must run on a XenServer host. exit 1 @@ -57,11 +59,12 @@ init_fs=0 create_vdi=0 just_find_vdi=0 +fs_uninitialised=0 while getopts "hvink:u:dc" opt ; do case $opt in h) usage ;; - c) create_vdi=1 ;; - i) init_fs=1 ;; + c) create_vdi=1 ; fs_uninitialised=1 ;; + i) init_fs=1 ; fs_uninitialised=1 ;; k) history_kept=${OPTARG} ;; u) sr_uuid=${OPTARG} ;; d) leave_mounted=1 ;; @@ -92,6 +95,7 @@ mnt= function cleanup { + trap "" TERM INT cd / if [ ! -z "${mnt}" ]; then umount ${mnt} >/dev/null 2>&1 @@ -121,6 +125,9 @@ fi fi fi + if [ ${fs_uninitialised} -eq 1 -a -n "${vdi_uuid}" ] ; then + ${XE} vdi-destroy uuid=${vdi_uuid} + fi } echo Using SR: ${sr_name} @@ -174,6 +181,7 @@ ${debug} echo -n "Creating filesystem: " mkfs.ext3 -j -F ${device} > /dev/null 2>&1 ${debug} echo "done" + fs_uninitialised=0 fi ${debug} echo -n "Mounting filesystem: "