diff options
| author | Karel Klic <kklic@redhat.com> | 2009-11-20 12:22:36 +0100 |
|---|---|---|
| committer | Karel Klic <kklic@redhat.com> | 2009-11-20 12:22:36 +0100 |
| commit | 18363807e6ffa8dab5a76f40bacac3695985147a (patch) | |
| tree | 8195336c29136a4761db501160c9f4620b16aa70 /lib/Utils | |
| parent | bd60681c8227bc31ef0991e98a9a3e849032c924 (diff) | |
| parent | 6ec2390e40ba4b0f6e10a2c8ce858d3431b34964 (diff) | |
| download | abrt-18363807e6ffa8dab5a76f40bacac3695985147a.tar.gz abrt-18363807e6ffa8dab5a76f40bacac3695985147a.tar.xz abrt-18363807e6ffa8dab5a76f40bacac3695985147a.zip | |
Merge branch 'master' of ssh://git.fedorahosted.org/git/abrt
Diffstat (limited to 'lib/Utils')
| -rw-r--r-- | lib/Utils/DebugDump.cpp | 90 | ||||
| -rw-r--r-- | lib/Utils/DebugDump.h | 3 | ||||
| -rw-r--r-- | lib/Utils/Plugin.h | 12 | ||||
| -rw-r--r-- | lib/Utils/make_descr.cpp | 85 |
4 files changed, 98 insertions, 92 deletions
diff --git a/lib/Utils/DebugDump.cpp b/lib/Utils/DebugDump.cpp index 2883d01..fff4695 100644 --- a/lib/Utils/DebugDump.cpp +++ b/lib/Utils/DebugDump.cpp @@ -23,7 +23,6 @@ #include <iostream> #include <sstream> #include <sys/utsname.h> -//#include <magic.h> #include "abrtlib.h" #include "DebugDump.h" #include "ABRTException.h" @@ -287,72 +286,6 @@ static void DeleteFileDir(const char *pDir) } } -static bool IsTextFile(const char *name) -{ - /* Some files in our dump directories are known to always be textual */ - if (strcmp(name, "backtrace") == 0 - || strcmp(name, "cmdline") == 0 - ) { - return true; - } - -/* This idiotic library thinks that file containing just "0" is not text (!!) - - magic_t m = magic_open(MAGIC_MIME_TYPE); - - if (m == NULL) - { - throw CABRTException(EXCEP_ERROR, std::string(__func__) + "Cannot open magic cookie: " + magic_error(m)); - } - - int r = magic_load(m, NULL); - - if (r == -1) - { - magic_close(m); - throw CABRTException(EXCEP_ERROR, std::string(__func__) + "Cannot load magic db: " + magic_error(m)); - } - - char* ch = (char *) magic_file(m, pName.c_str()); - - if (ch == NULL) - { - magic_close(m); - throw CABRTException(EXCEP_ERROR, std::string(__func__) + "Cannot determine file type: " + magic_error(m)); - } - - bool isText = (strncmp(ch, "text", 4) == 0); - - magic_close(m); - - return isText; - */ - int fd = open(name, O_RDONLY); - if (fd < 0) - return false; - - unsigned char buf[4*1024]; - int r = full_read(fd, buf, sizeof(buf)); - close(fd); - - /* Every once in a while, even a text file contains a few garbled - * or unexpected non-ASCII chars. We should not declare it "binary". - */ - const unsigned RATIO = 50; - unsigned total_chars = r + RATIO; - unsigned bad_chars = 1; /* 1 prevents division by 0 later */ - while (--r >= 0) - { - if (buf[r] >= 0x7f - /* among control chars, only '\t','\n' etc are allowed */ - || (buf[r] < ' ' && !isspace(buf[r])) - ) { - bad_chars++; - } - } - return (total_chars / bad_chars) >= RATIO; -} - void CDebugDump::Delete() { if (!ExistFileDir(m_sDebugDumpDir.c_str())) @@ -460,7 +393,7 @@ void CDebugDump::InitGetNextFile() { if (!m_bOpened) { - throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::InitGetNextFile(): DebugDump is not opened."); + throw CABRTException(EXCEP_DD_OPEN, "DebugDump is not opened"); } if (m_pGetNextFileDir != NULL) { @@ -469,11 +402,11 @@ void CDebugDump::InitGetNextFile() m_pGetNextFileDir = opendir(m_sDebugDumpDir.c_str()); if (m_pGetNextFileDir == NULL) { - throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::InitGetNextFile(): Cannot open dir " + m_sDebugDumpDir); + throw CABRTException(EXCEP_DD_OPEN, "Can't open dir " + m_sDebugDumpDir); } } -bool CDebugDump::GetNextFile(std::string& pFileName, std::string& pContent, bool& pIsTextFile) +bool CDebugDump::GetNextFile(std::string *short_name, std::string *full_name) { if (m_pGetNextFileDir == NULL) { @@ -485,19 +418,10 @@ bool CDebugDump::GetNextFile(std::string& pFileName, std::string& pContent, bool { if (is_regular_file(dent, m_sDebugDumpDir.c_str())) { - std::string fullname = concat_path_file(m_sDebugDumpDir.c_str(), dent->d_name); - - pFileName = dent->d_name; - if (IsTextFile(fullname.c_str())) - { - LoadText(dent->d_name, pContent); - pIsTextFile = true; - } - else - { - pContent.clear(); - pIsTextFile = false; - } + if (short_name) + *short_name = dent->d_name; + if (full_name) + *full_name = concat_path_file(m_sDebugDumpDir.c_str(), dent->d_name); return true; } } diff --git a/lib/Utils/DebugDump.h b/lib/Utils/DebugDump.h index b48a386..d753353 100644 --- a/lib/Utils/DebugDump.h +++ b/lib/Utils/DebugDump.h @@ -72,7 +72,8 @@ class CDebugDump void SaveBinary(const char* pName, const char* pData, unsigned pSize); void InitGetNextFile(); - bool GetNextFile(std::string& pFileName, std::string& pContent, bool& pIsTextFile); + /* Pointers may be NULL */ + bool GetNextFile(std::string *short_name, std::string *full_name); }; #endif /*DEBUGDUMP_H_*/ diff --git a/lib/Utils/Plugin.h b/lib/Utils/Plugin.h index f93f7e7..d7108ce 100644 --- a/lib/Utils/Plugin.h +++ b/lib/Utils/Plugin.h @@ -26,13 +26,13 @@ #include "abrt_types.h" #include "CrashTypes.h" #if HAVE_CONFIG_H - #include <config.h> +# include <config.h> #endif #if ENABLE_NLS - #include <libintl.h> - #define _(S) gettext(S) +# include <libintl.h> +# define _(S) gettext(S) #else - #define _(S) (S) +# define _(S) (S) #endif #define PLUGINS_MAGIC_NUMBER 6 @@ -83,7 +83,8 @@ typedef enum { ANALYZER, /**< An analyzer plugin*/ ACTION, /**< An action plugin*/ REPORTER, /**< A reporter plugin*/ - DATABASE /**< A database plugin*/ + DATABASE, /**< A database plugin*/ + MAX_PLUGIN_TYPE = DATABASE, } plugin_type_t; /** @@ -121,5 +122,6 @@ typedef struct SPluginInfo /* helper finctions */ std::string make_description_bz(const map_crash_report_t& pCrashReport); std::string make_description_logger(const map_crash_report_t& pCrashReport); +std::string make_description_catcut(const map_crash_report_t& pCrashReport); #endif diff --git a/lib/Utils/make_descr.cpp b/lib/Utils/make_descr.cpp index 0c09614..c4cc3f3 100644 --- a/lib/Utils/make_descr.cpp +++ b/lib/Utils/make_descr.cpp @@ -2,6 +2,15 @@ //#include "abrt_types.h" #include "CrashTypes.h" #include "DebugDump.h" /* FILENAME_ARCHITECTURE etc */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif +#if ENABLE_NLS +# include <libintl.h> +# define _(S) gettext(S) +#else +# define _(S) (S) +#endif using namespace std; @@ -42,6 +51,9 @@ static void add_content(bool &was_multiline, string& description, const char *he } } +/* Text attachments smaller than this will be also included in descrition */ +#define INLINE_TEXT_ATT_SIZE 1024 + string make_description_bz(const map_crash_report_t& pCrashReport) { string description; @@ -68,8 +80,9 @@ string make_description_bz(const map_crash_report_t& pCrashReport) const string &filename = it->first; const string &type = it->second[CD_TYPE]; const string &content = it->second[CD_CONTENT]; - if (type == CD_TXT) - { + if (type == CD_TXT + || (type == CD_ATT && content.size() < INLINE_TEXT_ATT_SIZE) + ) { if (filename != CD_UUID && filename != FILENAME_ARCHITECTURE && filename != FILENAME_RELEASE @@ -78,8 +91,9 @@ string make_description_bz(const map_crash_report_t& pCrashReport) ) { add_content(was_multiline, description, filename.c_str(), content.c_str()); } + continue; } - else if (type == CD_ATT) + if (type == CD_ATT) { add_content(was_multiline, description, "Attached file", filename.c_str()); } @@ -131,3 +145,68 @@ string make_description_logger(const map_crash_report_t& pCrashReport) return description; } + +/* This needs more work to make the result less ugly */ +string make_description_catcut(const map_crash_report_t& pCrashReport) +{ + map_crash_report_t::const_iterator end = pCrashReport.end(); + map_crash_report_t::const_iterator it; + + string howToReproduce; + it = pCrashReport.find(CD_REPRODUCE); + if (it != end) + { + howToReproduce = "\n\nHow to reproduce\n" + "-----\n"; + howToReproduce += it->second[CD_CONTENT]; + } + string comment; + it = pCrashReport.find(CD_COMMENT); + if (it != end) + { + comment = "\n\nComment\n" + "-----\n"; + comment += it->second[CD_CONTENT]; + } + + string pDescription = "\nabrt "VERSION" detected a crash.\n"; + pDescription += howToReproduce; + pDescription += comment; + pDescription += "\n\nAdditional information\n" + "======\n"; + + for (it = pCrashReport.begin(); it != end; it++) + { + const string &filename = it->first; + const string &type = it->second[CD_TYPE]; + const string &content = it->second[CD_CONTENT]; + if (type == CD_TXT) + { + if (filename != CD_UUID + && filename != FILENAME_ARCHITECTURE + && filename != FILENAME_RELEASE + && filename != CD_REPRODUCE + && filename != CD_COMMENT + ) { + pDescription += '\n'; + pDescription += filename; + pDescription += "\n-----\n"; + pDescription += content; + pDescription += "\n\n"; + } + } + else if (type == CD_ATT) + { + pDescription += "\n\nAttached files\n" + "----\n"; + pDescription += filename; + pDescription += '\n'; + } + else if (type == CD_BIN) + { + error_msg(_("Binary file %s will not be reported"), filename.c_str()); + } + } + + return pDescription; +} |
