Signed-off-by: Nikola Pajkovsky npajkovs@redhat.com --- src/daemon/abrt.conf | 2 ++ src/hooks/abrt-install-ccpp-hook | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/daemon/abrt.conf b/src/daemon/abrt.conf index c9a4333..94672e2 100644 --- a/src/daemon/abrt.conf +++ b/src/daemon/abrt.conf @@ -8,3 +8,5 @@ # Max size for crash storage [MiB] or 0 for unlimited # MaxCrashReportsSize = 1000 + +DumpLocation = /var/spool/abrt diff --git a/src/hooks/abrt-install-ccpp-hook b/src/hooks/abrt-install-ccpp-hook index 12a443f..a245aa2 100755 --- a/src/hooks/abrt-install-ccpp-hook +++ b/src/hooks/abrt-install-ccpp-hook @@ -6,14 +6,24 @@ dry_run=false verbose=false
+DEFAULT_LOCATION=/var/spool/abrt + +DUMP_LOCATION=`cat /etc/abrt/abrt.conf | grep '^[ ]*DumpLocation'` +DUMP_LOCATION=${DUMP_LOCATION#*DumpLocation*=} +DUMP_LOCATION=${DUMP_LOCATION// /} + +if [ "$DUMP_LOCATION" = "" ]; then + DUMP_LOCATION=$DEFAULT_LOCATION +fi + PATTERN_FILE="/proc/sys/kernel/core_pattern" SAVED_PATTERN_DIR="/var/run/abrt" SAVED_PATTERN_FILE="/var/run/abrt/saved_core_pattern" HOOK_BIN="/usr/libexec/abrt-hook-ccpp" # Must match percent_specifiers[] order in abrt-hook-ccpp.c: -PATTERN="|$HOOK_BIN /var/spool/abrt %s %c %p %u %g %t %e" +PATTERN="|$HOOK_BIN $DUMP_LOCATION %s %c %p %u %g %t %e" # Same, but with bogus "executable name" parameter -PATTERN1="|$HOOK_BIN /var/spool/abrt %s %c %p %u %g %t e" +PATTERN1="|$HOOK_BIN $DUMP_LOCATION %s %c %p %u %g %t e"
# core_pipe_limit specifies how many dump_helpers can run at the same time # 0 - means unlimited, but it's not guaranteed that /proc/<pid> of crashing
Signed-off-by: Nikola Pajkovsky npajkovs@redhat.com --- .gitignore | 1 + configure.ac | 1 + src/hooks/Makefile.am | 2 +- src/hooks/abrt-install-ccpp-hook | 107 ----------------------------------- src/hooks/abrt-install-ccpp-hook.in | 107 +++++++++++++++++++++++++++++++++++ 5 files changed, 110 insertions(+), 108 deletions(-) delete mode 100755 src/hooks/abrt-install-ccpp-hook create mode 100755 src/hooks/abrt-install-ccpp-hook.in
diff --git a/.gitignore b/.gitignore index 2bd423a..f73aef0 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,7 @@ src/applet/abrt-applet
src/hooks/abrt_exception_handler.py src/hooks/abrt-hook-ccpp +src/hooks/abrt-install-ccpp-hook
src/applet/abrt-applet.desktop src/gui-gtk/abrt.desktop diff --git a/configure.ac b/configure.ac index 1726093..ded4b4e 100644 --- a/configure.ac +++ b/configure.ac @@ -136,6 +136,7 @@ AC_CONFIG_FILES([ src/Makefile src/daemon/Makefile src/hooks/Makefile + src/hooks/abrt-install-ccpp-hook src/applet/Makefile src/gui-gtk/Makefile po/Makefile.in diff --git a/src/hooks/Makefile.am b/src/hooks/Makefile.am index 95cd363..962e326 100644 --- a/src/hooks/Makefile.am +++ b/src/hooks/Makefile.am @@ -27,7 +27,7 @@ abrt_hook_ccpp_LDADD = \ $(LIBREPORT_LIBS)
python_PYTHON = abrt.pth abrt_exception_handler.py -EXTRA_DIST = abrt_exception_handler.py.in abrt-install-ccpp-hook $(man_MANS) +EXTRA_DIST = abrt_exception_handler.py.in abrt-install-ccpp-hook.in $(man_MANS)
CLEANFILES := $(notdir $(wildcard *~)) $(notdir $(wildcard *#)) $(notdir $(wildcard .#*)) $(notdir $(wildcard *.pyc))
diff --git a/src/hooks/abrt-install-ccpp-hook b/src/hooks/abrt-install-ccpp-hook deleted file mode 100755 index a245aa2..0000000 --- a/src/hooks/abrt-install-ccpp-hook +++ /dev/null @@ -1,107 +0,0 @@ -#!/bin/bash -# Install coredump handler which saves segfault data - -# For debugging - -dry_run=false -verbose=false - -DEFAULT_LOCATION=/var/spool/abrt - -DUMP_LOCATION=`cat /etc/abrt/abrt.conf | grep '^[ ]*DumpLocation'` -DUMP_LOCATION=${DUMP_LOCATION#*DumpLocation*=} -DUMP_LOCATION=${DUMP_LOCATION// /} - -if [ "$DUMP_LOCATION" = "" ]; then - DUMP_LOCATION=$DEFAULT_LOCATION -fi - -PATTERN_FILE="/proc/sys/kernel/core_pattern" -SAVED_PATTERN_DIR="/var/run/abrt" -SAVED_PATTERN_FILE="/var/run/abrt/saved_core_pattern" -HOOK_BIN="/usr/libexec/abrt-hook-ccpp" -# Must match percent_specifiers[] order in abrt-hook-ccpp.c: -PATTERN="|$HOOK_BIN $DUMP_LOCATION %s %c %p %u %g %t %e" -# Same, but with bogus "executable name" parameter -PATTERN1="|$HOOK_BIN $DUMP_LOCATION %s %c %p %u %g %t e" - -# core_pipe_limit specifies how many dump_helpers can run at the same time -# 0 - means unlimited, but it's not guaranteed that /proc/<pid> of crashing -# process will be available for dump_helper. -# 4 - means that 4 dump_helpers can run at the same time (the rest will also -# run, but they will fail to read /proc/<pid>). -# -# This should be enough for ABRT, we can miss some crashes, but what are -# the odds that more processes crash at the same time? And moreover, -# do people want to save EVERY ONE of the crashes when they have -# a crash storm? I don't think so. -# The value of 4 has been recommended by nhorman. -# -CORE_PIPE_LIMIT_FILE="/proc/sys/kernel/core_pipe_limit" -CORE_PIPE_LIMIT="4" - -start() { - cur=`cat "$PATTERN_FILE"` - cur_first=`printf "%s" "$cur" | sed 's/ .*//'` - - # Is there a %e (executable name) in old pattern anywhere? - if test x"${cur#.*%e}" = x"${cur}"; then - # No. Can use PATTERN with less risk of overflow - # on expansion (executable names can be LONG). - # Overflow would cause kernel to abort coredump. BAD. - PATTERN="$PATTERN1" - fi - - $verbose && printf "cur:'%s'\n" "$cur" - # Is it already installed? - if test x"$cur_first" != x"|$HOOK_BIN"; then # no - # It is not installed - mkdir -p -- "$SAVED_PATTERN_DIR" - printf "%s\n" "$cur" >"$SAVED_PATTERN_FILE" - # Install new handler - $verbose && printf "Installing to %s:'%s'\n" "$PATTERN_FILE" "$PATTERN" - $dry_run || echo "$PATTERN" >"$PATTERN_FILE" - - # Check core_pipe_limit and change it if it's 0, - # otherwise the abrt-hook-ccpp won't be able to read /proc/<pid> - # of the crashing process - if test x"`cat "$CORE_PIPE_LIMIT_FILE"`" = x"0"; then - echo "$CORE_PIPE_LIMIT" >"$CORE_PIPE_LIMIT_FILE" - fi - fi -} - -stop() { - if test -f "$SAVED_PATTERN_FILE"; then - $verbose && printf "Restoring to %s:'%s'\n" "$PATTERN_FILE" "`cat "$SAVED_PATTERN_FILE"`" - $dry_run || cat "$SAVED_PATTERN_FILE" >"$PATTERN_FILE" - fi -} - -status() { - cur=`cat "$PATTERN_FILE"` - cur_first=`printf "%s" "$cur" | sed 's/ .*//'` - # Is it already installed? - if test x"$cur_first" = x"|$HOOK_BIN"; then # yes - $verbose && printf "Installed\n" - return 0 - else - $verbose && printf "Not installed\n" - return 1 - fi -} - -case "$1" in -install) - start - ;; -uninstall) - stop - ;; -is-installed) - status - ;; -*) - echo $"Usage: $0 {install|uninstall|is-installed}" - return 2 -esac diff --git a/src/hooks/abrt-install-ccpp-hook.in b/src/hooks/abrt-install-ccpp-hook.in new file mode 100755 index 0000000..a245aa2 --- /dev/null +++ b/src/hooks/abrt-install-ccpp-hook.in @@ -0,0 +1,107 @@ +#!/bin/bash +# Install coredump handler which saves segfault data + +# For debugging + +dry_run=false +verbose=false + +DEFAULT_LOCATION=/var/spool/abrt + +DUMP_LOCATION=`cat /etc/abrt/abrt.conf | grep '^[ ]*DumpLocation'` +DUMP_LOCATION=${DUMP_LOCATION#*DumpLocation*=} +DUMP_LOCATION=${DUMP_LOCATION// /} + +if [ "$DUMP_LOCATION" = "" ]; then + DUMP_LOCATION=$DEFAULT_LOCATION +fi + +PATTERN_FILE="/proc/sys/kernel/core_pattern" +SAVED_PATTERN_DIR="/var/run/abrt" +SAVED_PATTERN_FILE="/var/run/abrt/saved_core_pattern" +HOOK_BIN="/usr/libexec/abrt-hook-ccpp" +# Must match percent_specifiers[] order in abrt-hook-ccpp.c: +PATTERN="|$HOOK_BIN $DUMP_LOCATION %s %c %p %u %g %t %e" +# Same, but with bogus "executable name" parameter +PATTERN1="|$HOOK_BIN $DUMP_LOCATION %s %c %p %u %g %t e" + +# core_pipe_limit specifies how many dump_helpers can run at the same time +# 0 - means unlimited, but it's not guaranteed that /proc/<pid> of crashing +# process will be available for dump_helper. +# 4 - means that 4 dump_helpers can run at the same time (the rest will also +# run, but they will fail to read /proc/<pid>). +# +# This should be enough for ABRT, we can miss some crashes, but what are +# the odds that more processes crash at the same time? And moreover, +# do people want to save EVERY ONE of the crashes when they have +# a crash storm? I don't think so. +# The value of 4 has been recommended by nhorman. +# +CORE_PIPE_LIMIT_FILE="/proc/sys/kernel/core_pipe_limit" +CORE_PIPE_LIMIT="4" + +start() { + cur=`cat "$PATTERN_FILE"` + cur_first=`printf "%s" "$cur" | sed 's/ .*//'` + + # Is there a %e (executable name) in old pattern anywhere? + if test x"${cur#.*%e}" = x"${cur}"; then + # No. Can use PATTERN with less risk of overflow + # on expansion (executable names can be LONG). + # Overflow would cause kernel to abort coredump. BAD. + PATTERN="$PATTERN1" + fi + + $verbose && printf "cur:'%s'\n" "$cur" + # Is it already installed? + if test x"$cur_first" != x"|$HOOK_BIN"; then # no + # It is not installed + mkdir -p -- "$SAVED_PATTERN_DIR" + printf "%s\n" "$cur" >"$SAVED_PATTERN_FILE" + # Install new handler + $verbose && printf "Installing to %s:'%s'\n" "$PATTERN_FILE" "$PATTERN" + $dry_run || echo "$PATTERN" >"$PATTERN_FILE" + + # Check core_pipe_limit and change it if it's 0, + # otherwise the abrt-hook-ccpp won't be able to read /proc/<pid> + # of the crashing process + if test x"`cat "$CORE_PIPE_LIMIT_FILE"`" = x"0"; then + echo "$CORE_PIPE_LIMIT" >"$CORE_PIPE_LIMIT_FILE" + fi + fi +} + +stop() { + if test -f "$SAVED_PATTERN_FILE"; then + $verbose && printf "Restoring to %s:'%s'\n" "$PATTERN_FILE" "`cat "$SAVED_PATTERN_FILE"`" + $dry_run || cat "$SAVED_PATTERN_FILE" >"$PATTERN_FILE" + fi +} + +status() { + cur=`cat "$PATTERN_FILE"` + cur_first=`printf "%s" "$cur" | sed 's/ .*//'` + # Is it already installed? + if test x"$cur_first" = x"|$HOOK_BIN"; then # yes + $verbose && printf "Installed\n" + return 0 + else + $verbose && printf "Not installed\n" + return 1 + fi +} + +case "$1" in +install) + start + ;; +uninstall) + stop + ;; +is-installed) + status + ;; +*) + echo $"Usage: $0 {install|uninstall|is-installed}" + return 2 +esac
Signed-off-by: Nikola Pajkovsky npajkovs@redhat.com --- src/hooks/abrt-install-ccpp-hook.in | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/hooks/abrt-install-ccpp-hook.in b/src/hooks/abrt-install-ccpp-hook.in index a245aa2..9c7df75 100755 --- a/src/hooks/abrt-install-ccpp-hook.in +++ b/src/hooks/abrt-install-ccpp-hook.in @@ -8,7 +8,7 @@ verbose=false
DEFAULT_LOCATION=/var/spool/abrt
-DUMP_LOCATION=`cat /etc/abrt/abrt.conf | grep '^[ ]*DumpLocation'` +DUMP_LOCATION=`cat @sysconfdir@/abrt/abrt.conf | grep '^[ ]*DumpLocation'` DUMP_LOCATION=${DUMP_LOCATION#*DumpLocation*=} DUMP_LOCATION=${DUMP_LOCATION// /}
Signed-off-by: Nikola Pajkovsky npajkovs@redhat.com --- src/hooks/abrt-install-ccpp-hook.in | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/hooks/abrt-install-ccpp-hook.in b/src/hooks/abrt-install-ccpp-hook.in index 9c7df75..b5fac3d 100755 --- a/src/hooks/abrt-install-ccpp-hook.in +++ b/src/hooks/abrt-install-ccpp-hook.in @@ -8,12 +8,17 @@ verbose=false
DEFAULT_LOCATION=/var/spool/abrt
-DUMP_LOCATION=`cat @sysconfdir@/abrt/abrt.conf | grep '^[ ]*DumpLocation'` -DUMP_LOCATION=${DUMP_LOCATION#*DumpLocation*=} -DUMP_LOCATION=${DUMP_LOCATION// /} +wspace='[ ]*' +DUMP_LOCATION=`grep "^${wspace}DumpLocation${wspace}=" @sysconfdir@/abrt/abrt.conf \ + | sed -e "s/^${wspace}DumpLocation${wspace}=${wspace}//" -e "s/${wspace}$//"`
-if [ "$DUMP_LOCATION" = "" ]; then +if [ x"$DUMP_LOCATION" = x"" ]; then DUMP_LOCATION=$DEFAULT_LOCATION +else + if [ x"${DUMP_LOCATION#* }" != x"$DUMP_LOCATION" ]; then + # DUMP_LOCATION has a space. + DUMP_LOCATION=$DEFAULT_LOCATION + fi fi
PATTERN_FILE="/proc/sys/kernel/core_pattern"
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@redhat.com --- abrt.spec.in | 4 +- configure.ac | 1 + src/Makefile.am | 2 +- src/cli/Makefile.am | 25 ++++++ src/cli/abrt-cli.c | 146 ++++++++++++++++++++++++++++++++++ src/cli/builtin-cmd.h | 27 +++++++ src/cli/list.c | 206 +++++++++++++++++++++++++++++++++++++++++++++++++ src/cli/report.c | 45 +++++++++++ src/cli/rm.c | 53 +++++++++++++ 9 files changed, 506 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/abrt.spec.in b/abrt.spec.in index fb8470a..31b6ba2 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 \ @@ -428,6 +426,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 ded4b4e..2bbacfc 100644 --- a/configure.ac +++ b/configure.ac @@ -139,6 +139,7 @@ AC_CONFIG_FILES([ src/hooks/abrt-install-ccpp-hook 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..79d17bb --- /dev/null +++ b/src/cli/abrt-cli.c @@ -0,0 +1,146 @@ +/* + 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 */ + +/* better way to set <base-dir> as environ variable? */ +GList *D_list = NULL; + +const char abrt_cli_usage_string[] = + "abrt-cli [--version] [--base-dir=DUMP_DIR] <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); + } + else if (prefixcmp(cmd, "--base-dir=") == 0) + D_list = g_list_append(D_list, xstrdup(cmd + strlen("--base-dir="))); +#if 0 + 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")}, + {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..28aa753 --- /dev/null +++ b/src/cli/builtin-cmd.h @@ -0,0 +1,27 @@ +/* + 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); + +#endif /* _BUILTIN-CMD_H_ */ diff --git a/src/cli/list.c b/src/cli/list.c new file mode 100644 index 0000000..bdb371f --- /dev/null +++ b/src/cli/list.c @@ -0,0 +1,206 @@ +/* + 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" + +extern GList *D_list; + +/* 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) +{ + 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); + } + fputs(desc, stdout); + 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; + } + puts(""); + print_crash(crash, detailed); + } +} + +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); + + if (optind < argc) + { + while (optind < argc) + { + problem_data_t *problem = fill_crash_info(argv[optind++]); + print_crash(problem, opt_detailed); + free_problem_data(problem); + printf("\n"); + } + exit(0); + } + + 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; +} diff --git a/src/cli/report.c b/src/cli/report.c new file mode 100644 index 0000000..8d9f006 --- /dev/null +++ b/src/cli/report.c @@ -0,0 +1,45 @@ +/* + 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); + log("report '%s'", argv[optind++]); + } + } + + 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; +}
Signed-off-by: Nikola Pajkovsky npajkovs@redhat.com --- .gitignore | 2 ++ configure.ac | 7 ------- src/applet/Makefile.am | 1 - src/cli/Makefile.am | 4 ++-- src/cli/list.c | 4 +++- src/daemon/Makefile.am | 3 --- src/daemon/abrt-server.c | 16 ++++++++++------ src/daemon/abrtd.c | 24 ++++++++++++------------ src/gui-gtk/Makefile.am | 4 ++-- src/gui-gtk/main.c | 5 +++-- src/hooks/Makefile.am | 1 - src/hooks/abrt-hook-ccpp.c | 24 ++++++++++++++++++++---- src/lib/Makefile.am | 7 ------- src/lib/abrt_conf.c | 14 +++++++++++++- src/lib/abrt_conf.h | 2 ++ src/lib/hooklib.c | 9 +++++---- src/lib/hooklib.h | 2 +- src/plugins/Makefile.am | 7 ------- 18 files changed, 75 insertions(+), 61 deletions(-)
diff --git a/.gitignore b/.gitignore index f73aef0..29856ab 100644 --- a/.gitignore +++ b/.gitignore @@ -39,6 +39,8 @@ src/hooks/abrt-install-ccpp-hook src/applet/abrt-applet.desktop src/gui-gtk/abrt.desktop
+src/cli/abrt-cli + # cscope files cscope.* ncscope.* diff --git a/configure.ac b/configure.ac index 2bbacfc..f702263 100644 --- a/configure.ac +++ b/configure.ac @@ -94,14 +94,8 @@ PLUGINS_LIB_DIR='${libdir}/${PACKAGE_NAME}' ENABLE_SOCKET_OR_DBUS='-DENABLE_DBUS=1' LIBEXEC_DIR='${libexecdir}'
-DEBUG_DUMPS_DIR='${localstatedir}/spool/${PACKAGE_NAME}' DEBUG_INFO_DIR='${localstatedir}/cache/${PACKAGE_NAME}-di'
-AC_ARG_WITH(debugdumpsdir, - [AS_HELP_STRING([--with-debugdumpdir=DIR], - [Directory where debugdumps are created])], - [DEBUG_DUMPS_DIR="$withval"]) - AC_ARG_WITH(debuginfosdir, [AS_HELP_STRING([--with-debuginfodir=DIR], [Directory where debuginfo is stored])], @@ -114,7 +108,6 @@ AC_SUBST(REPORT_PLUGINS_CONF_DIR) AC_SUBST(EVENTS_CONF_DIR) AC_SUBST(EVENTS_DIR) AC_SUBST(PLUGINS_LIB_DIR) -AC_SUBST(DEBUG_DUMPS_DIR) AC_SUBST(DEBUG_INFO_DIR) AC_SUBST(LIBEXEC_DIR)
diff --git a/src/applet/Makefile.am b/src/applet/Makefile.am index db5266d..247bee2 100644 --- a/src/applet/Makefile.am +++ b/src/applet/Makefile.am @@ -9,7 +9,6 @@ abrt_applet_CPPFLAGS = \ -DBIN_DIR="$(bindir)" \ -DVAR_RUN="$(VAR_RUN)" \ -DCONF_DIR="$(CONF_DIR)" \ - -DDEBUG_DUMPS_DIR="$(DEBUG_DUMPS_DIR)" \ -DPLUGINS_LIB_DIR="$(PLUGINS_LIB_DIR)" \ -DPLUGINS_CONF_DIR="$(PLUGINS_CONF_DIR)" \ -DICON_DIR="${datadir}/abrt/icons/hicolor/48x48/status" \ diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am index c5ebc14..bbd1402 100644 --- a/src/cli/Makefile.am +++ b/src/cli/Makefile.am @@ -15,11 +15,11 @@ 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) + $(LIBREPORT_LIBS) \ + ../lib/libabrt.la
DEFS = -DLOCALEDIR="$(localedir)" @DEFS@ diff --git a/src/cli/list.c b/src/cli/list.c index bdb371f..63b5e65 100644 --- a/src/cli/list.c +++ b/src/cli/list.c @@ -175,13 +175,15 @@ int cmd_list(int argc, const char **argv) exit(0); }
+ load_abrt_conf(); 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)); + D_list = g_list_append(D_list, xstrdup(g_settings_dump_location)); } + free_abrt_conf_data();
VERB2 { diff --git a/src/daemon/Makefile.am b/src/daemon/Makefile.am index 18d41b6..9770e56 100644 --- a/src/daemon/Makefile.am +++ b/src/daemon/Makefile.am @@ -23,7 +23,6 @@ abrtd_CPPFLAGS = \ -DBIN_DIR="$(bindir)" \ -DVAR_RUN="$(VAR_RUN)" \ -DCONF_DIR="$(CONF_DIR)" \ - -DDEBUG_DUMPS_DIR="$(DEBUG_DUMPS_DIR)" \ -DDEBUG_INFO_DIR="$(DEBUG_INFO_DIR)" \ -DPLUGINS_LIB_DIR="$(PLUGINS_LIB_DIR)" \ -DPLUGINS_CONF_DIR="$(PLUGINS_CONF_DIR)" \ @@ -47,7 +46,6 @@ abrt_server_CPPFLAGS = \ -DBIN_DIR="$(bindir)" \ -DVAR_RUN="$(VAR_RUN)" \ -DCONF_DIR="$(CONF_DIR)" \ - -DDEBUG_DUMPS_DIR="$(DEBUG_DUMPS_DIR)" \ -DDEBUG_INFO_DIR="$(DEBUG_INFO_DIR)" \ -DPLUGINS_LIB_DIR="$(PLUGINS_LIB_DIR)" \ -DPLUGINS_CONF_DIR="$(PLUGINS_CONF_DIR)" \ @@ -69,7 +67,6 @@ abrt_action_save_package_data_CPPFLAGS = \ -DVAR_RUN="$(VAR_RUN)" \ -DCONF_DIR="$(CONF_DIR)" \ -DLOCALSTATEDIR='"$(localstatedir)"' \ - -DDEBUG_DUMPS_DIR="$(DEBUG_DUMPS_DIR)" \ -DDEBUG_INFO_DIR="$(DEBUG_INFO_DIR)" \ -DPLUGINS_LIB_DIR="$(PLUGINS_LIB_DIR)" \ -DPLUGINS_CONF_DIR="$(PLUGINS_CONF_DIR)" \ diff --git a/src/daemon/abrt-server.c b/src/daemon/abrt-server.c index 20caaae..c86c5b1 100644 --- a/src/daemon/abrt-server.c +++ b/src/daemon/abrt-server.c @@ -100,7 +100,8 @@ static int create_debug_dump() This directory is renamed to final directory name after all files have been stored into it. */ - char *path = xasprintf(DEBUG_DUMPS_DIR"/%s-%s-%u.new", + char *path = xasprintf("%s/%s-%s-%u.new", + g_settings_dump_location, dir_basename, iso_date_string(NULL), pid); @@ -149,8 +150,8 @@ static int create_debug_dump() g_settings_nMaxCrashReportsSize += g_settings_nMaxCrashReportsSize / 4; if (g_settings_nMaxCrashReportsSize > 0) { - check_free_space(g_settings_nMaxCrashReportsSize); - trim_debug_dumps(DEBUG_DUMPS_DIR, g_settings_nMaxCrashReportsSize * (double)(1024*1024), path); + check_free_space(g_settings_nMaxCrashReportsSize, g_settings_dump_location); + trim_debug_dumps(g_settings_dump_location, g_settings_nMaxCrashReportsSize * (double)(1024*1024), path); }
free(path); @@ -161,15 +162,18 @@ static int create_debug_dump() /* Remove dump dir */ static int delete_path(const char *dump_dir_name) { - /* If doesn't start with "DEBUG_DUMPS_DIR/"... */ - if (strncmp(dump_dir_name, DEBUG_DUMPS_DIR"/", strlen(DEBUG_DUMPS_DIR"/")) != 0 + char *dump_location = xasprintf("%s/", g_settings_dump_location); + /* If doesn't start with "DUMP_LOCATION/"... */ + if (strncmp(dump_dir_name, dump_location, strlen(dump_location)) != 0 /* or contains "/." anywhere (-> might contain ".." component) */ - || strstr(dump_dir_name + strlen(DEBUG_DUMPS_DIR), "/.") + || strstr(dump_dir_name + strlen(g_settings_dump_location), "/.") ) { /* Then refuse to operate on it (someone is attacking us??) */ error_msg("Bad dump directory name '%s', not deleting", dump_dir_name); + free(dump_location); return 400; /* Bad Request */ } + free(dump_location);
struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) diff --git a/src/daemon/abrtd.c b/src/daemon/abrtd.c index 8a22ab8..f636115 100644 --- a/src/daemon/abrtd.c +++ b/src/daemon/abrtd.c @@ -290,7 +290,7 @@ static int is_crash_a_dup(const char *dump_dir_name, void *param)
/* Scan crash dumps looking for a dup */ //TODO: explain why this is safe wrt concurrent runs - DIR *dir = opendir(DEBUG_DUMPS_DIR); + DIR *dir = opendir(g_settings_dump_location); if (dir != NULL) { struct dirent *dent; @@ -301,7 +301,7 @@ static int is_crash_a_dup(const char *dump_dir_name, void *param)
int different; char *uid, *uuid; - char *dump_dir_name2 = concat_path_file(DEBUG_DUMPS_DIR, dent->d_name); + char *dump_dir_name2 = concat_path_file(g_settings_dump_location, dent->d_name);
if (strcmp(dump_dir_name, dump_dir_name2) == 0) goto next; /* we are never a dup of ourself */ @@ -518,7 +518,7 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin if (fork() == 0) { xchdir(dir); - execlp("abrt-handle-upload", "abrt-handle-upload", DEBUG_DUMPS_DIR, dir, name, (char*)NULL); + execlp("abrt-handle-upload", "abrt-handle-upload", g_settings_dump_location, dir, name, (char*)NULL); error_msg_and_die("Can't execute '%s'", "abrt-handle-upload"); } } @@ -543,13 +543,13 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin { char *worst_dir = NULL; while (g_settings_nMaxCrashReportsSize > 0 - && get_dirsize_find_largest_dir(DEBUG_DUMPS_DIR, &worst_dir, name) / (1024*1024) >= g_settings_nMaxCrashReportsSize + && get_dirsize_find_largest_dir(g_settings_dump_location, &worst_dir, name) / (1024*1024) >= g_settings_nMaxCrashReportsSize && worst_dir ) { - log("Size of '%s' >= %u MB, deleting '%s'", DEBUG_DUMPS_DIR, g_settings_nMaxCrashReportsSize, worst_dir); + log("Size of '%s' >= %u MB, deleting '%s'", g_settings_dump_location, g_settings_nMaxCrashReportsSize, worst_dir); send_dbus_sig_QuotaExceeded(_("The size of the report exceeded the quota. Please check system's MaxCrashReportsSize value in abrt.conf.")); /* deletes both directory and DB record */ - char *d = concat_path_file(DEBUG_DUMPS_DIR, worst_dir); + char *d = concat_path_file(g_settings_dump_location, worst_dir); free(worst_dir); worst_dir = NULL; delete_dump_dir(d); @@ -559,7 +559,7 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin
char *fullname = NULL; problem_data_t *problem_data = NULL; - fullname = concat_path_file(DEBUG_DUMPS_DIR, name); + fullname = concat_path_file(g_settings_dump_location, name); mw_result_t res = LoadDebugDump(fullname, &problem_data); const char *first = problem_data ? get_problem_item_content_or_NULL(problem_data, CD_DUMPDIR) : NULL; switch (res) @@ -693,9 +693,9 @@ static void sanitize_dump_dir_rights() * us with thousands of bogus or malicious dumps */ /* 07000 bits are setuid, setgit, and sticky, and they must be unset */ /* 00777 bits are usual "rwxrwxrwx" access rights */ - ensure_writable_dir(DEBUG_DUMPS_DIR, 0755, "abrt"); + ensure_writable_dir(g_settings_dump_location, 0755, "abrt"); /* debuginfo cache */ - ensure_writable_dir(DEBUG_INFO_DIR, 0775, "abrt"); + ensure_writable_dir(g_settings_dump_location, 0775, "abrt"); /* temp dir */ ensure_writable_dir(VAR_RUN"/abrt", 0755, "root"); } @@ -823,10 +823,10 @@ int main(int argc, char** argv) perror_msg_and_die("inotify_init failed"); close_on_exec_on(inotify_fd);
- /* Watching DEBUG_DUMPS_DIR for new files... */ - if (inotify_add_watch(inotify_fd, DEBUG_DUMPS_DIR, IN_CREATE | IN_MOVED_TO) < 0) + /* Watching 'g_settings_dump_location' for new files... */ + if (inotify_add_watch(inotify_fd, g_settings_dump_location, IN_CREATE | IN_MOVED_TO) < 0) { - perror_msg("inotify_add_watch failed on '%s'", DEBUG_DUMPS_DIR); + perror_msg("inotify_add_watch failed on '%s'", g_settings_dump_location); goto init_error; } if (g_settings_sWatchCrashdumpArchiveDir) diff --git a/src/gui-gtk/Makefile.am b/src/gui-gtk/Makefile.am index 5025082..a2bb755 100644 --- a/src/gui-gtk/Makefile.am +++ b/src/gui-gtk/Makefile.am @@ -9,7 +9,6 @@ abrt_gui_CFLAGS = \ -DBIN_DIR="$(bindir)" \ -DVAR_RUN="$(VAR_RUN)" \ -DCONF_DIR="$(CONF_DIR)" \ - -DDEBUG_DUMPS_DIR="$(DEBUG_DUMPS_DIR)" \ -DPLUGINS_LIB_DIR="$(PLUGINS_LIB_DIR)" \ -DPLUGINS_CONF_DIR="$(PLUGINS_CONF_DIR)" \ -DICON_DIR="${datadir}/abrt/icons/hicolor/48x48/status" \ @@ -25,7 +24,8 @@ abrt_gui_LDADD = \ -lglib-2.0 \ -lgthread-2.0 \ $(GTK_LIBS) \ - $(LIBREPORT_GTK_LIBS) + $(LIBREPORT_GTK_LIBS) \ + ../lib/libabrt.la # $(LIBNOTIFY_LIBS)
#test_report_SOURCES = \ diff --git a/src/gui-gtk/main.c b/src/gui-gtk/main.c index 541c297..e4aecbd 100644 --- a/src/gui-gtk/main.c +++ b/src/gui-gtk/main.c @@ -710,7 +710,6 @@ int main(int argc, char **argv) "\b [-vp] [DIR]...\n" "\n" "Shows list of ABRT dump directories in specified DIR(s)\n" - "(default DIRs: "DEBUG_DUMPS_DIR" $HOME/.abrt/spool)" ); enum { OPT_v = 1 << 0, @@ -728,8 +727,9 @@ int main(int argc, char **argv)
GtkWidget *main_window = create_main_window();
+ load_abrt_conf(); const char *default_dirs[] = { - "/var/spool/abrt", + g_settings_dump_location, NULL, NULL, }; @@ -766,5 +766,6 @@ int main(int argc, char **argv) /* Enter main loop */ gtk_main();
+ free_abrt_conf_data(); return 0; } diff --git a/src/hooks/Makefile.am b/src/hooks/Makefile.am index 962e326..a65fb91 100644 --- a/src/hooks/Makefile.am +++ b/src/hooks/Makefile.am @@ -14,7 +14,6 @@ abrt_hook_ccpp_SOURCES = \ abrt_hook_ccpp_CPPFLAGS = \ -I$(srcdir)/../include \ -I$(srcdir)/../lib \ - -DDEBUG_DUMPS_DIR="$(DEBUG_DUMPS_DIR)" \ -DCONF_DIR="$(CONF_DIR)" \ -DVAR_RUN="$(VAR_RUN)" \ -DPLUGINS_CONF_DIR="$(PLUGINS_CONF_DIR)" \ diff --git a/src/hooks/abrt-hook-ccpp.c b/src/hooks/abrt-hook-ccpp.c index ba79beb..5a5fe39 100644 --- a/src/hooks/abrt-hook-ccpp.c +++ b/src/hooks/abrt-hook-ccpp.c @@ -405,7 +405,6 @@ int main(int argc, char** argv)
/* Parse abrt.conf */ load_abrt_conf(); - free_abrt_conf_data(); /* can do this because we need only g_settings_nMaxCrashReportsSize */ /* x1.25: go a bit up, so that usual in-daemon trimming * kicks in first, and we don't "fight" with it: */ @@ -475,7 +474,7 @@ int main(int argc, char** argv) if (g_settings_nMaxCrashReportsSize > 0) { g_settings_nMaxCrashReportsSize += g_settings_nMaxCrashReportsSize / 4; - check_free_space(g_settings_nMaxCrashReportsSize); + check_free_space(g_settings_nMaxCrashReportsSize, g_settings_dump_location); }
char path[PATH_MAX]; @@ -502,6 +501,8 @@ int main(int argc, char** argv) error_msg("not dumping repeating crash in '%s'", executable); if (setting_MakeCompatCore) goto create_user_core; + + free_abrt_conf_data(); return 1; } } @@ -529,16 +530,21 @@ int main(int argc, char** argv) unlink(path); /* copyfd_eof logs the error including errno string, * but it does not log file name */ + free_abrt_conf_data(); error_msg_and_die("error saving coredump to %s", path); } log("saved core dump of pid %lu (%s) to %s (%llu bytes)", (long)pid, executable, path, (long long)core_size); + free_abrt_conf_data(); return 0; }
unsigned path_len = snprintf(path, sizeof(path), "%s/ccpp-%s-%lu.new", dddir, iso_date_string(NULL), (long)pid); if (path_len >= (sizeof(path) - sizeof("/"FILENAME_COREDUMP))) + { + free_abrt_conf_data(); return 1; + }
struct dump_dir *dd = dd_create(path, uid, 0640); if (dd) @@ -588,6 +594,7 @@ int main(int argc, char** argv) if (sz < 0 || fsync(dst_fd_binary) != 0) { unlink(path); + free_abrt_conf_data(); error_msg_and_die("error saving binary image to %s", path); } close(dst_fd_binary); @@ -606,7 +613,8 @@ int main(int argc, char** argv) unlink(core_basename); } errno = sv_errno; - perror_msg_and_die("Can't open '%s'", path); + free_abrt_conf_data(); + perror_msg_and_die("can't open '%s'", path); } fchown(abrt_core_fd, dd->dd_uid, dd->dd_gid);
@@ -636,6 +644,7 @@ int main(int argc, char** argv) } /* copyfd_sparse logs the error including errno string, * but it does not log file name */ + free_abrt_conf_data(); error_msg_and_die("error writing %s", path); } log("saved core dump of pid %lu (%s) to %s (%llu bytes)", (long)pid, executable, path, (long long)core_size); @@ -662,16 +671,20 @@ int main(int argc, char** argv) /* rhbz#539551: "abrt going crazy when crashing process is respawned" */ if (g_settings_nMaxCrashReportsSize > 0) { - trim_debug_dumps(DEBUG_DUMPS_DIR, g_settings_nMaxCrashReportsSize * (double)(1024*1024), path); + trim_debug_dumps(g_settings_dump_location, g_settings_nMaxCrashReportsSize * (double)(1024*1024), path); }
+ free_abrt_conf_data(); return 0; }
/* We didn't create abrt dump, but may need to create compat coredump */ create_user_core: if (user_core_fd < 0) + { + free_abrt_conf_data(); return 0; + }
off_t core_size = copyfd_size(STDIN_FILENO, user_core_fd, ulimit_c, COPYFD_SPARSE); if (core_size < 0 || fsync(user_core_fd) != 0) { @@ -679,15 +692,18 @@ int main(int argc, char** argv) perror_msg("error writing %s/%s", user_pwd, core_basename); xchdir(user_pwd); unlink(core_basename); + free_abrt_conf_data(); return 1; } if (ulimit_c == 0 || core_size > ulimit_c) { xchdir(user_pwd); unlink(core_basename); + free_abrt_conf_data(); return 1; } log("saved core dump of pid %lu to %s/%s (%llu bytes)", (long)pid, user_pwd, core_basename, (long long)core_size);
+ free_abrt_conf_data(); return 0; } diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index d9465b3..08c8749 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -19,7 +19,6 @@ libabrt_la_CPPFLAGS = \ -I$(srcdir)/../lib \ -DLOCALSTATEDIR='"$(localstatedir)"' \ -DVAR_RUN="$(VAR_RUN)" \ - -DDEBUG_DUMPS_DIR="$(DEBUG_DUMPS_DIR)" \ -DPLUGINS_LIB_DIR="$(PLUGINS_LIB_DIR)" \ -DPLUGINS_CONF_DIR="$(PLUGINS_CONF_DIR)" \ -DCONF_DIR="$(CONF_DIR)" \ @@ -32,9 +31,3 @@ libabrt_la_LDFLAGS = \ -version-info 0:1:0 libabrt_la_LIBADD = \ $(GLIB_LIBS) - -$(DESTDIR)/$(DEBUG_DUMPS_DIR): - $(mkdir_p) '$@' -# no need to chmod it here -#chmod 1777 '$@' -install-data-local: $(DESTDIR)/$(DEBUG_DUMPS_DIR) diff --git a/src/lib/abrt_conf.c b/src/lib/abrt_conf.c index be06c7f..a39ceec 100644 --- a/src/lib/abrt_conf.c +++ b/src/lib/abrt_conf.c @@ -20,12 +20,15 @@
char * g_settings_sWatchCrashdumpArchiveDir = NULL; unsigned int g_settings_nMaxCrashReportsSize = 1000; - +char * g_settings_dump_location = NULL;
void free_abrt_conf_data() { free(g_settings_sWatchCrashdumpArchiveDir); g_settings_sWatchCrashdumpArchiveDir = NULL; + + free(g_settings_dump_location); + g_settings_dump_location = NULL; }
static void ParseCommon(map_string_h *settings, const char *conf_filename) @@ -51,6 +54,15 @@ static void ParseCommon(map_string_h *settings, const char *conf_filename) g_hash_table_remove(settings, "MaxCrashReportsSize"); }
+ value = g_hash_table_lookup(settings, "DumpLocation"); + if (value) + { + g_settings_dump_location = xstrdup(value); + g_hash_table_remove(settings, "DumpLocation"); + } + else + g_settings_dump_location = xstrdup("/var/spool/abrt"); + GHashTableIter iter; char *name; /*char *value; - already declared */ diff --git a/src/lib/abrt_conf.h b/src/lib/abrt_conf.h index 14fc742..ccd3ca9 100644 --- a/src/lib/abrt_conf.h +++ b/src/lib/abrt_conf.h @@ -27,6 +27,8 @@ extern "C" { extern unsigned int g_settings_nMaxCrashReportsSize; #define g_settings_sWatchCrashdumpArchiveDir abrt_g_settings_sWatchCrashdumpArchiveDir extern char * g_settings_sWatchCrashdumpArchiveDir; +#define g_settings_dump_location abrt_g_settings_dump_location +extern char * g_settings_dump_location;
#define load_abrt_conf abrt_load_abrt_conf int load_abrt_conf(); diff --git a/src/lib/hooklib.c b/src/lib/hooklib.c index b5fcec2..7ded7f6 100644 --- a/src/lib/hooklib.c +++ b/src/lib/hooklib.c @@ -15,16 +15,17 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ + #include <sys/statvfs.h> #include "internal_libreport.h" #include "hooklib.h"
-void check_free_space(unsigned setting_MaxCrashReportsSize) +void check_free_space(unsigned setting_MaxCrashReportsSize, char *dump_location) { struct statvfs vfs; - if (statvfs(DEBUG_DUMPS_DIR, &vfs) != 0) + if (statvfs(dump_location, &vfs) != 0) { - perror_msg_and_die("statvfs('%s')", DEBUG_DUMPS_DIR); + perror_msg_and_die("statvfs('%s')", dump_location); }
/* Check that at least MaxCrashReportsSize/4 MBs are free */ @@ -34,7 +35,7 @@ void check_free_space(unsigned setting_MaxCrashReportsSize) unsigned long fs_free_mb_x4 = ((unsigned long long)vfs.f_bfree / (1024/4)) * vfs.f_bsize / 1024; if (fs_free_mb_x4 < setting_MaxCrashReportsSize) { - error_msg_and_die("aborting dump: only %luMiB is available on %s", fs_free_mb_x4 / 4, DEBUG_DUMPS_DIR); + error_msg_and_die("aborting dump: only %luMiB is available on %s", fs_free_mb_x4 / 4, dump_location); } }
diff --git a/src/lib/hooklib.h b/src/lib/hooklib.h index 1add7d0..0f2169f 100644 --- a/src/lib/hooklib.h +++ b/src/lib/hooklib.h @@ -23,7 +23,7 @@ extern "C" { #endif
#define check_free_space abrt_check_free_space -void check_free_space(unsigned setting_MaxCrashReportsSize); +void check_free_space(unsigned setting_MaxCrashReportsSize, char *dump_location);
#define trim_debug_dumps abrt_trim_debug_dumps void trim_debug_dumps(const char *dirname, double cap_size, const char *exclude_path); diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index 7eecb31..d86cc9a 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -90,7 +90,6 @@ abrt_dump_oops_CPPFLAGS = \ -DVAR_RUN="$(VAR_RUN)" \ -DCONF_DIR="$(CONF_DIR)" \ -DLOCALSTATEDIR='"$(localstatedir)"' \ - -DDEBUG_DUMPS_DIR="$(DEBUG_DUMPS_DIR)" \ -DDEBUG_INFO_DIR="$(DEBUG_INFO_DIR)" \ -DPLUGINS_LIB_DIR="$(PLUGINS_LIB_DIR)" \ -DPLUGINS_CONF_DIR="$(PLUGINS_CONF_DIR)" \ @@ -111,7 +110,6 @@ abrt_action_analyze_c_CPPFLAGS = \ -DVAR_RUN="$(VAR_RUN)" \ -DCONF_DIR="$(CONF_DIR)" \ -DLOCALSTATEDIR='"$(localstatedir)"' \ - -DDEBUG_DUMPS_DIR="$(DEBUG_DUMPS_DIR)" \ -DDEBUG_INFO_DIR="$(DEBUG_INFO_DIR)" \ -DPLUGINS_LIB_DIR="$(PLUGINS_LIB_DIR)" \ -DPLUGINS_CONF_DIR="$(PLUGINS_CONF_DIR)" \ @@ -131,7 +129,6 @@ abrt_action_analyze_python_CPPFLAGS = \ -DVAR_RUN="$(VAR_RUN)" \ -DCONF_DIR="$(CONF_DIR)" \ -DLOCALSTATEDIR='"$(localstatedir)"' \ - -DDEBUG_DUMPS_DIR="$(DEBUG_DUMPS_DIR)" \ -DDEBUG_INFO_DIR="$(DEBUG_INFO_DIR)" \ -DPLUGINS_LIB_DIR="$(PLUGINS_LIB_DIR)" \ -DPLUGINS_CONF_DIR="$(PLUGINS_CONF_DIR)" \ @@ -152,7 +149,6 @@ abrt_action_analyze_oops_CPPFLAGS = \ -DVAR_RUN="$(VAR_RUN)" \ -DCONF_DIR="$(CONF_DIR)" \ -DLOCALSTATEDIR='"$(localstatedir)"' \ - -DDEBUG_DUMPS_DIR="$(DEBUG_DUMPS_DIR)" \ -DDEBUG_INFO_DIR="$(DEBUG_INFO_DIR)" \ -DPLUGINS_LIB_DIR="$(PLUGINS_LIB_DIR)" \ -DPLUGINS_CONF_DIR="$(PLUGINS_CONF_DIR)" \ @@ -172,7 +168,6 @@ abrt_action_trim_files_CPPFLAGS = \ -DVAR_RUN="$(VAR_RUN)" \ -DCONF_DIR="$(CONF_DIR)" \ -DLOCALSTATEDIR='"$(localstatedir)"' \ - -DDEBUG_DUMPS_DIR="$(DEBUG_DUMPS_DIR)" \ -DDEBUG_INFO_DIR="$(DEBUG_INFO_DIR)" \ -DPLUGINS_LIB_DIR="$(PLUGINS_LIB_DIR)" \ -DPLUGINS_CONF_DIR="$(PLUGINS_CONF_DIR)" \ @@ -193,7 +188,6 @@ abrt_action_generate_backtrace_CPPFLAGS = \ -DVAR_RUN="$(VAR_RUN)" \ -DCONF_DIR="$(CONF_DIR)" \ -DLOCALSTATEDIR='"$(localstatedir)"' \ - -DDEBUG_DUMPS_DIR="$(DEBUG_DUMPS_DIR)" \ -DDEBUG_INFO_DIR="$(DEBUG_INFO_DIR)" \ -DPLUGINS_LIB_DIR="$(PLUGINS_LIB_DIR)" \ -DPLUGINS_CONF_DIR="$(PLUGINS_CONF_DIR)" \ @@ -213,7 +207,6 @@ abrt_action_analyze_backtrace_CPPFLAGS = \ -DVAR_RUN="$(VAR_RUN)" \ -DCONF_DIR="$(CONF_DIR)" \ -DLOCALSTATEDIR='"$(localstatedir)"' \ - -DDEBUG_DUMPS_DIR="$(DEBUG_DUMPS_DIR)" \ -DDEBUG_INFO_DIR="$(DEBUG_INFO_DIR)" \ -DPLUGINS_LIB_DIR="$(PLUGINS_LIB_DIR)" \ -DPLUGINS_CONF_DIR="$(PLUGINS_CONF_DIR)" \
crash-catcher@lists.fedorahosted.org