diff --git a/WHATS_NEW b/WHATS_NEW index 167cb23da..698a709cd 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,7 @@ Version 2.02.38 - ================================= + In script-processing mode, stop if any command fails. + Warn if command exits with non-zero status code without a prior log_error. Make clvmd-cman use a hash rather than an array for node updown info. Check lv_count in vg_validate. Add --prefixes to reporting tools for field name prefix output format. diff --git a/lib/log/log.c b/lib/log/log.c index f32e56ea3..e8806619e 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -51,6 +51,7 @@ static int _already_logging = 0; static int _mirror_in_sync = 0; static int _dmeventd_monitor = DEFAULT_DMEVENTD_MONITOR; static int _ignore_suspended_devices = 0; +static int _error_message_produced = 0; static lvm2_log_fn_t _lvm2_log_fn = NULL; @@ -238,6 +239,16 @@ void init_indent(int indent) _indent = indent; } +void init_error_message_produced(int error_message_produced) +{ + _error_message_produced = error_message_produced; +} + +int error_message_produced(void) +{ + return _error_message_produced; +} + int test_mode() { return _test; @@ -322,6 +333,9 @@ void print_log(int level, const char *file, int line, const char *format, ...) if (_log_suppress == 2) return; + if (level <= _LOG_ERR) + _error_message_produced = 1; + trformat = _(format); if (_lvm2_log_fn) { diff --git a/lib/log/log.h b/lib/log/log.h index d5e0664e7..8b85758bf 100644 --- a/lib/log/log.h +++ b/lib/log/log.h @@ -79,6 +79,7 @@ void init_security_level(int level); void init_mirror_in_sync(int in_sync); void init_dmeventd_monitor(int reg); void init_ignore_suspended_devices(int ignore); +void init_error_message_produced(int error_message_produced); void set_cmd_name(const char *cmd_name); @@ -94,6 +95,7 @@ int lockingfailed(void); int security_level(void); int mirror_in_sync(void); int ignore_suspended_devices(void); +int error_message_produced(void); #define DMEVENTD_MONITOR_IGNORE -1 int dmeventd_monitor_mode(void); diff --git a/tools/lvm.c b/tools/lvm.c index 7d58ae829..04eaf6818 100644 --- a/tools/lvm.c +++ b/tools/lvm.c @@ -236,6 +236,10 @@ int lvm_shell(struct cmd_context *cmd, struct cmdline_context *cmdline) log_error("No such command '%s'. Try 'help'.", argv[0]); + if (ret && !error_message_produced()) { + log_debug("Internal error: Failed command did not use log_error"); + log_error("Command failed with status code %d.", ret); + } _write_history(); } diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c index bb3fdaecc..4ce2b0317 100644 --- a/tools/lvmcmdline.c +++ b/tools/lvmcmdline.c @@ -875,6 +875,8 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv) int ret = 0; int locking_type; + init_error_message_produced(0); + /* each command should start out with sigint flag cleared */ sigint_clear(); @@ -1096,7 +1098,14 @@ static int _run_script(struct cmd_context *cmd, int argc, char **argv) continue; if (!strcmp(argv[0], "quit") || !strcmp(argv[0], "exit")) break; - lvm_run_command(cmd, argc, argv); + ret = lvm_run_command(cmd, argc, argv); + if (ret) { + if (!error_message_produced()) { + log_debug("Internal error: Failed command did not use log_error"); + log_error("Command failed with status code %d.", ret); + } + break; + } } if (fclose(script)) @@ -1218,6 +1227,11 @@ int lvm2_main(int argc, char **argv, unsigned is_static) if (ret == ENO_SUCH_CMD) log_error("No such command. Try 'help'."); + if (ret && !error_message_produced()) { + log_debug("Internal error: Failed command did not use log_error"); + log_error("Command failed with status code %d.", ret); + } + out: lvm_fin(cmd); if (ret == ECMD_PROCESSED)