summaryrefslogtreecommitdiffstats
path: root/src/Hooks
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-11-26 12:04:13 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2009-11-26 12:04:13 +0100
commit0db8836cb63f60799ac7b4c5222ba9e12ca5659c (patch)
treeda5189263bae7a4ed6de98ee513cd5be4631b59e /src/Hooks
parentec91a4cc4decd1ffd8ba2f3d0139239b0a0dd022 (diff)
downloadabrt-0db8836cb63f60799ac7b4c5222ba9e12ca5659c.tar.gz
abrt-0db8836cb63f60799ac7b4c5222ba9e12ca5659c.tar.xz
abrt-0db8836cb63f60799ac7b4c5222ba9e12ca5659c.zip
hookCCpp: check total dump dir size and delete the largest/oldest one
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'src/Hooks')
-rw-r--r--src/Hooks/CCpp.cpp55
-rw-r--r--src/Hooks/Makefile.am2
2 files changed, 55 insertions, 2 deletions
diff --git a/src/Hooks/CCpp.cpp b/src/Hooks/CCpp.cpp
index 138d0d66..de74bdf9 100644
--- a/src/Hooks/CCpp.cpp
+++ b/src/Hooks/CCpp.cpp
@@ -29,6 +29,8 @@
#define VAR_RUN_PID_FILE VAR_RUN"/abrt.pid"
+using namespace std;
+
static char* get_executable(pid_t pid)
{
char buf[PATH_MAX + 1];
@@ -282,9 +284,58 @@ int main(int argc, char** argv)
* but it does not log file name */
error_msg_and_die("error saving coredump to %s", path);
}
- /* free(executable); - why bother? */
- /* free(cmdline); */
+ free(executable);
+ free(cmdline);
log("saved core dump of pid %u to %s (%llu bytes)", (int)pid, path, (long long)size);
+ path[len] = '\0'; /* path now contains directory name */
+
+ /* We close dumpdir before we start catering for crash storm case.
+ * Otherwise, delete_debug_dump_dir's from other concurrent
+ * CCpp's won't be able to delete our dump (their delete_debug_dump_dir
+ * will wait for us), and we won't be able to delete their dumps.
+ * Classic deadlock.
+ */
+ dd.Close();
+
+ /* Get it from abrt.conf */
+ unsigned setting_MaxCrashReportsSize = 0;
+ FILE *fp = fopen(CONF_DIR"/abrt.conf", "r");
+ if (fp)
+ {
+ char line[256];
+ while (fgets(line, sizeof(line), fp) != NULL)
+ {
+ const char *p = skip_whitespace(line);
+ if (strncmp(p, "MaxCrashReportsSize", sizeof("MaxCrashReportsSize")-1) == 0)
+ {
+ p = skip_whitespace(p + sizeof("MaxCrashReportsSize")-1);
+ if (*p != '=')
+ continue;
+ p = skip_whitespace(p + 1);
+ if (isdigit(*p))
+ setting_MaxCrashReportsSize = (unsigned long)atoi(p);
+ continue;
+ }
+ /* add more 'if (strncmp(p, "xx", sizeof("xx")-1) == 0)' here... */
+ }
+ fclose(fp);
+ }
+ if (setting_MaxCrashReportsSize > 0)
+ {
+ string worst_dir;
+ while (1)
+ {
+ const char *base_dirname = strrchr(path, '/') + 1; /* never NULL */
+ /* We exclude our own dump from candidates for deletion (3rd param): */
+ double dirsize = get_dirsize_find_largest_dir(DEBUG_DUMPS_DIR, &worst_dir, base_dirname);
+ if (dirsize / (1024*1024) < setting_MaxCrashReportsSize || worst_dir == "")
+ break;
+ log("Size of '%s' >= %u MB, deleting '%s'", DEBUG_DUMPS_DIR, setting_MaxCrashReportsSize, worst_dir.c_str());
+ delete_debug_dump_dir(concat_path_file(DEBUG_DUMPS_DIR, worst_dir.c_str()).c_str());
+ worst_dir = "";
+ }
+ }
+
return 0;
}
catch (CABRTException& e)
diff --git a/src/Hooks/Makefile.am b/src/Hooks/Makefile.am
index 026d4cf7..c643b248 100644
--- a/src/Hooks/Makefile.am
+++ b/src/Hooks/Makefile.am
@@ -8,6 +8,7 @@ hookCCpp_CPPFLAGS = \
-I$(srcdir)/../../inc \
-I$(srcdir)/../../lib/Utils \
-DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \
+ -DCONF_DIR=\"$(CONF_DIR)\" \
-DVAR_RUN=\"$(VAR_RUN)\" \
-D_GNU_SOURCE
hookCCpp_LDADD = \
@@ -38,6 +39,7 @@ abrt_pyhook_helper_CPPFLAGS = \
-I$(srcdir)/../../inc \
-I$(srcdir)/../../lib/Utils \
-DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \
+ -DCONF_DIR=\"$(CONF_DIR)\" \
-DVAR_RUN=\"$(VAR_RUN)\" \
-D_GNU_SOURCE
abrt_pyhook_helper_LDADD = \