diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-10-30 19:17:10 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-10-30 19:17:10 +0100 |
commit | 276a9017d63445dd322f9a93ff34e67cbdf97dc9 (patch) | |
tree | be5d38eaa1aeaefe49966ea280e6e8d13e6ec2ce | |
parent | b4e0ad1ef24fd49bcd5cdd1b6f1dd69768036e07 (diff) | |
download | abrt-276a9017d63445dd322f9a93ff34e67cbdf97dc9.tar.gz abrt-276a9017d63445dd322f9a93ff34e67cbdf97dc9.tar.xz abrt-276a9017d63445dd322f9a93ff34e67cbdf97dc9.zip |
lib/Plugins/Logger: much more sane dump format; fix misdetection of text files
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | lib/Plugins/Logger.cpp | 1 | ||||
-rw-r--r-- | lib/Utils/DebugDump.cpp | 26 | ||||
-rw-r--r-- | lib/Utils/Makefile.am | 1 | ||||
-rw-r--r-- | lib/Utils/make_descr.cpp | 81 | ||||
-rw-r--r-- | src/Daemon/MiddleWare.cpp | 4 | ||||
-rw-r--r-- | src/Hooks/CCpp.cpp | 31 |
7 files changed, 74 insertions, 74 deletions
diff --git a/configure.ac b/configure.ac index dcbb57c9..f4242338 100644 --- a/configure.ac +++ b/configure.ac @@ -39,10 +39,6 @@ AC_CHECK_HEADER([libtar.h], [], AC_CHECK_HEADER([sys/inotify.h], [], [AC_MSG_ERROR([sys/inotify.h is needed to build abrt])]) -AC_CHECK_HEADER([magic.h], [], - [AC_MSG_ERROR([magic.h is needed to build abrt])]) - - CONF_DIR='${sysconfdir}/${PACKAGE_NAME}' VAR_RUN='${localstatedir}/run' PLUGINS_CONF_DIR='${sysconfdir}/${PACKAGE_NAME}/plugins' diff --git a/lib/Plugins/Logger.cpp b/lib/Plugins/Logger.cpp index 69453d40..eb9c2404 100644 --- a/lib/Plugins/Logger.cpp +++ b/lib/Plugins/Logger.cpp @@ -58,6 +58,7 @@ std::string CLogger::Report(const map_crash_report_t& pCrashReport, const std::s update_client(_("Creating a report...")); std::string description = make_description_logger(pCrashReport); + description += "\n\n\n"; FILE *fOut; if (m_bAppendLogs) diff --git a/lib/Utils/DebugDump.cpp b/lib/Utils/DebugDump.cpp index ecd6d05b..5017d868 100644 --- a/lib/Utils/DebugDump.cpp +++ b/lib/Utils/DebugDump.cpp @@ -23,7 +23,7 @@ #include <iostream> #include <sstream> #include <sys/utsname.h> -#include <magic.h> +//#include <magic.h> #include "abrtlib.h" #include "DebugDump.h" #include "ABRTException.h" @@ -290,8 +290,10 @@ static void DeleteFileDir(const std::string& pDir) } } -static bool IsTextFile(const std::string& pName) +static bool IsTextFile(const char *name) { +/* This idiotic library thinks that file containing just "0" is not text (!!) + magic_t m = magic_open(MAGIC_MIME_TYPE); if (m == NULL) @@ -320,6 +322,24 @@ static bool IsTextFile(const std::string& pName) 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); + + while (--r >= 0) + { + if (buf[r] >= 0x7f) + return false; + /* Among control chars, only '\t','\n' etc are allowed */ + if (buf[r] < ' ' && !isspace(buf[r])) + return false; + } + return true; } static std::string RemoveBackSlashes(const std::string& pDir) @@ -532,7 +552,7 @@ bool CDebugDump::GetNextFile(std::string& pFileName, std::string& pContent, bool std::string fullname = m_sDebugDumpDir + "/" + dent->d_name; pFileName = dent->d_name; - if (IsTextFile(fullname)) + if (IsTextFile(fullname.c_str())) { LoadText(dent->d_name, pContent); pIsTextFile = true; diff --git a/lib/Utils/Makefile.am b/lib/Utils/Makefile.am index 7823b4d4..88df68f6 100644 --- a/lib/Utils/Makefile.am +++ b/lib/Utils/Makefile.am @@ -37,7 +37,6 @@ libABRTUtils_la_LDFLAGS = \ $(DL_LIBS) \ $(DBUS_LIBS) libABRTUtils_la_LIBADD = \ - -lmagic \ $(POLKIT_LIBS) install-data-local: diff --git a/lib/Utils/make_descr.cpp b/lib/Utils/make_descr.cpp index 2823dbb4..71b91912 100644 --- a/lib/Utils/make_descr.cpp +++ b/lib/Utils/make_descr.cpp @@ -11,14 +11,13 @@ static void add_content(bool &was_multiline, string& description, const char *he if (was_multiline) description += '\n'; - description += header; - while (content[0] == '\n') content++; if (strchr(content, '\n') == NULL) { /* one string value, like OS release */ + description += header; description += ": "; description += content; description += '\n'; @@ -27,6 +26,9 @@ static void add_content(bool &was_multiline, string& description, const char *he else { /* multi-string value, like backtrace */ + if (!was_multiline && description.size() != 0) /* if wasn't yet separated */ + description += '\n'; /* do it now */ + description += header; description += "\n-----\n"; description += content; if (content[strlen(content) - 1] != '\n') @@ -76,11 +78,6 @@ string make_description_bz(const map_crash_report_t& pCrashReport) { add_content(was_multiline, description, "Attached file", filename.c_str()); } - //else if (type == CD_BIN) - //{ - // string msg = ssprintf(_("Binary file %s is not reported"), filename.c_str()); - // warn_client(msg); - //} } return description; @@ -88,65 +85,41 @@ string make_description_bz(const map_crash_report_t& pCrashReport) string make_description_logger(const map_crash_report_t& pCrashReport) { -// string description; - stringstream binaryFiles, commonFiles, bigTextFiles, additionalFiles, UUIDFile; + string description; + string long_description; map_crash_report_t::const_iterator it = pCrashReport.begin(); for (; it != pCrashReport.end(); it++) { - if (it->second[CD_TYPE] == CD_TXT) - { - if (it->first != CD_UUID - && it->first != FILENAME_ARCHITECTURE - && it->first != FILENAME_KERNEL - && it->first != FILENAME_PACKAGE - ) { - additionalFiles << it->first << std::endl; - additionalFiles << "-----" << std::endl; - additionalFiles << it->second[CD_CONTENT] << std::endl << std::endl; - } - else if (it->first == CD_UUID) + const string &filename = it->first; + const string &type = it->second[CD_TYPE]; + const string &content = it->second[CD_CONTENT]; + if (type == CD_TXT + || type == CD_ATT + || type == CD_BIN + ) { + bool was_multiline = 0; + string tmp; + add_content(was_multiline, tmp, filename.c_str(), content.c_str()); + + if (was_multiline) { - UUIDFile << it->first << std::endl; - UUIDFile << "-----" << std::endl; - UUIDFile << it->second[CD_CONTENT] << std::endl << std::endl; + if (long_description.size() != 0) + long_description += '\n'; + long_description += tmp; } else { - commonFiles << it->first << std::endl; - commonFiles << "-----" << std::endl; - commonFiles << it->second[CD_CONTENT] << std::endl << std::endl; + description += tmp; } } - if (it->second[CD_TYPE] == CD_ATT) - { - bigTextFiles << it->first << std::endl; - bigTextFiles << "-----" << std::endl; - bigTextFiles << it->second[CD_CONTENT] << std::endl << std::endl; - } - if (it->second[CD_TYPE] == CD_BIN) - { - binaryFiles << it->first << std::endl; - binaryFiles << "-----" << std::endl; - binaryFiles << it->second[CD_CONTENT] << std::endl << std::endl; - } } - string description = "Duplicity check\n======\n\n"; - description += UUIDFile.str(); - description += '\n'; - description += "Common information\n======\n\n"; - description += commonFiles.str(); - description += '\n'; - description += "Additional information\n======\n\n"; - description += additionalFiles.str(); - description += '\n'; - description += "Big Text Files\n======\n\n"; - description += bigTextFiles.str(); - description += '\n'; - description += "Binary files\n======\n"; - description += binaryFiles.str(); - description += "\n\n"; + if (long_description.size() != 0) + { + description += '\n'; + description += long_description; + } return description; } diff --git a/src/Daemon/MiddleWare.cpp b/src/Daemon/MiddleWare.cpp index 7c5bb412..2fd4f259 100644 --- a/src/Daemon/MiddleWare.cpp +++ b/src/Daemon/MiddleWare.cpp @@ -84,12 +84,14 @@ static void DebugDumpToCrashReport(const std::string& pDebugDumpDir, map_crash_r !dd.Exist(FILENAME_RELEASE) || !dd.Exist(FILENAME_EXECUTABLE)) { - throw CABRTException(EXCEP_ERROR, "DebugDumpToCrashReport(): One or more of important file(s)'re missing."); + throw CABRTException(EXCEP_ERROR, "DebugDumpToCrashReport(): One or more of important file(s)'re missing"); } + pCrashReport.clear(); dd.InitGetNextFile(); while (dd.GetNextFile(fileName, content, isTextFile)) { +VERB3 log(" file:'%s' text:%d", fileName.c_str(), isTextFile); if (!isTextFile) { add_crash_data_to_crash_report(pCrashReport, diff --git a/src/Hooks/CCpp.cpp b/src/Hooks/CCpp.cpp index e6768a60..1c152e6c 100644 --- a/src/Hooks/CCpp.cpp +++ b/src/Hooks/CCpp.cpp @@ -54,32 +54,41 @@ static char* get_cmdline(pid_t pid) char path[PATH_MAX]; char cmdline[COMMAND_LINE_SIZE]; snprintf(path, sizeof(path), "/proc/%u/cmdline", (int)pid); - int dst = 0; + int idx = 0; int fd = open(path, O_RDONLY); if (fd >= 0) { int len = read(fd, cmdline, sizeof(cmdline) - 1); - if (len >= 0) + close(fd); + + if (len > 0) { - int src = 0; - while (src < len) + /* In Linux, there is always one trailing NUL byte, + * prevent it from being replaced by space below. + */ + if (cmdline[len - 1] == '\0') + len--; + + while (idx < len) { - char ch = cmdline[src++]; + unsigned char ch = cmdline[idx]; if (ch == '\0') { - cmdline[dst++] = ' '; + cmdline[idx++] = ' '; } - /* TODO: maybe just ch >= ' '? */ - else if (isspace(ch) || (isascii(ch) && !iscntrl(ch))) + else if (ch >= ' ' && ch <= 0x7e) { - cmdline[dst++] = ch; + cmdline[idx++] = ch; + } + else + { + cmdline[idx++] = '?'; } } } - close(fd); } - cmdline[dst] = '\0'; + cmdline[idx] = '\0'; return xstrdup(cmdline); } |