[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[lvm-devel] [PATCH] Optionally abort on internal errors.



Hi,

a fairly straightforward patch adding a configure option that will
abort() the process in case it encounters an internal
error. Undocumented so far and not sure it's appropriate to expose --
but maybe we have a policy of no undocumented options?

Anyway, patch attached. (It also makes the testsuite set this option, so
it'll catch any internal errors that may happen during the tests.)

Yours,
    Petr.

Index: lib/commands/toolcontext.c
===================================================================
RCS file: /cvs/lvm2/LVM2/lib/commands/toolcontext.c,v
retrieving revision 1.86
diff -u -p -r1.86 toolcontext.c
--- lib/commands/toolcontext.c	16 Oct 2009 17:41:50 -0000	1.86
+++ lib/commands/toolcontext.c	29 Nov 2009 19:23:14 -0000
@@ -147,7 +147,9 @@ static void _init_logging(struct cmd_con
 
 	/* Log message formatting */
 	init_indent(find_config_tree_int(cmd, "log/indent",
-				    DEFAULT_INDENT));
+					 DEFAULT_INDENT));
+	init_abort_on_internal_errors(find_config_tree_int(cmd, "log/abort_on_internal_errors",
+							   DEFAULT_ABORT_ON_INTERNAL_ERRORS));
 
 	cmd->default_settings.msg_prefix = find_config_tree_str(cmd,
 							   "log/prefix",
Index: lib/config/defaults.h
===================================================================
RCS file: /cvs/lvm2/LVM2/lib/config/defaults.h,v
retrieving revision 1.53
diff -u -p -r1.53 defaults.h
--- lib/config/defaults.h	5 Oct 2009 12:44:21 -0000	1.53
+++ lib/config/defaults.h	29 Nov 2009 19:23:14 -0000
@@ -84,6 +84,7 @@
 #define DEFAULT_VERBOSE 0
 #define DEFAULT_LOGLEVEL 0
 #define DEFAULT_INDENT 1
+#define DEFAULT_ABORT_ON_INTERNAL_ERRORS 0
 #define DEFAULT_UNITS "h"
 #define DEFAULT_SUFFIX 1
 #define DEFAULT_HOSTTAGS 0
Index: lib/log/log.c
===================================================================
RCS file: /cvs/lvm2/LVM2/lib/log/log.c,v
retrieving revision 1.52
diff -u -p -r1.52 log.c
--- lib/log/log.c	16 Jul 2009 13:13:33 -0000	1.52
+++ lib/log/log.c	29 Nov 2009 19:23:14 -0000
@@ -35,6 +36,7 @@ static int _indent = 1;
 static int _log_suppress = 0;
 static char _msg_prefix[30] = "  ";
 static int _already_logging = 0;
+static int _abort_on_internal_errors = 0;
 
 static lvm2_log_fn_t _lvm2_log_fn = NULL;
 
@@ -140,6 +142,11 @@ void init_indent(int indent)
 	_indent = indent;
 }
 
+void init_abort_on_internal_errors(int fatal)
+{
+	_abort_on_internal_errors = fatal;
+}
+
 void reset_lvm_errno(int store_errmsg)
 {
 	_lvm_errno = 0;
@@ -172,9 +179,14 @@ void print_log(int level, const char *fi
 	const char *trformat;		/* Translated format string */
 	char *newbuf;
 	int use_stderr = level & _LOG_STDERR;
+	int internal_error = 0;
 
 	level &= ~_LOG_STDERR;
 
+	if (level <= _LOG_ERR && !strncmp(format, "Internal error:",
+					  strlen("Internal error:")))
+		internal_error = 1;
+
 	if (_log_suppress == 2)
 		return;
 
@@ -291,6 +303,9 @@ void print_log(int level, const char *fi
 		va_end(ap);
 	}
 
+	if (internal_error && _abort_on_internal_errors)
+		abort();
+
 	if (level > debug_level())
 		return;
 
Index: test/test-utils.sh
===================================================================
RCS file: /cvs/lvm2/LVM2/test/test-utils.sh,v
retrieving revision 1.14
diff -u -p -r1.14 test-utils.sh
--- test/test-utils.sh	2 Aug 2009 21:45:45 -0000	1.14
+++ test/test-utils.sh	29 Nov 2009 19:23:15 -0000
@@ -193,6 +193,7 @@ prepare_lvmconf() {
     verbose = $verboselevel
     syslog = 0
     indent = 1
+    abort_on_internal_errors = 1
   }
   backup {
     backup = 0

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]