Skip to contentSkip to conversation

master - sigint: improve logic on for sigint reaction

PATCH Zdenek Kabelac 1 participant 1 message Jul 3, 2013

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6f335ffa35552ed9d002d8a6884c707b2942750c
Commit:        6f335ffa35552ed9d002d8a6884c707b2942750c
Parent:        ffa11ed35688243a4546d4a35a97fc0339916651
Author:        Zdenek Kabelac <[email protected]>
AuthorDate:    Mon Jul 1 16:30:12 2013 +0200
Committer:     Zdenek Kabelac <[email protected]>
CommitterDate: Wed Jul 3 14:46:42 2013 +0200

sigint: improve logic on for sigint reaction

Fix and improve handling on sigint.

Always check for signal presence *before* calling of command, so it will not call the command when break was hit.

If the command has been finished succesfully there is no problem to mark the command ok and not report interrupt at all.

Fix cuple related stack; reports and assignments.

---
 WHATS_NEW               |    1 +
 lib/cache/lvmetad.c     |    8 ++-
 lib/locking/locking.c   |    3 +
 lib/metadata/lv_manip.c |    2 +-
 tools/lvchange.c        |    4 +-
 tools/pvcreate.c        |    6 +-
 tools/pvscan.c          |   18 +++++--
 tools/toollib.c         |  126 ++++++++++++++++++++++++-----------------------
 8 files changed, 91 insertions(+), 77 deletions(-)
WHATS_NEW +1 -0
index f1f9a82..adecd63 100644
@@ -1,5 +1,6 @@
 Version 2.02.99 - 
 ===================================
+  Improve error loging when user tries to interrupt commands.
   Rename _swap_lv to _swap_lv_identifiers and move to allow an additional user.
   Rename snapshot segment returning methods from find_*_cow to find_*_snapshot.
   liblvm/python API: Additions: PV create/removal/resize/listing
lib/cache/lvmetad.c +5 -3
index a107047..f43283f 100644
@@ -955,11 +955,13 @@ int lvmetad_pvscan_all_devs(struct cmd_context *cmd, activation_handler handler)
 	init_silent(1);
 
 	while ((dev = dev_iter_get(iter))) {
-		if (!lvmetad_pvscan_single(cmd, dev, handler))
+		if (sigint_caught()) {
 			r = 0;
-
-		if (sigint_caught())
+			stack;
 			break;
+		}
+		if (!lvmetad_pvscan_single(cmd, dev, handler))
+			r = 0;
 	}
 
 	init_silent(was_silent);
lib/locking/locking.c +3 -0
index cdd6ac4..34e8bd9 100644
@@ -54,6 +54,9 @@ static void _catch_sigint(int unused __attribute__((unused)))
 }
 
 int sigint_caught(void) {
+	if (_sigint_caught)
+		log_error("Interrupted...");
+
 	return _sigint_caught;
 }
 
lib/metadata/lv_manip.c +1 -1
index 4c3beb0..b7914dd 100644
@@ -3252,7 +3252,7 @@ static int _request_confirmation(struct cmd_context *cmd,
 			return 0;
 		}
 		if (sigint_caught())
-			return 0;
+			return_0;
 	}
 
 	return 1;
tools/lvchange.c +2 -2
index 4b88a51..f7ce7fd 100644
@@ -347,7 +347,7 @@ static int lvchange_resync(struct cmd_context *cmd, struct logical_volume *lv)
 			}
 
 			if (sigint_caught())
-				return 0;
+				return_0;
 
 			active = 1;
 		}
@@ -643,7 +643,7 @@ static int lvchange_persistent(struct cmd_context *cmd,
 		}
 
 		if (sigint_caught())
-			return 0;
+			return_0;
 
 		log_verbose("Ensuring %s is inactive.", lv->name);
 		if (!deactivate_lv(cmd, lv)) {
tools/pvcreate.c +3 -3
index d2de4d9..b18e400 100644
@@ -108,14 +108,14 @@ int pvcreate(struct cmd_context *cmd, int argc, char **argv)
 	}
 
 	for (i = 0; i < argc; i++) {
+		if (sigint_caught())
+			return_ECMD_FAILED;
+
 		dm_unescape_colons_and_at_signs(argv[i], NULL, NULL);
 
 		if (ECMD_PROCESSED != pvcreate_locked(cmd, argv[i], &pp)) {
 			ret = ECMD_FAILED;
 		}
-
-		if (sigint_caught())
-			return ret;
 	}
 
 	return ret;
tools/pvscan.c +12 -6
index 665e416..63dc524 100644
@@ -193,13 +193,16 @@ static int _pvscan_lvmetad(struct cmd_context *cmd, int argc, char **argv)
 			ret = ECMD_FAILED;
 			continue;
 		}
-
-		if (!lvmetad_pvscan_single(cmd, dev, handler)) {
+		if (sigint_caught()) {
 			ret = ECMD_FAILED;
+			stack;
 			break;
 		}
-		if (sigint_caught())
+		if (!lvmetad_pvscan_single(cmd, dev, handler)) {
+			ret = ECMD_FAILED;
+			stack;
 			break;
+		}
 	}
 
 	if (!devno_args)
@@ -232,14 +235,17 @@ static int _pvscan_lvmetad(struct cmd_context *cmd, int argc, char **argv)
 				dm_free(buf);
 			continue;
 		}
-
+		if (sigint_caught()) {
+			ret = ECMD_FAILED;
+			stack;
+			break;
+		}
 		if (!lvmetad_pvscan_single(cmd, dev, handler)) {
 			ret = ECMD_FAILED;
+			stack;
 			break;
 		}
 
-		if (sigint_caught())
-			break;
 	}
 
 out:
tools/toollib.c +64 -62

291 lines not on this page · raw message