|
|
47a88a |
From 408a012dabf4c43cfb34dfb9547f9d908a521fec Mon Sep 17 00:00:00 2001
|
|
|
47a88a |
From: Jakub Filak <jfilak@redhat.com>
|
|
|
47a88a |
Date: Thu, 9 Jul 2015 11:54:36 +0200
|
|
|
47a88a |
Subject: [PATCH] cli: use internal command impl in the command process
|
|
|
47a88a |
|
|
|
47a88a |
It did not seem to be a good idea to add wrappers for the internal
|
|
|
47a88a |
commands, because the wrappers would be one line functions. Now, we need
|
|
|
47a88a |
to do more sophisticated processing (authenticate, chown), so adding the
|
|
|
47a88a |
wrappers is the best choice to provide the same functionality in the
|
|
|
47a88a |
command process.
|
|
|
47a88a |
|
|
|
47a88a |
Related: #1224984
|
|
|
47a88a |
|
|
|
47a88a |
Signed-off-by: Jakub Filak <jfilak@redhat.com>
|
|
|
47a88a |
---
|
|
|
47a88a |
src/cli/builtin-cmd.h | 3 +++
|
|
|
47a88a |
src/cli/list.c | 8 ++++++-
|
|
|
47a88a |
src/cli/process.c | 16 ++++---------
|
|
|
47a88a |
src/cli/report.c | 65 +++++++++++++++++++++++++++------------------------
|
|
|
47a88a |
src/cli/rm.c | 7 +++++-
|
|
|
47a88a |
5 files changed, 56 insertions(+), 43 deletions(-)
|
|
|
47a88a |
|
|
|
47a88a |
diff --git a/src/cli/builtin-cmd.h b/src/cli/builtin-cmd.h
|
|
|
47a88a |
index bc80479..c6cd691 100644
|
|
|
47a88a |
--- a/src/cli/builtin-cmd.h
|
|
|
47a88a |
+++ b/src/cli/builtin-cmd.h
|
|
|
47a88a |
@@ -22,8 +22,11 @@
|
|
|
47a88a |
|
|
|
47a88a |
extern int cmd_list(int argc, const char **argv);
|
|
|
47a88a |
extern int cmd_remove(int argc, const char **argv);
|
|
|
47a88a |
+extern int _cmd_remove(const char **dirs_strv);
|
|
|
47a88a |
extern int cmd_report(int argc, const char **argv);
|
|
|
47a88a |
+extern int _cmd_report(const char **dirs_strv, int remove);
|
|
|
47a88a |
extern int cmd_info(int argc, const char **argv);
|
|
|
47a88a |
+extern int _cmd_info(problem_data_t *problem_data, int detailed, int text_size);
|
|
|
47a88a |
extern int cmd_status(int argc, const char **argv);
|
|
|
47a88a |
extern int cmd_process(int argc, const char **argv);
|
|
|
47a88a |
|
|
|
47a88a |
diff --git a/src/cli/list.c b/src/cli/list.c
|
|
|
47a88a |
index 49c3e30..c76e4fb 100644
|
|
|
47a88a |
--- a/src/cli/list.c
|
|
|
47a88a |
+++ b/src/cli/list.c
|
|
|
47a88a |
@@ -217,6 +217,12 @@ int cmd_list(int argc, const char **argv)
|
|
|
47a88a |
return 0;
|
|
|
47a88a |
}
|
|
|
47a88a |
|
|
|
47a88a |
+int _cmd_info(problem_data_t *problem_data, int detailed, int text_size)
|
|
|
47a88a |
+{
|
|
|
47a88a |
+ print_crash(problem_data, detailed, text_size);
|
|
|
47a88a |
+ return 0;
|
|
|
47a88a |
+}
|
|
|
47a88a |
+
|
|
|
47a88a |
int cmd_info(int argc, const char **argv)
|
|
|
47a88a |
{
|
|
|
47a88a |
const char *program_usage_string = _(
|
|
|
47a88a |
@@ -254,7 +260,7 @@ int cmd_info(int argc, const char **argv)
|
|
|
47a88a |
continue;
|
|
|
47a88a |
}
|
|
|
47a88a |
|
|
|
47a88a |
- print_crash(problem, opt_detailed, text_size);
|
|
|
47a88a |
+ _cmd_info(problem, opt_detailed, text_size);
|
|
|
47a88a |
problem_data_free(problem);
|
|
|
47a88a |
if (*argv)
|
|
|
47a88a |
printf("\n");
|
|
|
47a88a |
diff --git a/src/cli/process.c b/src/cli/process.c
|
|
|
47a88a |
index 39462f9..401ef60 100644
|
|
|
47a88a |
--- a/src/cli/process.c
|
|
|
47a88a |
+++ b/src/cli/process.c
|
|
|
47a88a |
@@ -68,28 +68,22 @@ static int process_one_crash(problem_data_t *problem_data)
|
|
|
47a88a |
if(strcmp(action, "rm") == 0 || strcmp(action, "remove") == 0 )
|
|
|
47a88a |
{
|
|
|
47a88a |
log(_("Deleting '%s'"), dir_name);
|
|
|
47a88a |
- delete_dump_dir_possibly_using_abrtd(dir_name);
|
|
|
47a88a |
+ const char *dirs_strv[] = {dir_name, NULL};
|
|
|
47a88a |
+ _cmd_remove(dirs_strv);
|
|
|
47a88a |
|
|
|
47a88a |
ret_val = ACT_REMOVE;
|
|
|
47a88a |
}
|
|
|
47a88a |
else if (not_reportable == NULL && (strcmp(action, "e") == 0 || strcmp(action, "report") == 0))
|
|
|
47a88a |
{
|
|
|
47a88a |
log(_("Reporting '%s'"), dir_name);
|
|
|
47a88a |
- report_problem_in_dir(dir_name,
|
|
|
47a88a |
- LIBREPORT_WAIT
|
|
|
47a88a |
- | LIBREPORT_RUN_CLI);
|
|
|
47a88a |
+ const char *dirs_strv[] = {dir_name, NULL};
|
|
|
47a88a |
+ _cmd_report(dirs_strv, /*do not delete*/0);
|
|
|
47a88a |
|
|
|
47a88a |
ret_val = ACT_REPORT;
|
|
|
47a88a |
}
|
|
|
47a88a |
else if (strcmp(action, "i") == 0 || strcmp(action, "info") == 0)
|
|
|
47a88a |
{
|
|
|
47a88a |
- char *desc = make_description(problem_data,
|
|
|
47a88a |
- /*names_to_skip:*/ NULL,
|
|
|
47a88a |
- /*max_text_size:*/ CD_TEXT_ATT_SIZE_BZ,
|
|
|
47a88a |
- MAKEDESC_SHOW_FILES | MAKEDESC_SHOW_MULTILINE);
|
|
|
47a88a |
-
|
|
|
47a88a |
- fputs(desc, stdout);
|
|
|
47a88a |
- free(desc);
|
|
|
47a88a |
+ _cmd_info(problem_data, /*detailed*/1, CD_TEXT_ATT_SIZE_BZ);
|
|
|
47a88a |
|
|
|
47a88a |
ret_val = ACT_INFO;
|
|
|
47a88a |
}
|
|
|
47a88a |
diff --git a/src/cli/report.c b/src/cli/report.c
|
|
|
47a88a |
index 194f7c9..19b4c51 100644
|
|
|
47a88a |
--- a/src/cli/report.c
|
|
|
47a88a |
+++ b/src/cli/report.c
|
|
|
47a88a |
@@ -22,38 +22,12 @@
|
|
|
47a88a |
#include "abrt-cli-core.h"
|
|
|
47a88a |
#include "builtin-cmd.h"
|
|
|
47a88a |
|
|
|
47a88a |
-int cmd_report(int argc, const char **argv)
|
|
|
47a88a |
+int _cmd_report(const char **dirs_strv, int remove)
|
|
|
47a88a |
{
|
|
|
47a88a |
- const char *program_usage_string = _(
|
|
|
47a88a |
- "& report [options] DIR..."
|
|
|
47a88a |
- );
|
|
|
47a88a |
-
|
|
|
47a88a |
- enum {
|
|
|
47a88a |
- OPT_v = 1 << 0,
|
|
|
47a88a |
- OPT_d = 1 << 1,
|
|
|
47a88a |
- };
|
|
|
47a88a |
-
|
|
|
47a88a |
- struct options program_options[] = {
|
|
|
47a88a |
- OPT__VERBOSE(&g_verbose),
|
|
|
47a88a |
- OPT_BOOL('d', "delete", NULL, _("Remove PROBLEM_DIR after reporting")),
|
|
|
47a88a |
- OPT_END()
|
|
|
47a88a |
- };
|
|
|
47a88a |
-
|
|
|
47a88a |
- unsigned opts = parse_opts(argc, (char **)argv, program_options, program_usage_string);
|
|
|
47a88a |
- argv += optind;
|
|
|
47a88a |
-
|
|
|
47a88a |
- if (!argv[0])
|
|
|
47a88a |
- show_usage_and_die(program_usage_string, program_options);
|
|
|
47a88a |
-
|
|
|
47a88a |
- export_abrt_envvars(/*prog_prefix:*/ 0);
|
|
|
47a88a |
-
|
|
|
47a88a |
- load_abrt_conf();
|
|
|
47a88a |
- free_abrt_conf_data();
|
|
|
47a88a |
-
|
|
|
47a88a |
int ret = 0;
|
|
|
47a88a |
- while (*argv)
|
|
|
47a88a |
+ while (*dirs_strv)
|
|
|
47a88a |
{
|
|
|
47a88a |
- const char *dir_name = *argv++;
|
|
|
47a88a |
+ const char *dir_name = *dirs_strv++;
|
|
|
47a88a |
char *const real_problem_id = hash2dirname_if_necessary(dir_name);
|
|
|
47a88a |
if (real_problem_id == NULL)
|
|
|
47a88a |
{
|
|
|
47a88a |
@@ -75,7 +49,7 @@ int cmd_report(int argc, const char **argv)
|
|
|
47a88a |
| LIBREPORT_RUN_CLI);
|
|
|
47a88a |
|
|
|
47a88a |
/* the problem was successfully reported and option is -d */
|
|
|
47a88a |
- if((opts & OPT_d) && (status == 0 || status == EXIT_STOP_EVENT_RUN))
|
|
|
47a88a |
+ if(remove && (status == 0 || status == EXIT_STOP_EVENT_RUN))
|
|
|
47a88a |
{
|
|
|
47a88a |
log(_("Deleting '%s'"), real_problem_id);
|
|
|
47a88a |
delete_dump_dir_possibly_using_abrtd(real_problem_id);
|
|
|
47a88a |
@@ -89,3 +63,34 @@ int cmd_report(int argc, const char **argv)
|
|
|
47a88a |
|
|
|
47a88a |
return ret;
|
|
|
47a88a |
}
|
|
|
47a88a |
+
|
|
|
47a88a |
+int cmd_report(int argc, const char **argv)
|
|
|
47a88a |
+{
|
|
|
47a88a |
+ const char *program_usage_string = _(
|
|
|
47a88a |
+ "& report [options] DIR..."
|
|
|
47a88a |
+ );
|
|
|
47a88a |
+
|
|
|
47a88a |
+ enum {
|
|
|
47a88a |
+ OPT_v = 1 << 0,
|
|
|
47a88a |
+ OPT_d = 1 << 1,
|
|
|
47a88a |
+ };
|
|
|
47a88a |
+
|
|
|
47a88a |
+ struct options program_options[] = {
|
|
|
47a88a |
+ OPT__VERBOSE(&g_verbose),
|
|
|
47a88a |
+ OPT_BOOL('d', "delete", NULL, _("Remove PROBLEM_DIR after reporting")),
|
|
|
47a88a |
+ OPT_END()
|
|
|
47a88a |
+ };
|
|
|
47a88a |
+
|
|
|
47a88a |
+ unsigned opts = parse_opts(argc, (char **)argv, program_options, program_usage_string);
|
|
|
47a88a |
+ argv += optind;
|
|
|
47a88a |
+
|
|
|
47a88a |
+ if (!argv[0])
|
|
|
47a88a |
+ show_usage_and_die(program_usage_string, program_options);
|
|
|
47a88a |
+
|
|
|
47a88a |
+ export_abrt_envvars(/*prog_prefix:*/ 0);
|
|
|
47a88a |
+
|
|
|
47a88a |
+ load_abrt_conf();
|
|
|
47a88a |
+ free_abrt_conf_data();
|
|
|
47a88a |
+
|
|
|
47a88a |
+ return _cmd_report(argv, opts & OPT_d);
|
|
|
47a88a |
+}
|
|
|
47a88a |
diff --git a/src/cli/rm.c b/src/cli/rm.c
|
|
|
47a88a |
index 37d50e2..95ae097 100644
|
|
|
47a88a |
--- a/src/cli/rm.c
|
|
|
47a88a |
+++ b/src/cli/rm.c
|
|
|
47a88a |
@@ -52,6 +52,11 @@ static int remove_using_abrtd_or_fs(const char **dirs_strv)
|
|
|
47a88a |
return errs;
|
|
|
47a88a |
}
|
|
|
47a88a |
|
|
|
47a88a |
+int _cmd_remove(const char **dirs_strv)
|
|
|
47a88a |
+{
|
|
|
47a88a |
+ return (g_cli_authenticate ? remove_using_dbus : remove_using_abrtd_or_fs)(dirs_strv);
|
|
|
47a88a |
+}
|
|
|
47a88a |
+
|
|
|
47a88a |
int cmd_remove(int argc, const char **argv)
|
|
|
47a88a |
{
|
|
|
47a88a |
const char *program_usage_string = _(
|
|
|
47a88a |
@@ -69,5 +74,5 @@ int cmd_remove(int argc, const char **argv)
|
|
|
47a88a |
if (!argv[0])
|
|
|
47a88a |
show_usage_and_die(program_usage_string, program_options);
|
|
|
47a88a |
|
|
|
47a88a |
- return (g_cli_authenticate ? remove_using_dbus : remove_using_abrtd_or_fs)(argv);
|
|
|
47a88a |
+ return _cmd_remove(argv);
|
|
|
47a88a |
}
|
|
|
47a88a |
--
|
|
|
47a88a |
2.4.3
|
|
|
47a88a |
|