diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-10-28 23:44:28 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-10-28 23:44:28 +0100 |
commit | 7a2a2fa7e8d613c69d0fda6c220d97936f56c4fd (patch) | |
tree | 0a5346f5356f837f8a8513369039ad9445829824 /lib | |
parent | 15d6cd43bee1e9b66b3cd46e99598d7da3e03fd7 (diff) | |
download | abrt-7a2a2fa7e8d613c69d0fda6c220d97936f56c4fd.tar.gz abrt-7a2a2fa7e8d613c69d0fda6c220d97936f56c4fd.tar.xz abrt-7a2a2fa7e8d613c69d0fda6c220d97936f56c4fd.zip |
KerneloopsScanner: do not use global variables needlessly
text data bss dec hex filename
27341 1688 48 29077 7195 old/libKerneloopsScanner.so
26466 1672 24 28162 6e02 new/libKerneloopsScanner.so
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Plugins/KerneloopsScanner.cpp | 13 | ||||
-rw-r--r-- | lib/Plugins/KerneloopsScanner.h | 2 | ||||
-rw-r--r-- | lib/Plugins/KerneloopsSysLog.cpp | 183 | ||||
-rw-r--r-- | lib/Plugins/KerneloopsSysLog.h | 2 |
4 files changed, 90 insertions, 110 deletions
diff --git a/lib/Plugins/KerneloopsScanner.cpp b/lib/Plugins/KerneloopsScanner.cpp index 60fa92e4..317aeabb 100644 --- a/lib/Plugins/KerneloopsScanner.cpp +++ b/lib/Plugins/KerneloopsScanner.cpp @@ -83,12 +83,10 @@ void CKerneloopsScanner::SaveOopsToDebugDump() m_pSysLog.ClearOopsList(); while (!oopsList.empty()) { - char path[PATH_MAX]; - snprintf(path, sizeof(path), "%s/kerneloops-%lu-%lu", - DEBUG_DUMPS_DIR, (long)t, (long)oopsList.size()); - + char path[sizeof(DEBUG_DUMPS_DIR"/kerneloops-%lu-%lu") + 2 * sizeof(long)*3]; + sprintf(path, DEBUG_DUMPS_DIR"/kerneloops-%lu-%lu", + (long)t, (long)oopsList.size()); COops oops = oopsList.back(); - try { CDebugDump debugDump; @@ -171,9 +169,10 @@ int CKerneloopsScanner::ScanSysLogFile(const char *filename) void CKerneloopsScanner::SetSettings(const map_plugin_settings_t& pSettings) { - if (pSettings.find("SysLogFile") != pSettings.end()) + map_plugin_settings_t::const_iterator it = pSettings.find("SysLogFile"); + if (it != pSettings.end()) { - m_sSysLogFile = pSettings.find("SysLogFile")->second; + m_sSysLogFile = it->second; } } diff --git a/lib/Plugins/KerneloopsScanner.h b/lib/Plugins/KerneloopsScanner.h index 981f187a..512fb9c8 100644 --- a/lib/Plugins/KerneloopsScanner.h +++ b/lib/Plugins/KerneloopsScanner.h @@ -38,7 +38,7 @@ class CKerneloopsScanner : public CAction CSysLog m_pSysLog; public: - /* For standalone oops processor */ + /* For "dumpoops" tool */ void SaveOopsToDebugDump(); int ScanDmesg(); int ScanSysLogFile(const char *filename); diff --git a/lib/Plugins/KerneloopsSysLog.cpp b/lib/Plugins/KerneloopsSysLog.cpp index b1171cf6..886073b3 100644 --- a/lib/Plugins/KerneloopsSysLog.cpp +++ b/lib/Plugins/KerneloopsSysLog.cpp @@ -37,45 +37,16 @@ */ #define MAX_OOPS 16 -struct line_info { - char *ptr; - char level; -}; - -static struct line_info *lines_info; -static int lines_info_alloc; -static int linecount; - -#define REALLOC_CHUNK 1000 - -static int set_line_info(int index, char *linepointer, char linelevel) -{ - if (index >= lines_info_alloc) { - struct line_info *new_info; - new_info = (line_info*)realloc(lines_info, - (lines_info_alloc + REALLOC_CHUNK) * sizeof(struct line_info)); - if (!new_info) - return -1; - lines_info_alloc += REALLOC_CHUNK; - lines_info = new_info; - } - - lines_info[index].ptr = linepointer; - lines_info[index].level = linelevel; - return 0; -} - CSysLog::CSysLog() : m_nFoundOopses(0) {} void CSysLog::QueueOops(char *data, char *version) { - COops m_NewOops; - if (m_nFoundOopses > MAX_OOPS) return; + COops m_NewOops; m_NewOops.m_sData = data; m_NewOops.m_sVersion = version; @@ -93,24 +64,64 @@ const std::list<COops>& CSysLog::GetOopsList() return m_OopsQueue; } + /* - * This function splits the dmesg buffer data into lines - * (null terminated). + * extract_version tries to find the kernel version in given data */ -int CSysLog::FillLinePointers(char *buffer, size_t buflen) +static int extract_version(const char *linepointer, char *version) { - char *c, *linepointer, linelevel; + int ret; + + ret = 0; + if ((strstr(linepointer, "Pid") != NULL) + || (strstr(linepointer, "comm") != NULL) + || (strstr(linepointer, "CPU") != NULL) + || (strstr(linepointer, "REGS") != NULL) + || (strstr(linepointer, "EFLAGS") != NULL) + ) { + char* start; + char* end; + + start = strstr((char*)linepointer, "2.6."); + if (start) { + end = strchrnul(start, ' '); + strncpy(version, start, end-start); + ret = 1; + } + } + + if (!ret) + strncpy(version, "undefined", 9); + + return ret; +} + +/* + * extract_oops tries to find oops signatures in a log + */ +struct line_info { + char *ptr; + char level; +}; +#define REALLOC_CHUNK 1000 +int CSysLog::ExtractOops(char *buffer, size_t buflen) +{ + char *c; enum { maybe, no, yes } syslog_format = maybe; - linecount = 0; + int linecount = 0; + int lines_info_alloc = 0; + struct line_info *lines_info = NULL; + + /* Split buffer into lines */ - if (!buflen) - return 0; - buffer[buflen - 1] = '\n'; /* the buffer usually ends with \n, but let's make sure */ + if (buflen != 0) + buffer[buflen - 1] = '\n'; /* the buffer usually ends with \n, but let's make sure */ c = buffer; while (c < buffer + buflen) { - char v; + char v, linelevel; int len = 0; char *c9; + char *linepointer; c9 = (char*)memchr(c, '\n', buffer + buflen - c); /* a \n will always be found */ assert(c9); @@ -183,66 +194,31 @@ int CSysLog::FillLinePointers(char *buffer, size_t buflen) /* if we see our own marker, we know we submitted everything upto here already */ if (len >= 4 && memmem(linepointer, len, "Abrt", 4)) { linecount = 0; - lines_info[0].ptr = NULL; + lines_info_alloc = 0; + free(lines_info); + lines_info = NULL; } - if (set_line_info(linecount, linepointer, linelevel) < 0) - return -1; + + if (linecount >= lines_info_alloc) { + lines_info_alloc += REALLOC_CHUNK; + lines_info = (line_info*)xrealloc(lines_info, + lines_info_alloc * sizeof(struct line_info)); + } + lines_info[linecount].ptr = linepointer; + lines_info[linecount].level = linelevel; linecount++; next_line: c = c9 + 1; } - return 0; -} - -/* - * extract_version tries to find the kernel version in given data - */ -int CSysLog::ExtractVersion(char *linepointer, char *version) -{ - int ret; - - ret = 0; - if ((strstr(linepointer, "Pid") != NULL) || - (strstr(linepointer, "comm") != NULL) || - (strstr(linepointer, "CPU") != NULL) || - (strstr(linepointer, "REGS") != NULL) || - (strstr(linepointer, "EFLAGS") != NULL)) - { - char* start; - char* end; - - start = strstr(linepointer, "2.6."); - if (start) { - end = strchrnul(start, ' '); - strncpy(version, start, end-start); - ret = 1; - } - } - if (!ret) - strncpy(version, "undefined", 9); + /* Analyze lines */ - return ret; -} - -/* - * extract_oops tries to find oops signatures in a log - */ -int CSysLog::ExtractOops(char *buffer, size_t buflen) -{ int i; char prevlevel = 0; int oopsstart = -1; int oopsend; int inbacktrace = 0; int oopsesfound = 0; - - lines_info = NULL; - lines_info_alloc = 0; - - if (FillLinePointers(buffer, buflen) < 0) - goto fail; - oopsend = linecount; i = 0; @@ -323,26 +299,33 @@ int CSysLog::ExtractOops(char *buffer, size_t buflen) c1 = strstr(lines_info[i].ptr, ">]"); c2 = strstr(lines_info[i].ptr, "+0x"); c3 = strstr(lines_info[i].ptr, "/0x"); - if (lines_info[i].ptr[0] == ' ' && lines_info[i].ptr[1] == '[' && lines_info[i].ptr[2] == '<' && c1 && c2 && c3) + if (lines_info[i].ptr[0] == ' ' + && lines_info[i].ptr[1] == '[' + && lines_info[i].ptr[2] == '<' + && c1 && c2 && c3 + ) { inbacktrace = 1; - } else + } + } /* try to see if we're at the end of an oops */ - if (oopsstart >= 0 && inbacktrace > 0) { + else if (oopsstart >= 0 && inbacktrace > 0) { char c2, c3; c2 = lines_info[i].ptr[0]; c3 = lines_info[i].ptr[1]; /* line needs to start with " [" or have "] ["*/ - if ((c2 != ' ' || c3 != '[') && - strstr(lines_info[i].ptr, "] [") == NULL && - strstr(lines_info[i].ptr, "--- Exception") == NULL && - strstr(lines_info[i].ptr, " LR =") == NULL && - strstr(lines_info[i].ptr, "<#DF>") == NULL && - strstr(lines_info[i].ptr, "<IRQ>") == NULL && - strstr(lines_info[i].ptr, "<EOI>") == NULL && - strstr(lines_info[i].ptr, "<<EOE>>") == NULL) + if ((c2 != ' ' || c3 != '[') + && strstr(lines_info[i].ptr, "] [") == NULL + && strstr(lines_info[i].ptr, "--- Exception") == NULL + && strstr(lines_info[i].ptr, " LR =") == NULL + && strstr(lines_info[i].ptr, "<#DF>") == NULL + && strstr(lines_info[i].ptr, "<IRQ>") == NULL + && strstr(lines_info[i].ptr, "<EOI>") == NULL + && strstr(lines_info[i].ptr, "<<EOE>>") == NULL + ) { oopsend = i-1; + } /* oops lines are always more than 8 long */ if (strlen(lines_info[i].ptr) < 8) @@ -381,7 +364,7 @@ int CSysLog::ExtractOops(char *buffer, size_t buflen) is_version = 0; for (q = oopsstart; q <= oopsend; q++) { if (!is_version) - is_version = ExtractVersion(lines_info[q].ptr, version); + is_version = extract_version(lines_info[q].ptr, version); strcat(oops, lines_info[q].ptr); strcat(oops, "\n"); } @@ -431,7 +414,7 @@ int CSysLog::ExtractOops(char *buffer, size_t buflen) is_version = 0; for (q = oopsstart; q <= oopsend; q++) { if (!is_version) - is_version = ExtractVersion(lines_info[q].ptr, version); + is_version = extract_version(lines_info[q].ptr, version); strcat(oops, lines_info[q].ptr); strcat(oops, "\n"); } @@ -446,8 +429,8 @@ int CSysLog::ExtractOops(char *buffer, size_t buflen) free(oops); free(version); } + fail: free(lines_info); - lines_info = NULL; return oopsesfound; } diff --git a/lib/Plugins/KerneloopsSysLog.h b/lib/Plugins/KerneloopsSysLog.h index c2e8c2d0..8d0626b7 100644 --- a/lib/Plugins/KerneloopsSysLog.h +++ b/lib/Plugins/KerneloopsSysLog.h @@ -41,8 +41,6 @@ class CSysLog { private: void QueueOops(char *data, char *version); - int ExtractVersion(char *linepointer, char *version); - int FillLinePointers(char *buffer, size_t buflen); std::list<COops> m_OopsQueue; int m_nFoundOopses; |