[Libguestfs] [PATCH 1/3] Fix RHEV cleanup on unclean shutdown

Matthew Booth mbooth at redhat.com
Tue Jun 8 14:55:48 UTC 2010


Cleanup was not happening properly if a migration to RHEV was killed
prematurely with a Ctrl-C. Firstly, the SIGINT and SIGQUIT handlers were not
being registered early enough in virt-v2v.pl. Secondly, if Ctrl-C killed the
guestfs qemu process first it would deliver a SIGPIPE to v2v, which caused an
unclean shutdown without cleanup.

Fixes RHBZ#596015
---
 v2v/virt-v2v.pl |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/v2v/virt-v2v.pl b/v2v/virt-v2v.pl
index bed69a0..36297ed 100755
--- a/v2v/virt-v2v.pl
+++ b/v2v/virt-v2v.pl
@@ -214,6 +214,14 @@ Display version number and exit.
 
 =cut
 
+$SIG{'INT'} = \&signal_exit;
+$SIG{'QUIT'} = \&signal_exit;
+
+# SIGPIPE will cause an untidy exit of the perl process, without calling
+# destructors. We don't rely on it anywhere, as we check for errors when reading
+# from or writing to a pipe.
+$SIG{'PIPE'} = 'IGNORE';
+
 # Initialise the message output prefix
 Sys::VirtV2V::UserMessage->set_identifier('virt-v2v');
 
@@ -362,9 +370,6 @@ if ($output_method eq 'rhev') {
     $> = "0";
 }
 
-$SIG{'INT'} = \&close_guest_handle;
-$SIG{'QUIT'} = \&close_guest_handle;
-
 # Inspect the guest
 my $os = inspect_guest($g);
 
@@ -425,6 +430,12 @@ sub close_guest_handle
     }
 }
 
+sub signal_exit
+{
+    close_guest_handle();
+    exit(1);
+}
+
 sub get_guestfs_handle
 {
     my ($storage, $transferiso) = @_;
-- 
1.7.0.1




More information about the Libguestfs mailing list