[PATCH] Several potential leaked FDs found by `cppcheck' in libreport sources.
by Michal Nowak
E.g.:
$ cppcheck -q scm/abrt/ -I ./libreport/src/gtk-helpers/ -I ./libreport/src/include/ -I ./libreport/src/lib/ libreport/
[libreport/src/cli/cli-report.c:365]: (error) Resource leak: fd
---
src/cli/cli-report.c | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/src/cli/cli-report.c b/src/cli/cli-report.c
index f203fad..a1b51b2 100644
--- a/src/cli/cli-report.c
+++ b/src/cli/cli-report.c
@@ -318,18 +318,23 @@ static int run_report_editor(problem_data_t *problem_data)
if (fclose(fp)) /* errno is set */
{
perror_msg("Can't write '%s'", filename);
+ close(fd);
return 2;
}
// Start a text editor on the temporary file.
if (launch_editor(filename) != 0)
+ {
+ close(fd);
return 3; /* exit with error */
+ }
// Read the file back and update the report from the file.
fp = fopen(filename, "r");
if (!fp) /* errno is set */
{
perror_msg("Can't open '%s' to read the crash report", filename);
+ close(fd);
return 2;
}
@@ -342,6 +347,7 @@ static int run_report_editor(problem_data_t *problem_data)
{
error_msg("Can't read '%s'", filename);
fclose(fp);
+ close(fd);
return 2;
}
text[size] = '\0';
@@ -362,6 +368,8 @@ static int run_report_editor(problem_data_t *problem_data)
else
puts(_("\nNo changes were detected in the report"));
+ close(fd);
+
return 0;
}
--
1.7.1
12 years, 9 months
[PATCH] Check by `cppcheck' found possible leaked FDs in src/hooks/abrt-hook-ccpp.c.
by Michal Nowak
$ cppcheck scm/abrt/src/hooks/abrt-hook-ccpp.c
Checking scm/abrt/src/hooks/abrt-hook-ccpp.c...
[scm/abrt/src/hooks/abrt-hook-ccpp.c:296]: (error) Resource leak: user_core_fd
$ cppcheck scm/abrt/src/hooks/abrt-hook-ccpp.c
Checking scm/abrt/src/hooks/abrt-hook-ccpp.c...
[scm/abrt/src/hooks/abrt-hook-ccpp.c:303]: (error) Resource leak: user_core_fd
---
src/hooks/abrt-hook-ccpp.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/src/hooks/abrt-hook-ccpp.c b/src/hooks/abrt-hook-ccpp.c
index 52d006f..dad7a2e 100644
--- a/src/hooks/abrt-hook-ccpp.c
+++ b/src/hooks/abrt-hook-ccpp.c
@@ -293,12 +293,14 @@ static int open_user_core(const char *user_pwd, uid_t uid, pid_t pid, char **per
/* kernel internal dumper checks this too: if (inode->i_uid != current->fsuid) <fail>, need to mimic? */
) {
perror_msg("%s/%s is not a regular file with link count 1", user_pwd, core_basename);
+ close(user_core_fd);
return -1;
}
if (ftruncate(user_core_fd, 0) != 0) {
/* perror first, otherwise unlink may trash errno */
perror_msg("truncate %s/%s", user_pwd, core_basename);
unlink(core_basename);
+ close(user_core_fd);
return -1;
}
--
1.7.1
12 years, 9 months
[PATCH] [abrt] invoke report-cli when reporting from abrt-cli
by Nikola Pajkovsky
Signed-off-by: Nikola Pajkovsky <npajkovs(a)redhat.com>
---
src/cli/report.c | 13 +++++++++++--
1 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/cli/report.c b/src/cli/report.c
index 1d2ffbc..ce22456 100644
--- a/src/cli/report.c
+++ b/src/cli/report.c
@@ -33,9 +33,18 @@ int cmd_report(int argc, const char **argv)
parse_opts(argc, (char **)argv, program_options, program_usage_string);
if (optind < argc)
+ {
while (optind < argc)
- report_problem_in_dir(argv[optind++],
- LIBREPORT_ANALYZE | LIBREPORT_NOWAIT);
+ {
+ int status = report_problem_in_dir(argv[optind++],
+ LIBREPORT_ANALYZE
+ | LIBREPORT_WAIT
+ | LIBREPORT_RUN_CLI);
+ if (status)
+ exit(status);
+ }
+ exit(0);
+ }
show_usage_and_die(program_usage_string, program_options);
--
1.7.6.345.g5c2f8
12 years, 9 months
[PATCH] Return nonzero when -r is passed invalid directory
by Martin Milata
This should fix bug #300.
---
src/cli/cli.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/cli/cli.c b/src/cli/cli.c
index 49484c3..e356f5e 100644
--- a/src/cli/cli.c
+++ b/src/cli/cli.c
@@ -322,7 +322,7 @@ int main(int argc, char** argv)
{
struct dump_dir *dd = dd_opendir(dump_dir_name, DD_OPEN_READONLY);
if (!dd)
- break;
+ return 1;
int readonly = !dd->locked;
dd_close(dd);
if (readonly)
--
1.7.6
12 years, 9 months
[PATCH 1/2] [abrt] bring back to live abrt-cli
by Nikola Pajkovsky
getting infos about crash, deleting dump dirs and invoking reporting belongs to
abrt.git (abrt-gui does it too)
abrt-cli uses commands now instead of switches for main purpose like deleting,
reporting and getting information about crash.
second steps will be to add aliases for commands. If aliases won't be set for
commands, then abbreviation for commands comes to play.
Usage string for abrt-cli:
abrt-cli [--version] [--base-dir=DUMP_DIR] <command> [<args>]
--base-dir - change base dir for dump directories
--version - print out version and die
commands are:
list
rm
report
Each command can take it's own arguments.
list command
------------
Usage: abrt-cli list [options] [<dump-dir>]...
-v, --verbose Be verbose
-f, --full List even reported problems
-d, --detailed Show detailed report
Maybe option --detail is better then --detailed
rm command
----------
Usage: abrt-cli rm [options] [<dump-dir>]...
-v, --verbose Be verbose
note that you can do abrt-cli rm /path/to/base/dir/cpp-* so wildcard is working
out of box
report command
--------------
Usage: abrt-cli report [options] [<dump-dir>]...
-v, --verbose Be verbose
simply invoke report_problem_in_dir
Signed-off-by: Nikola Pajkovsky <npajkovs(a)redhat.com>
---
.gitignore | 1 +
abrt.spec.in | 4 +-
configure.ac | 1 +
src/Makefile.am | 2 +-
src/cli/Makefile.am | 25 +++++
src/cli/abrt-cli.c | 144 +++++++++++++++++++++++++++++
src/cli/builtin-cmd.h | 28 ++++++
src/cli/list.c | 242 +++++++++++++++++++++++++++++++++++++++++++++++++
src/cli/report.c | 43 +++++++++
src/cli/rm.c | 53 +++++++++++
10 files changed, 540 insertions(+), 3 deletions(-)
create mode 100644 src/cli/Makefile.am
create mode 100644 src/cli/abrt-cli.c
create mode 100644 src/cli/builtin-cmd.h
create mode 100644 src/cli/list.c
create mode 100644 src/cli/report.c
create mode 100644 src/cli/rm.c
diff --git a/.gitignore b/.gitignore
index 745cb02..a60e543 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,6 +26,7 @@ src/hooks/abrt_exception_handler.py
src/hooks/abrt-hook-ccpp
src/applet/abrt-applet.desktop
src/gui-gtk/abrt.desktop
+src/cli/abrt-cli
# cscope files
cscope.*
diff --git a/abrt.spec.in b/abrt.spec.in
index 00e37d4..3334b70 100644
--- a/abrt.spec.in
+++ b/abrt.spec.in
@@ -185,8 +185,6 @@ mkdir -p $RPM_BUILD_ROOT/var/cache/abrt-di
mkdir -p $RPM_BUILD_ROOT/var/run/abrt
mkdir -p $RPM_BUILD_ROOT/var/spool/abrt
mkdir -p $RPM_BUILD_ROOT/var/spool/abrt-upload
-# compat before we split abrt-cli and report-cli
-ln -s %{_bindir}/report-cli $RPM_BUILD_ROOT/%{_bindir}/abrt-cli
desktop-file-install \
--dir ${RPM_BUILD_ROOT}%{_datadir}/applications \
@@ -429,6 +427,8 @@ gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :
%files cli
%defattr(-,root,root,-)
%{_bindir}/abrt-cli
+# provide asap
+#% {_mandir}/man1/report-cli.1.gz
%files desktop
%defattr(-,root,root,-)
diff --git a/configure.ac b/configure.ac
index 1726093..8de55d2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -138,6 +138,7 @@ AC_CONFIG_FILES([
src/hooks/Makefile
src/applet/Makefile
src/gui-gtk/Makefile
+ src/cli/Makefile
po/Makefile.in
icons/Makefile
])
diff --git a/src/Makefile.am b/src/Makefile.am
index b41b939..ab95ef7 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1 +1 @@
-SUBDIRS = include lib hooks daemon applet gui-gtk plugins
+SUBDIRS = include lib hooks daemon applet gui-gtk plugins cli
diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am
new file mode 100644
index 0000000..c5ebc14
--- /dev/null
+++ b/src/cli/Makefile.am
@@ -0,0 +1,25 @@
+-include ../../config.mak
+
+bin_PROGRAMS = abrt-cli
+
+CLI_C =
+CLI_C += abrt-cli.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_CFLAGS = \
+ -I$(srcdir)/../include \
+ -I$(srcdir)/../lib \
+ -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \
+ $(LIBREPORT_CFLAGS) \
+ -Wwrite-strings -Werror
+
+abrt_cli_LDADD = \
+ $(LIBREPORT_LIBS)
+
+DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
diff --git a/src/cli/abrt-cli.c b/src/cli/abrt-cli.c
new file mode 100644
index 0000000..ebc1620
--- /dev/null
+++ b/src/cli/abrt-cli.c
@@ -0,0 +1,144 @@
+/*
+ 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 "builtin-cmd.h"
+
+#define USAGE_OPTS_WIDTH 12
+#define USAGE_GAP 2
+
+/* TODO: add --pager(default) and --no-pager */
+
+const char abrt_cli_usage_string[] =
+ "abrt-cli [--version] <command> [<args>]";
+
+struct cmd_struct {
+ const char *cmd;
+ int (*fn)(int, const char **);
+ const char *help;
+};
+
+static void list_cmds_help(const struct cmd_struct *commands)
+{
+ for (const struct cmd_struct *p = commands; p->cmd; ++p)
+ {
+ size_t pos;
+ int pad;
+
+ pos = fprintf(stderr, " ");
+ pos += fprintf(stderr, "%s", p->cmd);
+
+ if (pos <= USAGE_OPTS_WIDTH)
+ pad = USAGE_OPTS_WIDTH - pos;
+ else
+ {
+ fputc('\n', stderr);
+ pad = USAGE_OPTS_WIDTH;
+ }
+
+ fprintf(stderr, "%*s%s\n", pad + USAGE_GAP, "", p->help);
+ }
+}
+
+static void handle_internal_options(int *argc, const char ***argv)
+{
+ while (*argc > 0)
+ {
+ const char *cmd = (*argv)[0];
+ if (cmd[0] != '-')
+ break;
+
+ if (strcmp(cmd, "--version") == 0)
+ {
+ puts(PACKAGE_VERSION);
+ exit(0);
+ }
+#if 0
+ else if (prefixcmp(cmd, "--base-dir=") == 0)
+ D_list = g_list_append(D_list, xstrdup(cmd + strlen("--base-dir=")));
+ else if (prefixcmp(cmd, "--list-events") == 0)
+ {
+ const char *pfx = cmd + strlen("--list-events");
+ if (pfx && *pfx)
+ pfx += 1; /* skip '=' */
+
+ char *events = list_possible_events(NULL, dump_dir_name, pfx);
+ if (!events)
+ exit(1); /* error msg is already logged */
+
+ fputs(events, stdout);
+ free(events);
+
+ exit(0);
+ }
+#endif
+ else
+ error_msg_and_die("usage: %s", abrt_cli_usage_string);
+
+ (*argv)++;
+ (*argc)--;
+ }
+}
+
+static void handle_internal_command(int argc, const char **argv,
+ const struct cmd_struct *commands)
+{
+ const char *cmd = argv[0];
+
+ for (const struct cmd_struct *p = commands; p->cmd; ++p)
+ {
+ if (strcmp(p->cmd, cmd))
+ continue;
+
+ exit(p->fn(argc, argv));
+ }
+}
+
+int main(int argc, const char **argv)
+{
+ abrt_init((char **)argv);
+
+ setlocale(LC_ALL, "");
+#if ENABLE_NLS
+ bindtextdomain(PACKAGE, LOCALEDIR);
+ textdomain(PACKAGE);
+#endif
+
+ argv++;
+ argc--;
+
+ const struct cmd_struct commands[] = {
+ {"list", cmd_list, _("List not yet reported problems")},
+ {"rm", cmd_rm, _("Remove files from problem directory")},
+ {"report", cmd_report, _("Analyze and report problem data in problem directory")},
+ {"info", cmd_info, _("Print information about DUMP_DIR")},
+ {NULL, NULL, NULL}
+ };
+
+ handle_internal_options(&argc, &argv);
+ if (argc > 0)
+ handle_internal_command(argc, argv, commands);
+
+ /* user didn't specify command; print out help */
+ printf("%s\n\n", abrt_cli_usage_string);
+ list_cmds_help(commands);
+ printf("\n%s\n", _("See 'abrt-cli <command> -h' for more information"));
+
+ return 0;
+}
diff --git a/src/cli/builtin-cmd.h b/src/cli/builtin-cmd.h
new file mode 100644
index 0000000..cea77d8
--- /dev/null
+++ b/src/cli/builtin-cmd.h
@@ -0,0 +1,28 @@
+/*
+ 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 _BUILTIN_CMD_H_
+#define _BUILTIN_CMD_H_
+
+extern int cmd_list(int argc, const char **argv);
+extern int cmd_rm(int argc, const char **argv);
+extern int cmd_report(int argc, const char **argv);
+extern int cmd_info(int argc, const char **argv);
+
+#endif /* _BUILTIN-CMD_H_ */
diff --git a/src/cli/list.c b/src/cli/list.c
new file mode 100644
index 0000000..833b4c7
--- /dev/null
+++ b/src/cli/list.c
@@ -0,0 +1,242 @@
+/*
+ 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 "builtin-cmd.h"
+
+/* TODO: npajkovs
+ * add --since
+ * add --until
+ * add --pretty=oneline|raw|normal|format="%a %b %c"
+ * add wildcard e.g. *-2011-04-01-10-* (list all problems in specific day)
+ *
+ * TODO?: remove base dir from list of crashes? is there a way that same crash can be in
+ * ~/.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)
+{
+ if (!problem_data)
+ return;
+
+ char *desc;
+ if (detailed)
+ {
+ int show_multiline = (detailed ? MAKEDESC_SHOW_MULTILINE : 0);
+ desc = make_description(problem_data,
+ /*names_to_skip:*/ NULL,
+ /*max_text_size:*/ CD_TEXT_ATT_SIZE,
+ MAKEDESC_SHOW_FILES | show_multiline);
+ }
+ else
+ {
+ desc = make_description(problem_data,
+ /*names_to_skip:*/ NULL,
+ /*max_text_size:*/ CD_TEXT_ATT_SIZE,
+ MAKEDESC_SHOW_ONLY_LIST);
+ }
+ fprintf(stdout, "%s", desc);
+ free(desc);
+}
+
+/**
+ * Prints a list containing "crashes" to stdout.
+ * @param include_reported
+ * Do not skip entries marked as already reported.
+ */
+static void print_crash_list(vector_of_problem_data_t *crash_list, int include_reported,
+ int detailed)
+{
+ unsigned i;
+ for (i = 0; i < crash_list->len; ++i)
+ {
+ problem_data_t *crash = get_problem_data(crash_list, i);
+ if (!include_reported)
+ {
+ const char *msg = get_problem_item_content_or_NULL(crash, FILENAME_REPORTED_TO);
+ if (msg)
+ continue;
+ }
+ print_crash(crash, detailed);
+ if (i != crash_list->len - 1)
+ printf("\n");
+ }
+}
+
+int cmd_list(int argc, const char **argv)
+{
+ const char *program_usage_string = _(
+ "\b list [options] [<dump-dir>]..."
+ );
+
+ static int opt_full, opt_detailed;
+ struct options program_options[] = {
+ OPT__VERBOSE(&g_verbose),
+ OPT_GROUP(""),
+ OPT_BOOL('f', "full" , &opt_full, _("List even reported problems")),
+ /* deprecate -d option with --pretty=full*/
+ OPT_BOOL('d', "detailed" , &opt_detailed, _("Show detailed report")),
+ OPT_END()
+ };
+
+ parse_opts(argc, (char **)argv, program_options, program_usage_string);
+
+ GList *D_list = NULL;
+ if (optind < argc)
+ while (optind < argc)
+ D_list = g_list_append(D_list, xstrdup(argv[optind++]));
+
+ if (!D_list)
+ {
+ char *home = getenv("HOME");
+ if (home)
+ D_list = g_list_append(D_list, concat_path_file(home, ".abrt/spool"));
+ D_list = g_list_append(D_list, xstrdup((void*)DEBUG_DUMPS_DIR));
+ }
+
+ VERB2
+ {
+ log("Base directory");
+ for (GList *li = D_list; li; li = li->next)
+ 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);
+ }
+ print_crash_list(ci, opt_full, opt_detailed);
+ free_vector_of_problem_data(ci);
+ g_list_free(D_list);
+
+ return 0;
+}
+
+int cmd_info(int argc, const char **argv)
+{
+ const char *program_usage_string = _(
+ "\b info [options] [<dump-dir>]..."
+ );
+
+ static int opt_detailed;
+ struct options program_options[] = {
+ OPT__VERBOSE(&g_verbose),
+ OPT_GROUP(""),
+ /* deprecate -d option with --pretty=full*/
+ OPT_BOOL('d', "detailed" , &opt_detailed, _("Show detailed report")),
+ OPT_END()
+ };
+
+ parse_opts(argc, (char **)argv, program_options, program_usage_string);
+
+ if (optind < argc)
+ {
+ while (optind < argc)
+ {
+ const char *dump_dir = argv[optind++];
+ problem_data_t *problem = fill_crash_info(dump_dir);
+ if (!problem)
+ {
+ error_msg("no such problem directory '%s'", dump_dir);
+ continue;
+ }
+ print_crash(problem, opt_detailed);
+ free_problem_data(problem);
+ if (optind - argc)
+ printf("\n");
+ }
+ exit(0);
+ }
+
+ show_usage_and_die(program_usage_string, program_options);
+
+ return 0;
+}
diff --git a/src/cli/report.c b/src/cli/report.c
new file mode 100644
index 0000000..1d2ffbc
--- /dev/null
+++ b/src/cli/report.c
@@ -0,0 +1,43 @@
+/*
+ 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 "builtin-cmd.h"
+
+int cmd_report(int argc, const char **argv)
+{
+ const char *program_usage_string = _(
+ "\b report [options] [<dump-dir>]..."
+ );
+
+ struct options program_options[] = {
+ OPT__VERBOSE(&g_verbose),
+ OPT_END()
+ };
+
+ parse_opts(argc, (char **)argv, program_options, program_usage_string);
+ if (optind < argc)
+ while (optind < argc)
+ report_problem_in_dir(argv[optind++],
+ LIBREPORT_ANALYZE | LIBREPORT_NOWAIT);
+
+ show_usage_and_die(program_usage_string, program_options);
+
+ return 0;
+}
diff --git a/src/cli/rm.c b/src/cli/rm.c
new file mode 100644
index 0000000..eac01af
--- /dev/null
+++ b/src/cli/rm.c
@@ -0,0 +1,53 @@
+/*
+ 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 "builtin-cmd.h"
+
+/* TODO npajkovs:
+ * add -n, --dry-run
+ * add -q, --quite
+ */
+
+int cmd_rm(int argc, const char **argv)
+{
+ const char *program_usage_string = _(
+ "\b rm [options] [<dump-dir>]..."
+ );
+
+ struct options program_options[] = {
+ OPT__VERBOSE(&g_verbose),
+ OPT_END()
+ };
+
+ parse_opts(argc, (char **)argv, program_options, program_usage_string);
+ if (optind < argc)
+ {
+ int status;
+ while (optind < argc)
+ {
+ const char *rm_dir = argv[optind++];
+ status = delete_dump_dir_possibly_using_abrtd(rm_dir);
+ if (!status)
+ log("rm '%s'", rm_dir);
+ }
+ }
+
+ return 0;
+}
--
1.7.6.233.gd79bc
12 years, 9 months
[PATCH] rhbz#724999 - fix (null) in summary
by Nikola Pajkovsky
when you report selinux problem via libreport summary looks like
[abrt] (null): SELinux is preventing /usr/bin/abrt-dump-oops from 'open'
accesses on the file /var/log/messages.
(null) is name of the package, but it doesn't have any. Reasonable summary
is only from 'reason' file.
Signed-off-by: Nikola Pajkovsky <npajkovs(a)redhat.com>
---
src/plugins/rhbz.c | 27 ++++++++++++++++-----------
1 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/src/plugins/rhbz.c b/src/plugins/rhbz.c
index 0a4c28e..5b53465 100644
--- a/src/plugins/rhbz.c
+++ b/src/plugins/rhbz.c
@@ -307,20 +307,25 @@ int rhbz_new_bug(struct abrt_xmlrpc *ax, problem_data_t *problem_data,
FILENAME_TAINTED_SHORT);
struct strbuf *buf_summary = strbuf_new();
- strbuf_append_strf(buf_summary, "[abrt] %s", package);
-
- if (function != NULL && strlen(function) < 30)
- strbuf_append_strf(buf_summary, ": %s", function);
-
- if (reason != NULL)
- strbuf_append_strf(buf_summary, ": %s", reason);
-
- if (tainted_short && analyzer
- && (strcmp(analyzer, "Kerneloops") == 0))
+ if (analyzer && strcmp(analyzer, "libreport") == 0)
{
- strbuf_append_strf(buf_summary, ": TAINTED %s", tainted_short);
+ strbuf_append_str(buf_summary, reason);
}
+ else
+ {
+ strbuf_append_strf(buf_summary, "[abrt] %s", package);
+ if (function && strlen(function) < 30)
+ strbuf_append_strf(buf_summary, ": %s", function);
+ if (reason)
+ strbuf_append_strf(buf_summary, ": %s", reason);
+
+ if (tainted_short && analyzer
+ && (strcmp(analyzer, "Kerneloops") == 0))
+ {
+ strbuf_append_strf(buf_summary, ": TAINTED %s", tainted_short);
+ }
+ }
char *status_whiteboard = xasprintf("abrt_hash:%s", duphash);
char *bz_dsc = make_description_bz(problem_data);
--
1.7.6.233.gd79bc
12 years, 9 months
[PATCH 1/2] [abrt] bring back to live abrt-cli
by Nikola Pajkovsky
getting infos about crash, deleting dump dirs and invoking reporting belongs to
abrt.git (abrt-gui does it too)
abrt-cli uses commands now instead of switches for main purpose like deleting,
reporting and getting information about crash.
second steps will be to add aliases for commands. If aliases won't be set for
commands, then abbreviation for commands comes to play.
Usage string for abrt-cli:
abrt-cli [--version] [--base-dir=DUMP_DIR] <command> [<args>]
--base-dir - change base dir for dump directories
--version - print out version and die
commands are:
list
rm
report
Each command can take it's own arguments.
list command
------------
Usage: abrt-cli list [options] [<dump-dir>]...
-v, --verbose Be verbose
-f, --full List even reported problems
-d, --detailed Show detailed report
Maybe option --detail is better then --detailed
rm command
----------
Usage: abrt-cli rm [options] [<dump-dir>]...
-v, --verbose Be verbose
note that you can do abrt-cli rm /path/to/base/dir/cpp-* so wildcard is working
out of box
report command
--------------
Usage: abrt-cli report [options] [<dump-dir>]...
-v, --verbose Be verbose
simply invoke report_problem_in_dir
Signed-off-by: Nikola Pajkovsky <npajkovs(a)redhat.com>
---
.gitignore | 1 +
abrt.spec.in | 4 +-
configure.ac | 1 +
src/Makefile.am | 2 +-
src/cli/Makefile.am | 25 +++++
src/cli/abrt-cli.c | 144 +++++++++++++++++++++++++++++
src/cli/builtin-cmd.h | 28 ++++++
src/cli/list.c | 242 +++++++++++++++++++++++++++++++++++++++++++++++++
src/cli/report.c | 43 +++++++++
src/cli/rm.c | 53 +++++++++++
10 files changed, 540 insertions(+), 3 deletions(-)
create mode 100644 src/cli/Makefile.am
create mode 100644 src/cli/abrt-cli.c
create mode 100644 src/cli/builtin-cmd.h
create mode 100644 src/cli/list.c
create mode 100644 src/cli/report.c
create mode 100644 src/cli/rm.c
diff --git a/.gitignore b/.gitignore
index 745cb02..a60e543 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,6 +26,7 @@ src/hooks/abrt_exception_handler.py
src/hooks/abrt-hook-ccpp
src/applet/abrt-applet.desktop
src/gui-gtk/abrt.desktop
+src/cli/abrt-cli
# cscope files
cscope.*
diff --git a/abrt.spec.in b/abrt.spec.in
index 00e37d4..3334b70 100644
--- a/abrt.spec.in
+++ b/abrt.spec.in
@@ -185,8 +185,6 @@ mkdir -p $RPM_BUILD_ROOT/var/cache/abrt-di
mkdir -p $RPM_BUILD_ROOT/var/run/abrt
mkdir -p $RPM_BUILD_ROOT/var/spool/abrt
mkdir -p $RPM_BUILD_ROOT/var/spool/abrt-upload
-# compat before we split abrt-cli and report-cli
-ln -s %{_bindir}/report-cli $RPM_BUILD_ROOT/%{_bindir}/abrt-cli
desktop-file-install \
--dir ${RPM_BUILD_ROOT}%{_datadir}/applications \
@@ -429,6 +427,8 @@ gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :
%files cli
%defattr(-,root,root,-)
%{_bindir}/abrt-cli
+# provide asap
+#% {_mandir}/man1/report-cli.1.gz
%files desktop
%defattr(-,root,root,-)
diff --git a/configure.ac b/configure.ac
index 1726093..8de55d2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -138,6 +138,7 @@ AC_CONFIG_FILES([
src/hooks/Makefile
src/applet/Makefile
src/gui-gtk/Makefile
+ src/cli/Makefile
po/Makefile.in
icons/Makefile
])
diff --git a/src/Makefile.am b/src/Makefile.am
index b41b939..ab95ef7 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1 +1 @@
-SUBDIRS = include lib hooks daemon applet gui-gtk plugins
+SUBDIRS = include lib hooks daemon applet gui-gtk plugins cli
diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am
new file mode 100644
index 0000000..c5ebc14
--- /dev/null
+++ b/src/cli/Makefile.am
@@ -0,0 +1,25 @@
+-include ../../config.mak
+
+bin_PROGRAMS = abrt-cli
+
+CLI_C =
+CLI_C += abrt-cli.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_CFLAGS = \
+ -I$(srcdir)/../include \
+ -I$(srcdir)/../lib \
+ -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \
+ $(LIBREPORT_CFLAGS) \
+ -Wwrite-strings -Werror
+
+abrt_cli_LDADD = \
+ $(LIBREPORT_LIBS)
+
+DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
diff --git a/src/cli/abrt-cli.c b/src/cli/abrt-cli.c
new file mode 100644
index 0000000..ebc1620
--- /dev/null
+++ b/src/cli/abrt-cli.c
@@ -0,0 +1,144 @@
+/*
+ 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 "builtin-cmd.h"
+
+#define USAGE_OPTS_WIDTH 12
+#define USAGE_GAP 2
+
+/* TODO: add --pager(default) and --no-pager */
+
+const char abrt_cli_usage_string[] =
+ "abrt-cli [--version] <command> [<args>]";
+
+struct cmd_struct {
+ const char *cmd;
+ int (*fn)(int, const char **);
+ const char *help;
+};
+
+static void list_cmds_help(const struct cmd_struct *commands)
+{
+ for (const struct cmd_struct *p = commands; p->cmd; ++p)
+ {
+ size_t pos;
+ int pad;
+
+ pos = fprintf(stderr, " ");
+ pos += fprintf(stderr, "%s", p->cmd);
+
+ if (pos <= USAGE_OPTS_WIDTH)
+ pad = USAGE_OPTS_WIDTH - pos;
+ else
+ {
+ fputc('\n', stderr);
+ pad = USAGE_OPTS_WIDTH;
+ }
+
+ fprintf(stderr, "%*s%s\n", pad + USAGE_GAP, "", p->help);
+ }
+}
+
+static void handle_internal_options(int *argc, const char ***argv)
+{
+ while (*argc > 0)
+ {
+ const char *cmd = (*argv)[0];
+ if (cmd[0] != '-')
+ break;
+
+ if (strcmp(cmd, "--version") == 0)
+ {
+ puts(PACKAGE_VERSION);
+ exit(0);
+ }
+#if 0
+ else if (prefixcmp(cmd, "--base-dir=") == 0)
+ D_list = g_list_append(D_list, xstrdup(cmd + strlen("--base-dir=")));
+ else if (prefixcmp(cmd, "--list-events") == 0)
+ {
+ const char *pfx = cmd + strlen("--list-events");
+ if (pfx && *pfx)
+ pfx += 1; /* skip '=' */
+
+ char *events = list_possible_events(NULL, dump_dir_name, pfx);
+ if (!events)
+ exit(1); /* error msg is already logged */
+
+ fputs(events, stdout);
+ free(events);
+
+ exit(0);
+ }
+#endif
+ else
+ error_msg_and_die("usage: %s", abrt_cli_usage_string);
+
+ (*argv)++;
+ (*argc)--;
+ }
+}
+
+static void handle_internal_command(int argc, const char **argv,
+ const struct cmd_struct *commands)
+{
+ const char *cmd = argv[0];
+
+ for (const struct cmd_struct *p = commands; p->cmd; ++p)
+ {
+ if (strcmp(p->cmd, cmd))
+ continue;
+
+ exit(p->fn(argc, argv));
+ }
+}
+
+int main(int argc, const char **argv)
+{
+ abrt_init((char **)argv);
+
+ setlocale(LC_ALL, "");
+#if ENABLE_NLS
+ bindtextdomain(PACKAGE, LOCALEDIR);
+ textdomain(PACKAGE);
+#endif
+
+ argv++;
+ argc--;
+
+ const struct cmd_struct commands[] = {
+ {"list", cmd_list, _("List not yet reported problems")},
+ {"rm", cmd_rm, _("Remove files from problem directory")},
+ {"report", cmd_report, _("Analyze and report problem data in problem directory")},
+ {"info", cmd_info, _("Print information about DUMP_DIR")},
+ {NULL, NULL, NULL}
+ };
+
+ handle_internal_options(&argc, &argv);
+ if (argc > 0)
+ handle_internal_command(argc, argv, commands);
+
+ /* user didn't specify command; print out help */
+ printf("%s\n\n", abrt_cli_usage_string);
+ list_cmds_help(commands);
+ printf("\n%s\n", _("See 'abrt-cli <command> -h' for more information"));
+
+ return 0;
+}
diff --git a/src/cli/builtin-cmd.h b/src/cli/builtin-cmd.h
new file mode 100644
index 0000000..cea77d8
--- /dev/null
+++ b/src/cli/builtin-cmd.h
@@ -0,0 +1,28 @@
+/*
+ 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 _BUILTIN_CMD_H_
+#define _BUILTIN_CMD_H_
+
+extern int cmd_list(int argc, const char **argv);
+extern int cmd_rm(int argc, const char **argv);
+extern int cmd_report(int argc, const char **argv);
+extern int cmd_info(int argc, const char **argv);
+
+#endif /* _BUILTIN-CMD_H_ */
diff --git a/src/cli/list.c b/src/cli/list.c
new file mode 100644
index 0000000..833b4c7
--- /dev/null
+++ b/src/cli/list.c
@@ -0,0 +1,242 @@
+/*
+ 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 "builtin-cmd.h"
+
+/* TODO: npajkovs
+ * add --since
+ * add --until
+ * add --pretty=oneline|raw|normal|format="%a %b %c"
+ * add wildcard e.g. *-2011-04-01-10-* (list all problems in specific day)
+ *
+ * TODO?: remove base dir from list of crashes? is there a way that same crash can be in
+ * ~/.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)
+{
+ if (!problem_data)
+ return;
+
+ char *desc;
+ if (detailed)
+ {
+ int show_multiline = (detailed ? MAKEDESC_SHOW_MULTILINE : 0);
+ desc = make_description(problem_data,
+ /*names_to_skip:*/ NULL,
+ /*max_text_size:*/ CD_TEXT_ATT_SIZE,
+ MAKEDESC_SHOW_FILES | show_multiline);
+ }
+ else
+ {
+ desc = make_description(problem_data,
+ /*names_to_skip:*/ NULL,
+ /*max_text_size:*/ CD_TEXT_ATT_SIZE,
+ MAKEDESC_SHOW_ONLY_LIST);
+ }
+ fprintf(stdout, "%s", desc);
+ free(desc);
+}
+
+/**
+ * Prints a list containing "crashes" to stdout.
+ * @param include_reported
+ * Do not skip entries marked as already reported.
+ */
+static void print_crash_list(vector_of_problem_data_t *crash_list, int include_reported,
+ int detailed)
+{
+ unsigned i;
+ for (i = 0; i < crash_list->len; ++i)
+ {
+ problem_data_t *crash = get_problem_data(crash_list, i);
+ if (!include_reported)
+ {
+ const char *msg = get_problem_item_content_or_NULL(crash, FILENAME_REPORTED_TO);
+ if (msg)
+ continue;
+ }
+ print_crash(crash, detailed);
+ if (i != crash_list->len - 1)
+ printf("\n");
+ }
+}
+
+int cmd_list(int argc, const char **argv)
+{
+ const char *program_usage_string = _(
+ "\b list [options] [<dump-dir>]..."
+ );
+
+ static int opt_full, opt_detailed;
+ struct options program_options[] = {
+ OPT__VERBOSE(&g_verbose),
+ OPT_GROUP(""),
+ OPT_BOOL('f', "full" , &opt_full, _("List even reported problems")),
+ /* deprecate -d option with --pretty=full*/
+ OPT_BOOL('d', "detailed" , &opt_detailed, _("Show detailed report")),
+ OPT_END()
+ };
+
+ parse_opts(argc, (char **)argv, program_options, program_usage_string);
+
+ GList *D_list = NULL;
+ if (optind < argc)
+ while (optind < argc)
+ D_list = g_list_append(D_list, xstrdup(argv[optind++]));
+
+ if (!D_list)
+ {
+ char *home = getenv("HOME");
+ if (home)
+ D_list = g_list_append(D_list, concat_path_file(home, ".abrt/spool"));
+ D_list = g_list_append(D_list, xstrdup((void*)DEBUG_DUMPS_DIR));
+ }
+
+ VERB2
+ {
+ log("Base directory");
+ for (GList *li = D_list; li; li = li->next)
+ 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);
+ }
+ print_crash_list(ci, opt_full, opt_detailed);
+ free_vector_of_problem_data(ci);
+ g_list_free(D_list);
+
+ return 0;
+}
+
+int cmd_info(int argc, const char **argv)
+{
+ const char *program_usage_string = _(
+ "\b info [options] [<dump-dir>]..."
+ );
+
+ static int opt_detailed;
+ struct options program_options[] = {
+ OPT__VERBOSE(&g_verbose),
+ OPT_GROUP(""),
+ /* deprecate -d option with --pretty=full*/
+ OPT_BOOL('d', "detailed" , &opt_detailed, _("Show detailed report")),
+ OPT_END()
+ };
+
+ parse_opts(argc, (char **)argv, program_options, program_usage_string);
+
+ if (optind < argc)
+ {
+ while (optind < argc)
+ {
+ const char *dump_dir = argv[optind++];
+ problem_data_t *problem = fill_crash_info(dump_dir);
+ if (!problem)
+ {
+ error_msg("no such problem directory '%s'", dump_dir);
+ continue;
+ }
+ print_crash(problem, opt_detailed);
+ free_problem_data(problem);
+ if (optind - argc)
+ printf("\n");
+ }
+ exit(0);
+ }
+
+ show_usage_and_die(program_usage_string, program_options);
+
+ return 0;
+}
diff --git a/src/cli/report.c b/src/cli/report.c
new file mode 100644
index 0000000..1d2ffbc
--- /dev/null
+++ b/src/cli/report.c
@@ -0,0 +1,43 @@
+/*
+ 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 "builtin-cmd.h"
+
+int cmd_report(int argc, const char **argv)
+{
+ const char *program_usage_string = _(
+ "\b report [options] [<dump-dir>]..."
+ );
+
+ struct options program_options[] = {
+ OPT__VERBOSE(&g_verbose),
+ OPT_END()
+ };
+
+ parse_opts(argc, (char **)argv, program_options, program_usage_string);
+ if (optind < argc)
+ while (optind < argc)
+ report_problem_in_dir(argv[optind++],
+ LIBREPORT_ANALYZE | LIBREPORT_NOWAIT);
+
+ show_usage_and_die(program_usage_string, program_options);
+
+ return 0;
+}
diff --git a/src/cli/rm.c b/src/cli/rm.c
new file mode 100644
index 0000000..eac01af
--- /dev/null
+++ b/src/cli/rm.c
@@ -0,0 +1,53 @@
+/*
+ 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 "builtin-cmd.h"
+
+/* TODO npajkovs:
+ * add -n, --dry-run
+ * add -q, --quite
+ */
+
+int cmd_rm(int argc, const char **argv)
+{
+ const char *program_usage_string = _(
+ "\b rm [options] [<dump-dir>]..."
+ );
+
+ struct options program_options[] = {
+ OPT__VERBOSE(&g_verbose),
+ OPT_END()
+ };
+
+ parse_opts(argc, (char **)argv, program_options, program_usage_string);
+ if (optind < argc)
+ {
+ int status;
+ while (optind < argc)
+ {
+ const char *rm_dir = argv[optind++];
+ status = delete_dump_dir_possibly_using_abrtd(rm_dir);
+ if (!status)
+ log("rm '%s'", rm_dir);
+ }
+ }
+
+ return 0;
+}
--
1.7.6.233.gd79bc
12 years, 9 months
[PATCH] [libreport] honor minimal rating
by Nikola Pajkovsky
Signed-off-by: Nikola Pajkovsky <npajkovs(a)redhat.com>
---
src/cli/cli-report.c | 10 ++++------
src/gui-wizard-gtk/wizard.c | 39 ++++++++++++++++++++++++++++++---------
src/include/event_config.h | 1 +
src/lib/event_xml_parser.c | 20 ++++++++++++++++++++
4 files changed, 55 insertions(+), 15 deletions(-)
diff --git a/src/cli/cli-report.c b/src/cli/cli-report.c
index 6ec7f96..f203fad 100644
--- a/src/cli/cli-report.c
+++ b/src/cli/cli-report.c
@@ -752,7 +752,9 @@ int report(const char *dump_dir_name, int flags)
{
const char *rating_str = get_problem_item_content_or_NULL(problem_data, FILENAME_RATING);
//COMPAT, remove after 2.1 release
- if (!rating_str) rating_str = get_problem_item_content_or_NULL(problem_data, "rating");
+ if (!rating_str)
+ rating_str = get_problem_item_content_or_NULL(problem_data, "rating");
+
unsigned i, rating = rating_str ? xatou(rating_str) : 4;
GList *li;
char wanted_reporters[255];
@@ -781,11 +783,7 @@ int report(const char *dump_dir_name, int flags)
if (!is_number_in_string(i, wanted_reporters))
continue;
- /* TODO: npajkovs; not implemented yet */
- //const char *rating_required = get_map_string_item_or_NULL(single_plugin_settings, "RatingRequired");
- //if (rating_required
- // && string_to_bool(rating_required) == true
- if (rating < 3)
+ if (rating < config->ec_minimal_rating)
{
puts(_("Reporting disabled because the backtrace is unusable"));
diff --git a/src/gui-wizard-gtk/wizard.c b/src/gui-wizard-gtk/wizard.c
index 3eea380..47f8d41 100644
--- a/src/gui-wizard-gtk/wizard.c
+++ b/src/gui-wizard-gtk/wizard.c
@@ -1455,23 +1455,44 @@ static void check_bt_rating_and_allow_send(void)
//FIXME: say "no" to special casing!
if (analyzer && strcmp(analyzer, "Kerneloops") != 0)
{
- const char *rating = get_problem_item_content_or_NULL(g_cd, FILENAME_RATING);
+ const char *rating_str = get_problem_item_content_or_NULL(g_cd, FILENAME_RATING);
//COMPAT, remove after 2.1 release
- if (!rating) rating= get_problem_item_content_or_NULL(g_cd, "rating");
- if (rating) switch (*rating)
+ if (!rating_str)
+ rating_str = get_problem_item_content_or_NULL(g_cd, "rating");
+
+ if (!rating_str)
{
- case '4': /* bt is ok - no warning here */
- break;
- case '3': /* bt is usable, but not complete, so show a warning */
+ add_warning(_("Reporting disabled because the rating is missing."));
+ send = false;
+ warn = true;
+ }
+ else
+ {
+ char *endptr;
+ errno = 0;
+ long rating = strtol(rating_str, &endptr, 10);
+ if (errno != 0 || endptr == rating_str || *endptr != '\0')
+ {
+ add_warning(_("Reporting disabled because the rating does not contain a number '%s'."));
+ send = false;
+ warn = true;
+ }
+
+ event_config_t *cfg = get_event_config(g_reporter_events_selected);
+
+ if (rating == cfg->ec_minimal_rating) /* bt is usable, but not complete, so show a warning */
+ {
add_warning(_("The backtrace is incomplete, please make sure you provide the steps to reproduce."));
warn = true;
- break;
- default:
+ }
+
+ if (rating < cfg->ec_minimal_rating)
+ {
//FIXME: see CreporterAssistant: 394 for ideas
add_warning(_("Reporting disabled because the backtrace is unusable."));
send = false;
warn = true;
- break;
+ }
}
}
diff --git a/src/include/event_config.h b/src/include/event_config.h
index 6f9383c..bd599f9 100644
--- a/src/include/event_config.h
+++ b/src/include/event_config.h
@@ -76,6 +76,7 @@ typedef struct
char *ec_include_items_by_default;
char *ec_exclude_items_always;
bool ec_exclude_binary_items;
+ long ec_minimal_rating;
GList *options;
} event_config_t;
diff --git a/src/lib/event_xml_parser.c b/src/lib/event_xml_parser.c
index 5b5fdd7..5b011bb 100644
--- a/src/lib/event_xml_parser.c
+++ b/src/lib/event_xml_parser.c
@@ -30,6 +30,7 @@
//#define ACTION_ELEMENT "action"
#define NAME_ELEMENT "name"
#define DEFAULT_VALUE_ELEMENT "default-value"
+#define MINIMAL_RATING_ELEMENT "minimal-rating"
#define REQUIRES_ELEMENT "requires-items"
#define EXCL_BY_DEFAULT_ELEMENT "exclude-items-by-default"
@@ -400,6 +401,25 @@ static void text(GMarkupParseContext *context,
free(text_copy);
return;
}
+ if (strcmp(inner_element, MINIMAL_RATING_ELEMENT) == 0)
+ {
+ char *endptr;
+ errno = 0;
+ ui->ec_minimal_rating = strtol(text_copy, &endptr, 10);
+ if (errno != 0 || endptr == text_copy || *endptr != '\0')
+ {
+ log("invalid minimal-rating number '%s', set to default 4", text_copy);
+ ui->ec_minimal_rating = 4;
+ }
+
+ if (ui->ec_minimal_rating > 4)
+ ui->ec_minimal_rating = 4;
+
+ if (ui->ec_minimal_rating < 0)
+ ui->ec_minimal_rating = 0;
+
+ return;
+ }
}
free(text_copy);
}
--
1.7.6.233.gd79bc
12 years, 9 months