stored_errno(), ret_code);
}
+static void _discard_log_report_content(struct cmd_context *cmd)
+{
+ if (cmd->cmd_report.log_rh)
+ dm_report_destroy_rows(cmd->cmd_report.log_rh);
+}
+
int lvm_shell(struct cmd_context *cmd, struct cmdline_context *cmdline)
{
log_report_t saved_log_report_state = log_get_report_state();
rl_attempted_completion_function = (rl_completion_func_t *) _completion;
_read_history(cmd);
-
_cmdline = cmdline;
cmd->is_interactive = 1;
+
+ if (!report_format_init(cmd))
+ return_ECMD_FAILED;
+
log_set_report_context(LOG_REPORT_CONTEXT_SHELL);
log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_CMD);
while (1) {
+ log_set_report(cmd->cmd_report.log_rh);
log_set_report_object_name_and_id(NULL, NULL);
+
free(input);
input = readline("lvm> ");
/* EOF */
if (!input) {
+ _discard_log_report_content(cmd);
/* readline sends prompt to stdout */
printf("\n");
break;
}
/* empty line */
- if (!*input)
+ if (!*input) {
+ _discard_log_report_content(cmd);
continue;
+ }
add_history(input);
argv = args;
if (lvm_split(input, &argc, argv, MAX_ARGS) == MAX_ARGS) {
+ _discard_log_report_content(cmd);
log_error("Too many arguments, sorry.");
continue;
}
- if (!argc)
+ if (!argc) {
+ _discard_log_report_content(cmd);
continue;
+ }
if (!strcmp(argv[0], "lvm")) {
argv++;
argc--;
}
- if (!argc)
+ if (!argc) {
+ _discard_log_report_content(cmd);
continue;
+ }
log_set_report_object_name_and_id(argv[0], NULL);
+ is_lastlog_cmd = !strcmp(argv[0], "lastlog");
+
+ if (!is_lastlog_cmd)
+ _discard_log_report_content(cmd);
+
if (!strcmp(argv[0], "quit") || !strcmp(argv[0], "exit")) {
+ _discard_log_report_content(cmd);
remove_history(history_length - 1);
log_error("Exiting.");
break;
}
- is_lastlog_cmd = !strcmp(argv[0], "lastlog");
-
- if (cmd->cmd_report.log_rh && !is_lastlog_cmd) {
- /* drop old log report */
- dm_report_free(cmd->cmd_report.log_rh);
- cmd->cmd_report.log_rh = NULL;
- }
-
ret = lvm_run_command(cmd, argc, argv);
if (ret == ENO_SUCH_CMD)
log_error("No such command '%s'. Try 'help'.",
if (!is_lastlog_cmd)
_log_shell_command_status(cmd, ret);
+
+ log_set_report(NULL);
+ dm_report_group_output_and_pop_all(cmd->cmd_report.report_group);
+
+ if (cmd->cmd_report.log_rh &&
+ !(dm_report_group_push(cmd->cmd_report.report_group,
+ cmd->cmd_report.log_rh,
+ (void *) cmd->cmd_report.log_name))) {
+ log_set_report(NULL);
+ log_error("Failed to add log report.");
+ break;
+ }
}
log_restore_report_state(saved_log_report_state);
cmd->is_interactive = 0;
free(input);
+
+ if (cmd->cmd_report.report_group) {
+ dm_report_group_destroy(cmd->cmd_report.report_group);
+ cmd->cmd_report.report_group = NULL;
+ }
+
+ if (cmd->cmd_report.log_rh) {
+ dm_report_free(cmd->cmd_report.log_rh);
+ cmd->cmd_report.report_group = NULL;
+ }
+
return 0;
}
} else
r = _do_report(cmd, handle, &args, single_args);
+ if (!args.log_only && !dm_report_group_pop(cmd->cmd_report.report_group)) {
+ log_error("Failed to finalize main report section in report group.");
+ r = ECMD_FAILED;
+ }
+
destroy_processing_handle(cmd, handle);
return r;
}
return 0;
}
-int lastlog(struct cmd_context *cmd, int argc, char **argv)
+int lastlog(struct cmd_context *cmd, int argc __attribute((unused)), char **argv __attribute__((unused)))
{
- struct dm_report_group *report_group = NULL;
const char *selection;
- int r = ECMD_FAILED;
if (!cmd->cmd_report.log_rh) {
log_error("No log report stored.");
- goto out;
+ return ECMD_FAILED;
}
if (!_do_report_get_selection(cmd, CMDLOG, 1, NULL, &selection))
- goto_out;
+ return_ECMD_FAILED;
if (!dm_report_set_selection(cmd->cmd_report.log_rh, selection)) {
log_error("Failed to set selection for log report.");
- goto out;
+ return ECMD_FAILED;
}
- if (!dm_report_output(cmd->cmd_report.log_rh) ||
- !dm_report_group_pop(report_group))
- goto_out;
-
- r = ECMD_PROCESSED;
-out:
- if (!dm_report_group_destroy(report_group))
- stack;
- return r;
+ return ECMD_PROCESSED;
}
log_restore_report_state(cmd->cmd_report.saved_log_report_state);
- if (!dm_report_group_destroy(cmd->cmd_report.report_group))
- stack;
- if (!cmd->is_interactive && cmd->cmd_report.log_rh) {
- dm_report_free(cmd->cmd_report.log_rh);
- cmd->cmd_report.log_rh = NULL;
+ if (!cmd->is_interactive) {
+ if (!dm_report_group_destroy(cmd->cmd_report.report_group))
+ stack;
+ cmd->cmd_report.report_group = NULL;
+
+ if (cmd->cmd_report.log_rh) {
+ dm_report_free(cmd->cmd_report.log_rh);
+ cmd->cmd_report.log_rh = NULL;
+ }
}
/*
* TODO: think about better alternatives: