abrt-cli can report problems by specifying number of crash instead of
long path name.
Signed-off-by: Nikola Pajkovsky <npajkovs(a)redhat.com>
---
src/cli/Makefile.am | 3 +-
src/cli/abrt-cli-core.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++
src/cli/abrt-cli-core.h | 32 ++++++++++++++++
src/cli/list.c | 85 ++++-------------------------------------
src/cli/report.c | 36 +++++++++++++++++-
5 files changed, 173 insertions(+), 78 deletions(-)
create mode 100644 src/cli/abrt-cli-core.c
create mode 100644 src/cli/abrt-cli-core.h
diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am
index bbd1402..3839e3c 100644
--- a/src/cli/Makefile.am
+++ b/src/cli/Makefile.am
@@ -4,13 +4,14 @@ bin_PROGRAMS = abrt-cli
CLI_C =
CLI_C += abrt-cli.c
+CLI_C += abrt-cli-core.c
BUILTIN_C =
BUILTIN_C += list.c
BUILTIN_C += rm.c
BUILTIN_C += report.c
-abrt_cli_SOURCES = $(CLI_C) $(BUILTIN_C) builtin-cmd.h
+abrt_cli_SOURCES = $(CLI_C) $(BUILTIN_C) builtin-cmd.h abrt-cli-core.h
abrt_cli_CFLAGS = \
-I$(srcdir)/../include \
diff --git a/src/cli/abrt-cli-core.c b/src/cli/abrt-cli-core.c
new file mode 100644
index 0000000..0221f03
--- /dev/null
+++ b/src/cli/abrt-cli-core.c
@@ -0,0 +1,95 @@
+/*
+ Copyright (C) 2011 ABRT Team
+ Copyright (C) 2011 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "abrtlib.h"
+#include "abrt-cli-core.h"
+
+/* Vector of problems: */
+/* problem_data_vector[i] = { "name" = { "content", CD_FLAG_foo_bits
} } */
+
+inline problem_data_t *get_problem_data(vector_of_problem_data_t *vector, unsigned i)
+{
+ return (problem_data_t *)g_ptr_array_index(vector, i);
+}
+
+void free_vector_of_problem_data(vector_of_problem_data_t *vector)
+{
+ if (vector)
+ g_ptr_array_free(vector, TRUE);
+}
+
+vector_of_problem_data_t *new_vector_of_problem_data(void)
+{
+ return g_ptr_array_new_with_free_func((void (*)(void*)) &free_problem_data);
+}
+
+problem_data_t *fill_crash_info(const char *dump_dir_name)
+{
+ int sv_logmode = logmode;
+ logmode = 0; /* suppress EPERM/EACCES errors in opendir */
+ struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ DD_OPEN_READONLY);
+ logmode = sv_logmode;
+
+ if (!dd)
+ return NULL;
+
+ problem_data_t *problem_data = create_problem_data_from_dump_dir(dd);
+ dd_close(dd);
+ add_to_problem_data_ext(problem_data, CD_DUMPDIR, dump_dir_name,
+ CD_FLAG_TXT + CD_FLAG_ISNOTEDITABLE + CD_FLAG_LIST);
+
+ return problem_data;
+}
+
+vector_of_problem_data_t *fetch_crash_infos(GList *dir_list)
+{
+ vector_of_problem_data_t *ci = new_vector_of_problem_data();
+ for (GList *li = dir_list; li; li = li->next)
+ {
+ char *dir_name = (char *)li->data;
+ VERB1 log("Loading dumps from '%s'", dir_name);
+
+ DIR *dir = opendir(dir_name);
+ if (dir != NULL)
+ {
+ struct dirent *dent;
+ while ((dent = readdir(dir)) != NULL)
+ {
+ if (dot_or_dotdot(dent->d_name))
+ continue; /* skip "." and ".." */
+
+ char *dump_dir_name = concat_path_file(dir_name, dent->d_name);
+
+ struct stat statbuf;
+ if (stat(dump_dir_name, &statbuf) == 0
+ && S_ISDIR(statbuf.st_mode))
+ {
+ problem_data_t *problem_data = fill_crash_info(dump_dir_name);
+ if (problem_data)
+ g_ptr_array_add(ci, problem_data);
+ }
+ free(dump_dir_name);
+ }
+ closedir(dir);
+ }
+ }
+
+ return ci;
+}
+
diff --git a/src/cli/abrt-cli-core.h b/src/cli/abrt-cli-core.h
new file mode 100644
index 0000000..55a307b
--- /dev/null
+++ b/src/cli/abrt-cli-core.h
@@ -0,0 +1,32 @@
+/*
+ Copyright (C) 2011 ABRT Team
+ Copyright (C) 2011 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#ifndef ABRT_CLI_CORE_H_
+#define ABRT_CLI_CORE_H_
+
+typedef GPtrArray vector_of_problem_data_t;
+
+problem_data_t *get_problem_data(vector_of_problem_data_t *vector, unsigned i);
+
+void free_vector_of_problem_data(vector_of_problem_data_t *vector);
+vector_of_problem_data_t *new_vector_of_problem_data(void);
+problem_data_t *fill_crash_info(const char *dump_dir_name);
+vector_of_problem_data_t *fetch_crash_infos(GList *dir_list);
+
+#endif /* ABRT_CLI_CORE_H_ */
diff --git a/src/cli/list.c b/src/cli/list.c
index e4f30fe..131111a 100644
--- a/src/cli/list.c
+++ b/src/cli/list.c
@@ -18,6 +18,8 @@
*/
#include "abrtlib.h"
+
+#include "abrt-cli-core.h"
#include "builtin-cmd.h"
/* TODO: npajkovs
@@ -30,73 +32,6 @@
* ~/.abrt/spool and /var/spool/abrt? needs more _meditation_.
*/
-/* Vector of problems: */
-/* problem_data_vector[i] = { "name" = { "content", CD_FLAG_foo_bits
} } */
-typedef GPtrArray vector_of_problem_data_t;
-
-static inline problem_data_t *get_problem_data(vector_of_problem_data_t *vector, unsigned
i)
-{
- return (problem_data_t *)g_ptr_array_index(vector, i);
-}
-
-static void free_vector_of_problem_data(vector_of_problem_data_t *vector)
-{
- if (vector)
- g_ptr_array_free(vector, TRUE);
-}
-
-static vector_of_problem_data_t *new_vector_of_problem_data(void)
-{
- return g_ptr_array_new_with_free_func((void (*)(void*)) &free_problem_data);
-}
-
-static problem_data_t *fill_crash_info(const char *dump_dir_name)
-{
- int sv_logmode = logmode;
- logmode = 0; /* suppress EPERM/EACCES errors in opendir */
- struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ DD_OPEN_READONLY);
- logmode = sv_logmode;
-
- if (!dd)
- return NULL;
-
- problem_data_t *problem_data = create_problem_data_from_dump_dir(dd);
- dd_close(dd);
- add_to_problem_data_ext(problem_data, CD_DUMPDIR, dump_dir_name,
- CD_FLAG_TXT + CD_FLAG_ISNOTEDITABLE + CD_FLAG_LIST);
-
- return problem_data;
-}
-
-static void get_all_crash_infos(vector_of_problem_data_t *retval, const char *dir_name)
-{
- VERB1 log("Loading dumps from '%s'", dir_name);
-
- DIR *dir = opendir(dir_name);
- if (dir != NULL)
- {
- struct dirent *dent;
- while ((dent = readdir(dir)) != NULL)
- {
- if (dot_or_dotdot(dent->d_name))
- continue; /* skip "." and ".." */
-
- char *dump_dir_name = concat_path_file(dir_name, dent->d_name);
-
- struct stat statbuf;
- if (stat(dump_dir_name, &statbuf) == 0
- && S_ISDIR(statbuf.st_mode))
- {
- problem_data_t *problem_data = fill_crash_info(dump_dir_name);
- if (problem_data)
- g_ptr_array_add(retval, problem_data);
- }
- free(dump_dir_name);
- }
- closedir(dir);
- }
-}
-
/** Prints basic information about a crash to stdout. */
static void print_crash(problem_data_t *problem_data, int detailed)
{
@@ -141,6 +76,8 @@ static void print_crash_list(vector_of_problem_data_t *crash_list, int
include_r
if (msg)
continue;
}
+
+ printf("@%i\n", i);
print_crash(crash, detailed);
if (i != crash_list->len - 1)
printf("\n");
@@ -187,17 +124,13 @@ int cmd_list(int argc, const char **argv)
log("\t %s", (char *) li->data);
}
- vector_of_problem_data_t *ci = new_vector_of_problem_data();
- while (D_list)
- {
- char *dir = (char *)D_list->data;
- get_all_crash_infos(ci, dir);
- D_list = g_list_remove(D_list, dir);
- free(dir);
- }
+ vector_of_problem_data_t *ci = fetch_crash_infos(D_list);
+
+ g_ptr_array_sort_with_data(ci, &cmp_problem_data, (char *) FILENAME_TIME);
+
print_crash_list(ci, opt_full, opt_detailed);
free_vector_of_problem_data(ci);
- g_list_free(D_list);
+ list_free_with_free(D_list);
return 0;
}
diff --git a/src/cli/report.c b/src/cli/report.c
index ce22456..770468a 100644
--- a/src/cli/report.c
+++ b/src/cli/report.c
@@ -18,6 +18,8 @@
*/
#include "abrtlib.h"
+
+#include "abrt-cli-core.h"
#include "builtin-cmd.h"
int cmd_report(int argc, const char **argv)
@@ -32,14 +34,46 @@ int cmd_report(int argc, const char **argv)
};
parse_opts(argc, (char **)argv, program_options, program_usage_string);
+
+ load_abrt_conf();
+ char *home = getenv("HOME");
+ GList *D_list = NULL;
+ if (home)
+ D_list = g_list_append(D_list, concat_path_file(home, ".abrt/spool"));
+ D_list = g_list_append(D_list, xstrdup(g_settings_dump_location));
+ free_abrt_conf_data();
+
if (optind < argc)
{
while (optind < argc)
{
- int status = report_problem_in_dir(argv[optind++],
+ const char *dir_name = argv[optind++];
+
+ vector_of_problem_data_t *ci = NULL;
+ if (*dir_name == '@')
+ {
+ dir_name++;
+ char *end;
+ errno = 0;
+ unsigned long at = strtoul(dir_name, &end, 10);
+ if (errno || end == dir_name || *end != '\0')
+ error_msg_and_die("error: not a number '%s'",
dir_name);
+
+ ci = fetch_crash_infos(D_list);
+ if (at >= ci->len)
+ error_msg_and_die("error: number is out of range
'%s'", dir_name);
+
+ g_ptr_array_sort_with_data(ci, &cmp_problem_data, (char *)
FILENAME_TIME);
+ problem_data_t *pd = get_problem_data(ci, at);
+
+ dir_name = get_problem_item_content_or_NULL(pd, CD_DUMPDIR);
+ }
+
+ int status = report_problem_in_dir(dir_name,
LIBREPORT_ANALYZE
| LIBREPORT_WAIT
| LIBREPORT_RUN_CLI);
+ free_vector_of_problem_data(ci);
if (status)
exit(status);
}
--
1.7.6.345.g5c2f8