bmap-flasher: act on KeyboardInterrupt
authorArtem Bityutskiy <artem.bityutskiy@intel.com>
Wed, 7 Nov 2012 09:09:17 +0000 (11:09 +0200)
committerArtem Bityutskiy <artem.bityutskiy@intel.com>
Thu, 8 Nov 2012 08:10:40 +0000 (10:10 +0200)
When one pressess Ctrl-C, the program hands for several minutes and does
not exit. The reason is that the kernel synchronized the block device on
the last close.

Let's at least print a message to the user and tell that there is no need
to worry.

Change-Id: I61368dddf697161c2a47012c5f9e2c96b74ef273
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
bmap-flasher

index 97e349b..6bec13d 100755 (executable)
@@ -119,17 +119,25 @@ def main():
                  % (args.bdev, args.bmap))
 
     try:
-        flasher.write(False, not args.no_verify)
-    except BmapFlasher.Error as err:
-        log.error(str(err))
-        raise SystemExit(1)
-
-    # Synchronize the block device
-    log.info("synchronizing block device '%s'" % args.bdev)
-    try:
-        flasher.sync()
-    except BmapFlasher.Error as err:
-        log.error(str(err))
+        try:
+            flasher.write(False, not args.no_verify)
+        except BmapFlasher.Error as err:
+            log.error(str(err))
+            raise SystemExit(1)
+
+        # Synchronize the block device
+        log.info("synchronizing block device '%s'" % args.bdev)
+        try:
+            flasher.sync()
+        except BmapFlasher.Error as err:
+            log.error(str(err))
+            raise SystemExit(1)
+    except KeyboardInterrupt:
+        log.error("the program is interrupted")
+        log.warning("do not panic if the program may not finish immediately, " \
+                    "just wait")
+        log.warning("reason: this is the Linux kernel behavior - it " \
+                    "synchronizes the block device")
         raise SystemExit(1)
 
     flashing_time = time.time() - start_time