From 816f3e001271ed8ab7fdadb6d90aeb2c61362dac Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 8 Dec 2010 14:51:47 +0100 Subject: removal of C++isms from libabrt, part 1 This patch converts libabrt usage of C++ map to a glib-based container, GHashTable. It is typedef-ed to map_string_h. We can't typedef it to map_string_t, since other parts of ABRT (daemon, cli) still use that name for C++ container. Also, exceptions are removed everywhere. Signed-off-by: Denys Vlasenko --- src/plugins/CCpp.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/plugins/CCpp.cpp') diff --git a/src/plugins/CCpp.cpp b/src/plugins/CCpp.cpp index e6807ea7..11968349 100644 --- a/src/plugins/CCpp.cpp +++ b/src/plugins/CCpp.cpp @@ -21,7 +21,6 @@ #include #include "abrtlib.h" #include "CCpp.h" -#include "abrt_exception.h" #include "comm_layer_inner.h" using namespace std; -- cgit From def39238640489b41da5cdc8fd4a83d16d49fcc7 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 8 Dec 2010 15:03:24 +0100 Subject: removal of C++isms from libabrt, part 2 This patch rewrites a few places where we use C++ strings Signed-off-by: Denys Vlasenko --- src/plugins/CCpp.cpp | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'src/plugins/CCpp.cpp') diff --git a/src/plugins/CCpp.cpp b/src/plugins/CCpp.cpp index 11968349..19860290 100644 --- a/src/plugins/CCpp.cpp +++ b/src/plugins/CCpp.cpp @@ -258,17 +258,6 @@ void CAnalyzerCCpp::SetSettings(const map_plugin_settings_t& pSettings) } } -//ok to delete? -//const map_plugin_settings_t& CAnalyzerCCpp::GetSettings() -//{ -// m_pSettings["MemoryMap"] = m_bMemoryMap ? "yes" : "no"; -// m_pSettings["DebugInfo"] = m_sDebugInfo; -// m_pSettings["DebugInfoCacheMB"] = to_string(m_nDebugInfoCacheMB); -// m_pSettings["InstallDebugInfo"] = m_bInstallDebugInfo ? "yes" : "no"; -// -// return m_pSettings; -//} - PLUGIN_INFO(ANALYZER, CAnalyzerCCpp, "CCpp", -- cgit From dc3c5b79ba1ee6fd7a98842fde43d072e004f93b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 8 Dec 2010 16:07:31 +0100 Subject: add abrt_ prefixes to abrt-internal functions in libabrt.so Signed-off-by: Denys Vlasenko --- src/plugins/CCpp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins/CCpp.cpp') diff --git a/src/plugins/CCpp.cpp b/src/plugins/CCpp.cpp index 19860290..d88a593d 100644 --- a/src/plugins/CCpp.cpp +++ b/src/plugins/CCpp.cpp @@ -240,7 +240,7 @@ void CAnalyzerCCpp::SetSettings(const map_plugin_settings_t& pSettings) it = pSettings.find("GdbTimeoutSec"); if (it != end) { - m_nGdbTimeoutSec = xatoi_u(it->second.c_str()); + m_nGdbTimeoutSec = xatoi_positive(it->second.c_str()); } it = pSettings.find("InstallDebugInfo"); if (it == end) //compat, remove after 0.0.11 -- cgit From d108d7d2fbe0b178110295fd8335c258f699a5d4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 6 Jan 2011 16:18:09 +0100 Subject: pass old pattern to ccpp hook and use it abrtd: instead of "|/usr/libexec/abrt-ccpp-hook DEBUG_DUMPS_DIR %p %s %u %c", sets coredump handler to "|/usr/libexec/abrt-ccpp-hook DEBUG_DUMPS_DIR %s %c %p %u %g %t %h %e OLD_PATTERN" abrt-ccpp-hook: expands OLD_PATTERN using values of %s %c %p %u %g %t %h %e and uses it as a name of "compat coredump". Patch has a feature which prevents usage of kernel-truncated OLD_PATTERN: it is passed as hex string *with terminating NUL* (encoded as 00). If ccpp hook doesn't see 00, it refuses to use OLD_PATTERN and uses string "core" instead. Run tested. On a new kernel, passes up to 27 char long old pattern. Longer patterns are still truncated. This may be improved in future kernels. Signed-off-by: Denys Vlasenko --- src/plugins/CCpp.cpp | 55 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 11 deletions(-) (limited to 'src/plugins/CCpp.cpp') diff --git a/src/plugins/CCpp.cpp b/src/plugins/CCpp.cpp index d88a593d..df2c4482 100644 --- a/src/plugins/CCpp.cpp +++ b/src/plugins/CCpp.cpp @@ -26,16 +26,28 @@ using namespace std; #define CORE_PATTERN_IFACE "/proc/sys/kernel/core_pattern" -#define CORE_PATTERN "|"CCPP_HOOK_PATH" "DEBUG_DUMPS_DIR" %p %s %u %c" +/* + * %s - signal number + * %c - ulimit -c value + * %p - pid + * %u - uid + * %g - gid + * %t - UNIX time of dump + * %h - hostname + * %e - executable filename + * %% - output one "%" + */ +#define CORE_PATTERN "|"CCPP_HOOK_PATH" "DEBUG_DUMPS_DIR" %s %c %p %u %g %t %h %e" + #define CORE_PIPE_LIMIT_IFACE "/proc/sys/kernel/core_pipe_limit" /* core_pipe_limit specifies how many dump_helpers might run at the same time * 0 - means unlimited, but it's not guaranteed that /proc/ of crashing - * process will be available for dump_helper + * 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/) - * This should be enough for ABRT, we can miss some crashes, but what are - * the odds that more processes crash at the same time? - * The value of 4 has been recommended by nhorman. + * run, but they will fail to read /proc/). + * This should be enough for ABRT, we can miss some crashes, but what are + * the odds that more processes crash at the same time? + * The value of 4 has been recommended by nhorman. */ #define CORE_PIPE_LIMIT "4" @@ -133,7 +145,7 @@ void CAnalyzerCCpp::Init() } if (m_sOldCorePattern[0] == '|') { - if (m_sOldCorePattern == CORE_PATTERN) + if (strncmp(m_sOldCorePattern.c_str(), CORE_PATTERN, strlen(CORE_PATTERN)) == 0) { log("warning: %s already contains %s, " "did abrt daemon crash recently?", @@ -157,14 +169,35 @@ void CAnalyzerCCpp::Init() fp = fopen(CORE_PATTERN_IFACE, "w"); if (fp) { - fputs(CORE_PATTERN, fp); + if (m_sOldCorePattern[0] != '|') + { + const char *old = m_sOldCorePattern.c_str(); + unsigned len = strchrnul(old, '\n') - old; + char *hex_old = (char*)xmalloc(len * 2 + 1); + bin2hex(hex_old, old, len)[0] = '\0'; + /* Trailing 00 is a sentinel. Decoder in the hook will check it. + * If it won't see it, then kernel has truncated the argument: + */ + char *pattern = xasprintf("%s %s00", CORE_PATTERN, hex_old); + //log("old:'%s'->'%s'", old, hex_old); + //log("pattern:'%s'", pattern); + + fputs(pattern, fp); + + free(pattern); + free(hex_old); + } + else + { + fputs(CORE_PATTERN, fp); + } fclose(fp); } /* read the core_pipe_limit and change it if it's == 0 - otherwise the abrt-hook-ccpp won't be able to read /proc/ - of the crashing process - */ + * otherwise the abrt-hook-ccpp won't be able to read /proc/ + * of the crashing process + */ fp = fopen(CORE_PIPE_LIMIT_IFACE, "r"); if (fp) { -- cgit From 480cac7647d567c3c3cb148c5a4750091b651934 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 19 Jan 2011 17:14:05 +0100 Subject: remove old plugin machinery. -10k and -1 library dependence in abrtd Signed-off-by: Denys Vlasenko --- src/plugins/CCpp.cpp | 301 --------------------------------------------------- 1 file changed, 301 deletions(-) delete mode 100644 src/plugins/CCpp.cpp (limited to 'src/plugins/CCpp.cpp') diff --git a/src/plugins/CCpp.cpp b/src/plugins/CCpp.cpp deleted file mode 100644 index df2c4482..00000000 --- a/src/plugins/CCpp.cpp +++ /dev/null @@ -1,301 +0,0 @@ -/* - CCpp.cpp - - Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) - 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 -#include "abrtlib.h" -#include "CCpp.h" -#include "comm_layer_inner.h" - -using namespace std; - -#define CORE_PATTERN_IFACE "/proc/sys/kernel/core_pattern" -/* - * %s - signal number - * %c - ulimit -c value - * %p - pid - * %u - uid - * %g - gid - * %t - UNIX time of dump - * %h - hostname - * %e - executable filename - * %% - output one "%" - */ -#define CORE_PATTERN "|"CCPP_HOOK_PATH" "DEBUG_DUMPS_DIR" %s %c %p %u %g %t %h %e" - -#define CORE_PIPE_LIMIT_IFACE "/proc/sys/kernel/core_pipe_limit" -/* core_pipe_limit specifies how many dump_helpers might run at the same time - * 0 - means unlimited, but it's not guaranteed that /proc/ 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/). - * This should be enough for ABRT, we can miss some crashes, but what are - * the odds that more processes crash at the same time? - * The value of 4 has been recommended by nhorman. - */ -#define CORE_PIPE_LIMIT "4" - -#define DEBUGINFO_CACHE_DIR LOCALSTATEDIR"/cache/abrt-di" - -CAnalyzerCCpp::CAnalyzerCCpp() : - m_bBacktrace(true), - m_bBacktraceRemotes(false), - m_bMemoryMap(false), - m_bInstallDebugInfo(true), - m_nDebugInfoCacheMB(4000), - m_nGdbTimeoutSec(60) -{} - -/* - this is just a workaround until kernel changes it's behavior - when handling pipes in core_pattern -*/ -#ifdef HOSTILE_KERNEL -#define CORE_SIZE_PATTERN "Max core file size=1:unlimited" -static int isdigit_str(char *str) -{ - do { - if (*str < '0' || *str > '9') - return 0; - } while (*++str); - return 1; -} - -static int set_limits() -{ - DIR *dir = opendir("/proc"); - if (!dir) { - /* this shouldn't fail, but to be safe.. */ - return 1; - } - - struct dirent *ent; - while ((ent = readdir(dir)) != NULL) { - if (!isdigit_str(ent->d_name)) - continue; - - char limits_name[sizeof("/proc/%s/limits") + sizeof(long)*3]; - snprintf(limits_name, sizeof(limits_name), "/proc/%s/limits", ent->d_name); - FILE *limits_fp = fopen(limits_name, "r"); - if (!limits_fp) { - break; - } - - char line[128]; - char *ulimit_c = NULL; - while (1) { - if (fgets(line, sizeof(line)-1, limits_fp) == NULL) - break; - if (strncmp(line, "Max core file size", sizeof("Max core file size")-1) == 0) { - ulimit_c = skip_whitespace(line + sizeof("Max core file size")-1); - skip_non_whitespace(ulimit_c)[0] = '\0'; - break; - } - } - fclose(limits_fp); - if (!ulimit_c || ulimit_c[0] != '0' || ulimit_c[1] != '\0') { - /*process has nonzero ulimit -c, so need to modify it*/ - continue; - } - /* echo -n 'Max core file size=1:unlimited' >/proc/PID/limits */ - int fd = open(limits_name, O_WRONLY); - if (fd >= 0) { - errno = 0; - /*full_*/ - ssize_t n = write(fd, CORE_SIZE_PATTERN, sizeof(CORE_SIZE_PATTERN)-1); - if (n < sizeof(CORE_SIZE_PATTERN)-1) - log("warning: can't write core_size limit to: %s", limits_name); - close(fd); - } - else - { - log("warning: can't open %s for writing", limits_name); - } - } - closedir(dir); - return 0; -} -#endif /* HOSTILE_KERNEL */ - -void CAnalyzerCCpp::Init() -{ - FILE *fp = fopen(CORE_PATTERN_IFACE, "r"); - if (fp) - { - char line[PATH_MAX]; - if (fgets(line, sizeof(line), fp)) - m_sOldCorePattern = line; - fclose(fp); - } - if (m_sOldCorePattern[0] == '|') - { - if (strncmp(m_sOldCorePattern.c_str(), CORE_PATTERN, strlen(CORE_PATTERN)) == 0) - { - log("warning: %s already contains %s, " - "did abrt daemon crash recently?", - CORE_PATTERN_IFACE, CORE_PATTERN); - /* There is no point in "restoring" CORE_PATTERN_IFACE - * to CORE_PATTERN on exit. Will restore to a default value: - */ - m_sOldCorePattern = "core"; - } else { - log("warning: %s was already set to run a crash analyser (%s), " - "abrt may interfere with it", - CORE_PATTERN_IFACE, CORE_PATTERN); - } - } -#ifdef HOSTILE_KERNEL - if (set_limits() != 0) - log("warning: failed to set core_size limit, ABRT won't detect crashes in" - "compiled apps"); -#endif - - fp = fopen(CORE_PATTERN_IFACE, "w"); - if (fp) - { - if (m_sOldCorePattern[0] != '|') - { - const char *old = m_sOldCorePattern.c_str(); - unsigned len = strchrnul(old, '\n') - old; - char *hex_old = (char*)xmalloc(len * 2 + 1); - bin2hex(hex_old, old, len)[0] = '\0'; - /* Trailing 00 is a sentinel. Decoder in the hook will check it. - * If it won't see it, then kernel has truncated the argument: - */ - char *pattern = xasprintf("%s %s00", CORE_PATTERN, hex_old); - //log("old:'%s'->'%s'", old, hex_old); - //log("pattern:'%s'", pattern); - - fputs(pattern, fp); - - free(pattern); - free(hex_old); - } - else - { - fputs(CORE_PATTERN, fp); - } - fclose(fp); - } - - /* read the core_pipe_limit and change it if it's == 0 - * otherwise the abrt-hook-ccpp won't be able to read /proc/ - * of the crashing process - */ - fp = fopen(CORE_PIPE_LIMIT_IFACE, "r"); - if (fp) - { - /* we care only about the first char, if it's - * not '0' then we don't have to change it, - * because it means that it's already != 0 - */ - char pipe_limit[2]; - if (!fgets(pipe_limit, sizeof(pipe_limit), fp)) - pipe_limit[0] = '1'; /* not 0 */ - fclose(fp); - if (pipe_limit[0] == '0') - { - fp = fopen(CORE_PIPE_LIMIT_IFACE, "w"); - if (fp) - { - fputs(CORE_PIPE_LIMIT, fp); - fclose(fp); - } - else - { - log("warning: failed to set core_pipe_limit, ABRT won't detect" - "crashes in compiled apps if kernel > 2.6.31"); - } - } - } -} - -void CAnalyzerCCpp::DeInit() -{ - /* no need to restore the core_pipe_limit, because it's only used - when there is s pipe in core_pattern - */ - FILE *fp = fopen(CORE_PATTERN_IFACE, "w"); - if (fp) - { - fputs(m_sOldCorePattern.c_str(), fp); - fclose(fp); - } -} - -void CAnalyzerCCpp::SetSettings(const map_plugin_settings_t& pSettings) -{ - m_pSettings = pSettings; - - map_plugin_settings_t::const_iterator end = pSettings.end(); - map_plugin_settings_t::const_iterator it; - it = pSettings.find("Backtrace"); - if (it != end) - { - m_bBacktrace = string_to_bool(it->second.c_str()); - } - it = pSettings.find("BacktraceRemotes"); - if (it != end) - { - m_bBacktraceRemotes = string_to_bool(it->second.c_str()); - } - it = pSettings.find("MemoryMap"); - if (it != end) - { - m_bMemoryMap = string_to_bool(it->second.c_str()); - } - it = pSettings.find("DebugInfo"); - if (it != end) - { - m_sDebugInfo = it->second; - } - it = pSettings.find("DebugInfoCacheMB"); - if (it != end) - { - m_nDebugInfoCacheMB = xatou(it->second.c_str()); - } - it = pSettings.find("GdbTimeoutSec"); - if (it != end) - { - m_nGdbTimeoutSec = xatoi_positive(it->second.c_str()); - } - it = pSettings.find("InstallDebugInfo"); - if (it == end) //compat, remove after 0.0.11 - it = pSettings.find("InstallDebuginfo"); - if (it != end) - { - m_bInstallDebugInfo = string_to_bool(it->second.c_str()); - } - m_sDebugInfoDirs = DEBUGINFO_CACHE_DIR; - it = pSettings.find("ReadonlyLocalDebugInfoDirs"); - if (it != end) - { - m_sDebugInfoDirs += ':'; - m_sDebugInfoDirs += it->second; - } -} - -PLUGIN_INFO(ANALYZER, - CAnalyzerCCpp, - "CCpp", - "0.0.1", - _("Analyzes crashes in C/C++ programs"), - "zprikryl@redhat.com", - "https://fedorahosted.org/abrt/wiki", - ""); -- cgit