From 94a67f5d3edd6ac842cc3d7feea9e1954ee58a37 Mon Sep 17 00:00:00 2001 From: Karel Klic Date: Tue, 4 May 2010 14:30:16 +0200 Subject: Move hooklib from src/Hooks to lib/Utils --- lib/Utils/Makefile.am | 3 +- lib/Utils/hooklib.cpp | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/Utils/hooklib.h | 21 +++++++++ src/Hooks/Makefile.am | 11 ++--- src/Hooks/hooklib.cpp | 122 -------------------------------------------------- src/Hooks/hooklib.h | 21 --------- 6 files changed, 148 insertions(+), 152 deletions(-) create mode 100644 lib/Utils/hooklib.cpp create mode 100644 lib/Utils/hooklib.h delete mode 100644 src/Hooks/hooklib.cpp delete mode 100644 src/Hooks/hooklib.h diff --git a/lib/Utils/Makefile.am b/lib/Utils/Makefile.am index 13144f68..f9979ec0 100644 --- a/lib/Utils/Makefile.am +++ b/lib/Utils/Makefile.am @@ -26,7 +26,8 @@ libABRTUtils_la_SOURCES = \ ABRTException.cpp \ backtrace.h backtrace.c \ backtrace_parser.y \ - strbuf.h strbuf.c + strbuf.h strbuf.c \ + hooklib.h hooklib.cpp libABRTUtils_la_CPPFLAGS = \ -Wall -Werror \ -I$(srcdir)/../../inc \ diff --git a/lib/Utils/hooklib.cpp b/lib/Utils/hooklib.cpp new file mode 100644 index 00000000..a722ef5f --- /dev/null +++ b/lib/Utils/hooklib.cpp @@ -0,0 +1,122 @@ +/* + Copyright (C) 2009 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 "hooklib.h" +#include "DebugDump.h" +#include + +using namespace std; + +void parse_conf(const char *additional_conf, unsigned *setting_MaxCrashReportsSize, bool *setting_MakeCompatCore) +{ + FILE *fp = fopen(CONF_DIR"/abrt.conf", "r"); + if (!fp) + return; + + char line[256]; + while (1) + { + if (fgets(line, sizeof(line), fp) == NULL) + { + fclose(fp); + if (additional_conf) + { + /* Next .conf file plz */ + fp = fopen(additional_conf, "r"); + if (fp) + { + additional_conf = NULL; + continue; + } + } + break; + } + + strchrnul(line, '\n')[0] = '\0'; + const char *p = skip_whitespace(line); +#undef DIRECTIVE +#define DIRECTIVE "MaxCrashReportsSize" + if (setting_MaxCrashReportsSize && strncmp(p, DIRECTIVE, sizeof(DIRECTIVE)-1) == 0) + { + p = skip_whitespace(p + sizeof(DIRECTIVE)-1); + if (*p != '=') + continue; + p = skip_whitespace(p + 1); + if (isdigit(*p)) + { + /* x1.25: go a bit up, so that usual in-daemon trimming + * kicks in first, and we don't "fight" with it. */ + *setting_MaxCrashReportsSize = (unsigned long)xatou(p) * 5 / 4; + } + continue; + } +#undef DIRECTIVE +#define DIRECTIVE "MakeCompatCore" + if (setting_MakeCompatCore && strncmp(p, DIRECTIVE, sizeof(DIRECTIVE)-1) == 0) + { + p = skip_whitespace(p + sizeof(DIRECTIVE)-1); + if (*p != '=') + continue; + p = skip_whitespace(p + 1); + *setting_MakeCompatCore = string_to_bool(p); + continue; + } +#undef DIRECTIVE + /* add more 'if (strncmp(p, DIRECTIVE, sizeof(DIRECTIVE)-1) == 0)' here... */ + } +} + +void check_free_space(unsigned setting_MaxCrashReportsSize) +{ + struct statvfs vfs; + if (statvfs(DEBUG_DUMPS_DIR, &vfs) != 0) + { + perror_msg_and_die("statvfs('%s')", DEBUG_DUMPS_DIR); + } + + /* Check that at least MaxCrashReportsSize/4 MBs are free */ + + /* fs_free_mb_x4 ~= vfs.f_bfree * vfs.f_bsize * 4, expressed in MBytes. + * Need to neither overflow nor round f_bfree down too much. */ + 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\n", fs_free_mb_x4 / 4, DEBUG_DUMPS_DIR); + } +} + +/* rhbz#539551: "abrt going crazy when crashing process is respawned". + * Check total size of dump dir, if it overflows, + * delete oldest/biggest dumps. + */ +void trim_debug_dumps(unsigned setting_MaxCrashReportsSize, const char *exclude_path) +{ + int count = 10; + string worst_dir; + while (--count >= 0) + { + const char *base_dirname = strrchr(exclude_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 = ""; + } +} diff --git a/lib/Utils/hooklib.h b/lib/Utils/hooklib.h new file mode 100644 index 00000000..0794ff60 --- /dev/null +++ b/lib/Utils/hooklib.h @@ -0,0 +1,21 @@ +/* + Copyright (C) 2009 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. +*/ + +void parse_conf(const char *additional_conf, unsigned *setting_MaxCrashReportsSize, bool *setting_MakeCompatCore); +void check_free_space(unsigned setting_MaxCrashReportsSize); +void trim_debug_dumps(unsigned setting_MaxCrashReportsSize, const char *exclude_path); diff --git a/src/Hooks/Makefile.am b/src/Hooks/Makefile.am index 6845c72c..ef4ab821 100644 --- a/src/Hooks/Makefile.am +++ b/src/Hooks/Makefile.am @@ -2,9 +2,7 @@ libexec_PROGRAMS = abrt-hook-ccpp abrt-hook-python bin_PROGRAMS = dumpoops # abrt-hook-ccpp -abrt_hook_ccpp_SOURCES = \ - abrt-hook-ccpp.cpp \ - hooklib.h hooklib.cpp +abrt_hook_ccpp_SOURCES = abrt-hook-ccpp.cpp abrt_hook_ccpp_CPPFLAGS = \ -I$(srcdir)/../../inc \ -I$(srcdir)/../../lib/Utils \ @@ -16,8 +14,7 @@ abrt_hook_ccpp_LDADD = \ ../../lib/Utils/libABRTUtils.la # dumpoops -dumpoops_SOURCES = \ - dumpoops.cpp +dumpoops_SOURCES = dumpoops.cpp dumpoops_CPPFLAGS = \ -I$(srcdir)/../../inc \ -I$(srcdir)/../../lib/Utils \ @@ -34,9 +31,7 @@ dumpoops_LDADD = \ ../../lib/Utils/libABRTdUtils.la # abrt-hook-python -abrt_hook_python_SOURCES = \ - abrt-hook-python.cpp \ - hooklib.h hooklib.cpp +abrt_hook_python_SOURCES = abrt-hook-python.cpp abrt_hook_python_CPPFLAGS = \ -I$(srcdir)/../../inc \ -I$(srcdir)/../../lib/Utils \ diff --git a/src/Hooks/hooklib.cpp b/src/Hooks/hooklib.cpp deleted file mode 100644 index a722ef5f..00000000 --- a/src/Hooks/hooklib.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* - Copyright (C) 2009 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 "hooklib.h" -#include "DebugDump.h" -#include - -using namespace std; - -void parse_conf(const char *additional_conf, unsigned *setting_MaxCrashReportsSize, bool *setting_MakeCompatCore) -{ - FILE *fp = fopen(CONF_DIR"/abrt.conf", "r"); - if (!fp) - return; - - char line[256]; - while (1) - { - if (fgets(line, sizeof(line), fp) == NULL) - { - fclose(fp); - if (additional_conf) - { - /* Next .conf file plz */ - fp = fopen(additional_conf, "r"); - if (fp) - { - additional_conf = NULL; - continue; - } - } - break; - } - - strchrnul(line, '\n')[0] = '\0'; - const char *p = skip_whitespace(line); -#undef DIRECTIVE -#define DIRECTIVE "MaxCrashReportsSize" - if (setting_MaxCrashReportsSize && strncmp(p, DIRECTIVE, sizeof(DIRECTIVE)-1) == 0) - { - p = skip_whitespace(p + sizeof(DIRECTIVE)-1); - if (*p != '=') - continue; - p = skip_whitespace(p + 1); - if (isdigit(*p)) - { - /* x1.25: go a bit up, so that usual in-daemon trimming - * kicks in first, and we don't "fight" with it. */ - *setting_MaxCrashReportsSize = (unsigned long)xatou(p) * 5 / 4; - } - continue; - } -#undef DIRECTIVE -#define DIRECTIVE "MakeCompatCore" - if (setting_MakeCompatCore && strncmp(p, DIRECTIVE, sizeof(DIRECTIVE)-1) == 0) - { - p = skip_whitespace(p + sizeof(DIRECTIVE)-1); - if (*p != '=') - continue; - p = skip_whitespace(p + 1); - *setting_MakeCompatCore = string_to_bool(p); - continue; - } -#undef DIRECTIVE - /* add more 'if (strncmp(p, DIRECTIVE, sizeof(DIRECTIVE)-1) == 0)' here... */ - } -} - -void check_free_space(unsigned setting_MaxCrashReportsSize) -{ - struct statvfs vfs; - if (statvfs(DEBUG_DUMPS_DIR, &vfs) != 0) - { - perror_msg_and_die("statvfs('%s')", DEBUG_DUMPS_DIR); - } - - /* Check that at least MaxCrashReportsSize/4 MBs are free */ - - /* fs_free_mb_x4 ~= vfs.f_bfree * vfs.f_bsize * 4, expressed in MBytes. - * Need to neither overflow nor round f_bfree down too much. */ - 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\n", fs_free_mb_x4 / 4, DEBUG_DUMPS_DIR); - } -} - -/* rhbz#539551: "abrt going crazy when crashing process is respawned". - * Check total size of dump dir, if it overflows, - * delete oldest/biggest dumps. - */ -void trim_debug_dumps(unsigned setting_MaxCrashReportsSize, const char *exclude_path) -{ - int count = 10; - string worst_dir; - while (--count >= 0) - { - const char *base_dirname = strrchr(exclude_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 = ""; - } -} diff --git a/src/Hooks/hooklib.h b/src/Hooks/hooklib.h deleted file mode 100644 index 0794ff60..00000000 --- a/src/Hooks/hooklib.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - Copyright (C) 2009 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. -*/ - -void parse_conf(const char *additional_conf, unsigned *setting_MaxCrashReportsSize, bool *setting_MakeCompatCore); -void check_free_space(unsigned setting_MaxCrashReportsSize); -void trim_debug_dumps(unsigned setting_MaxCrashReportsSize, const char *exclude_path); -- cgit