diff options
-rw-r--r-- | inc/abrtlib.h | 5 | ||||
-rw-r--r-- | lib/Plugins/Kerneloops.cpp | 2 | ||||
-rw-r--r-- | lib/Plugins/KerneloopsReporter.cpp | 50 | ||||
-rw-r--r-- | lib/Plugins/KerneloopsScanner.cpp | 29 | ||||
-rw-r--r-- | lib/Plugins/KerneloopsScanner.h | 7 | ||||
-rw-r--r-- | lib/Plugins/KerneloopsSysLog.cpp | 2 | ||||
-rw-r--r-- | lib/Plugins/KerneloopsSysLog.h | 2 | ||||
-rw-r--r-- | lib/Utils/Makefile.am | 7 | ||||
-rw-r--r-- | src/Applet/Makefile.am | 2 | ||||
-rw-r--r-- | src/Daemon/Makefile.am | 2 |
10 files changed, 75 insertions, 33 deletions
diff --git a/inc/abrtlib.h b/inc/abrtlib.h index 82ad3443..ae86a66b 100644 --- a/inc/abrtlib.h +++ b/inc/abrtlib.h @@ -3,6 +3,9 @@ * * Licensed under GPLv2, see file COPYING in this tarball for details. */ +#ifndef ABRTLIB_H_ +#define ABRTLIB_H_ + #include <ctype.h> #include <dirent.h> #include <errno.h> @@ -100,3 +103,5 @@ void xstat(const char *name, struct stat *stat_buf); void xmove_fd(int from, int to); char* xasprintf(const char *format, ...); + +#endif diff --git a/lib/Plugins/Kerneloops.cpp b/lib/Plugins/Kerneloops.cpp index 57482c0e..f4714834 100644 --- a/lib/Plugins/Kerneloops.cpp +++ b/lib/Plugins/Kerneloops.cpp @@ -35,7 +35,7 @@ std::string CAnalyzerKerneloops::GetLocalUUID(const std::string& pDebugDumpDir) { - comm_layer_inner_status("Getting local/global universal unique identification..."); + comm_layer_inner_status("Getting local/global universal unique identification..."); std::string m_sOops; std::stringstream m_sHash; diff --git a/lib/Plugins/KerneloopsReporter.cpp b/lib/Plugins/KerneloopsReporter.cpp index 2b5e2be4..30119809 100644 --- a/lib/Plugins/KerneloopsReporter.cpp +++ b/lib/Plugins/KerneloopsReporter.cpp @@ -35,17 +35,16 @@ #define FILENAME_KERNELOOPS "kerneloops" -CKerneloopsReporter::CKerneloopsReporter() : - m_sSubmitURL("http://submit.kerneloops.org/submitoops.php") -{} +/* helpers */ -size_t writefunction(void *ptr, size_t size, size_t nmemb, void *stream) +static size_t writefunction(void *ptr, size_t size, size_t nmemb, void *stream) { char *c, *c1, *c2; - c = (char*)xzalloc(size*nmemb + 1); - memcpy(c, ptr, size*nmemb); - printf("received %s \n", c); + size *= nmemb; +/* log("received: '%*.*s'\n", (int)size, (int)size, (char*)ptr); + c = (char*)xzalloc(size + 1); + memcpy(c, ptr, size); c1 = strstr(c, "201 "); if (c1) { c1 += 4; @@ -53,24 +52,27 @@ size_t writefunction(void *ptr, size_t size, size_t nmemb, void *stream) if (c2) *c2 = 0; } + free(c); +*/ - return size * nmemb; + return size; } -void CKerneloopsReporter::Report(const map_crash_report_t& pCrashReport, const std::string& pArgs) +/* Send oops data to kerneloops.org-style site, using HTTP POST */ +/* Returns 0 on success */ +static int http_post_to_kerneloops_site(const char *url, const char *oopsdata) { - comm_layer_inner_status("Creating and submitting a report..."); - + CURLcode ret; CURL *handle; struct curl_httppost *post = NULL; struct curl_httppost *last = NULL; handle = curl_easy_init(); - curl_easy_setopt(handle, CURLOPT_URL, m_sSubmitURL.c_str()); + curl_easy_setopt(handle, CURLOPT_URL, url); curl_formadd(&post, &last, CURLFORM_COPYNAME, "oopsdata", - CURLFORM_COPYCONTENTS, pCrashReport.find(FILENAME_KERNELOOPS)->second[CD_CONTENT].c_str(), + CURLFORM_COPYCONTENTS, oopsdata, CURLFORM_END); curl_formadd(&post, &last, CURLFORM_COPYNAME, "pass_on_allowed", @@ -80,10 +82,30 @@ void CKerneloopsReporter::Report(const map_crash_report_t& pCrashReport, const s curl_easy_setopt(handle, CURLOPT_HTTPPOST, post); curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, writefunction); - curl_easy_perform(handle); + ret = curl_easy_perform(handle); curl_formfree(post); curl_easy_cleanup(handle); + + return ret != 0; +} + + +/* class CKerneloopsReporter */ + +CKerneloopsReporter::CKerneloopsReporter() : + m_sSubmitURL("http://submit.kerneloops.org/submitoops.php") +{} + +void CKerneloopsReporter::Report(const map_crash_report_t& pCrashReport, const std::string& pArgs) +{ + comm_layer_inner_status("Creating and submitting a report..."); + + /* TODO: react on errorcode (!0 -> error) */ + http_post_to_kerneloops_site( + m_sSubmitURL.c_str(), + pCrashReport.find(FILENAME_KERNELOOPS)->second[CD_CONTENT].c_str() + ); } void CKerneloopsReporter::LoadSettings(const std::string& pPath) diff --git a/lib/Plugins/KerneloopsScanner.cpp b/lib/Plugins/KerneloopsScanner.cpp index 3134d342..01020e68 100644 --- a/lib/Plugins/KerneloopsScanner.cpp +++ b/lib/Plugins/KerneloopsScanner.cpp @@ -21,17 +21,25 @@ void CKerneloopsScanner::Run(const std::string& pActionDir, { int cnt_FoundOopses; + /* Scan syslog file, on first call only */ if (!m_bSysLogFileScanned) { - cnt_FoundOopses = ScanSysLogFile(m_sSysLogFile.c_str(), 1); + cnt_FoundOopses = ScanSysLogFile(m_sSysLogFile.c_str()); if (cnt_FoundOopses > 0) { SaveOopsToDebugDump(); + /* + * This marker in syslog file prevents us from re-parsing + * old oopses (any oops before it is ignored by ScanSysLogFile()). + * The only problem is that we can't be sure here + * that m_sSysLogFile is the file where syslog(xxx) stuff ends up. + */ openlog("abrt", 0, LOG_KERN); syslog(LOG_WARNING, "Kerneloops: Reported %u kernel oopses to Abrt", cnt_FoundOopses); closelog(); } m_bSysLogFileScanned = true; } + /* Scan kernel's log buffer */ cnt_FoundOopses = ScanDmesg(); if (cnt_FoundOopses > 0) SaveOopsToDebugDump(); @@ -41,16 +49,14 @@ void CKerneloopsScanner::SaveOopsToDebugDump() { comm_layer_inner_status("Creating kernel oops crash reports..."); - CDebugDump debugDump; - char path[PATH_MAX]; - std::list<COops> oopsList; - time_t t = time(NULL); - - oopsList = m_pSysLog.GetOopsList(); + CDebugDump debugDump; + std::list<COops> oopsList = m_pSysLog.GetOopsList(); 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()); COops oops = oopsList.back(); @@ -79,17 +85,18 @@ int CKerneloopsScanner::ScanDmesg() int cnt_FoundOopses; char *buffer; + int pagesz = getpagesize(); - buffer = (char*)xzalloc(getpagesize()+1); + buffer = (char*)xzalloc(pagesz + 1); - syscall(__NR_syslog, 3, buffer, getpagesize()); + syscall(__NR_syslog, 3, buffer, pagesz); cnt_FoundOopses = m_pSysLog.ExtractOops(buffer, strlen(buffer), 0); free(buffer); return cnt_FoundOopses; } -int CKerneloopsScanner::ScanSysLogFile(const char *filename, int issyslog) +int CKerneloopsScanner::ScanSysLogFile(const char *filename) { comm_layer_inner_debug("Scanning syslog..."); @@ -128,7 +135,7 @@ int CKerneloopsScanner::ScanSysLogFile(const char *filename, int issyslog) cnt_FoundOopses = 0; if (sz > 0) - cnt_FoundOopses = m_pSysLog.ExtractOops(buffer, sz, issyslog); + cnt_FoundOopses = m_pSysLog.ExtractOops(buffer, sz, 1); free(buffer); return cnt_FoundOopses; diff --git a/lib/Plugins/KerneloopsScanner.h b/lib/Plugins/KerneloopsScanner.h index 08f8c6c3..ccc2606e 100644 --- a/lib/Plugins/KerneloopsScanner.h +++ b/lib/Plugins/KerneloopsScanner.h @@ -12,10 +12,13 @@ class CKerneloopsScanner : public CAction CSysLog m_pSysLog; bool m_bSysLogFileScanned; + public: + /* For standalone oops processor */ void SaveOopsToDebugDump(); int ScanDmesg(); - int ScanSysLogFile(const char *filename, int issyslog); - public: + int ScanSysLogFile(const char *filename); + + /* Plugin intarface */ CKerneloopsScanner() : m_sSysLogFile("/var/log/messages"), m_bSysLogFileScanned(false) diff --git a/lib/Plugins/KerneloopsSysLog.cpp b/lib/Plugins/KerneloopsSysLog.cpp index a30fc69d..e64be504 100644 --- a/lib/Plugins/KerneloopsSysLog.cpp +++ b/lib/Plugins/KerneloopsSysLog.cpp @@ -89,7 +89,7 @@ void CSysLog::ClearOopsList() m_OopsQueue.clear(); } -std::list<COops> CSysLog::GetOopsList() +const std::list<COops>& CSysLog::GetOopsList() { return m_OopsQueue; } diff --git a/lib/Plugins/KerneloopsSysLog.h b/lib/Plugins/KerneloopsSysLog.h index ff4c8ba2..dc88d9ca 100644 --- a/lib/Plugins/KerneloopsSysLog.h +++ b/lib/Plugins/KerneloopsSysLog.h @@ -48,7 +48,7 @@ class CSysLog public: CSysLog(); - std::list<COops> GetOopsList(); + const std::list<COops>& GetOopsList(); void ClearOopsList(); int ExtractOops(char *buffer, size_t buflen, int remove_syslog); }; diff --git a/lib/Utils/Makefile.am b/lib/Utils/Makefile.am index fb4f578a..60431a59 100644 --- a/lib/Utils/Makefile.am +++ b/lib/Utils/Makefile.am @@ -1,5 +1,10 @@ lib_LTLIBRARIES = libABRTUtils.la -libABRTUtils_la_SOURCES = DebugDump.cpp DebugDump.h logging.cpp read_write.cpp xfuncs.cpp +libABRTUtils_la_SOURCES = \ + DebugDump.cpp DebugDump.h \ + xfuncs.cpp \ + read_write.cpp \ + logging.cpp + libABRTUtils_la_LDFLAGS = -version-info 0:1:0 libABRTUtils_la_LIBADD = -lmagic libABRTUtils_la_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../../lib/CommLayer diff --git a/src/Applet/Makefile.am b/src/Applet/Makefile.am index bbf65999..26658504 100644 --- a/src/Applet/Makefile.am +++ b/src/Applet/Makefile.am @@ -6,7 +6,7 @@ abrt_applet_CPPFLAGS = -Wall -Werror -I../Daemon/ \ $(DBUS_GLIB_CFLAGS) $(GTK_CFLAGS) $(DBUSCPP_CFLAGS) $(LIBNOTIFY_CFLAGS)\ -I$(srcdir)/../../inc -I../../lib/CommLayer \ -I../../lib/MiddleWare -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include - + abrt_applet_LDADD = $(DL_LIBS) $(GTK_LIBS) -lglib-2.0 -lgthread-2.0 $(DBUSCPP_LIBS) $(LIBNOTIFY_LIBS) EXTRA_DIST = abrt-applet.desktop diff --git a/src/Daemon/Makefile.am b/src/Daemon/Makefile.am index 61d19207..b6a66f69 100644 --- a/src/Daemon/Makefile.am +++ b/src/Daemon/Makefile.am @@ -8,7 +8,7 @@ abrt_CPPFLAGS = -I$(srcdir)/../../lib/MiddleWare -I$(srcdir)/../../lib/CommLayer -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \ -DCONF_DIR=\"$(CONF_DIR)\" \ -DVAR_RUN=\"$(VAR_RUN)\" $(ENABLE_SOCKET_OR_DBUS) - + abrt_LDADD = ../../lib/MiddleWare/libABRTMiddleWare.la ../../lib/CommLayer/libABRTCommLayer.la $(DL_LIBS) $(DBUSCPP_LIBS) $(RPM_LIBS) dbusabrtconfdir = ${sysconfdir}/dbus-1/system.d/ dist_dbusabrtconf_DATA = dbus-abrt.conf |