diff options
| author | Denys Vlasenko <dvlasenk@redhat.com> | 2010-10-25 18:45:26 +0200 |
|---|---|---|
| committer | Denys Vlasenko <dvlasenk@redhat.com> | 2010-10-25 18:45:26 +0200 |
| commit | 80b386c9e03117e12699d22e24edd602011bcd72 (patch) | |
| tree | 340deb0ec37dfcdfda52f854c2a73ad8d5bbcbdd /lib/plugins | |
| parent | d50f3cd388ebc2c8772d874aae0340489957fbcb (diff) | |
| download | abrt-80b386c9e03117e12699d22e24edd602011bcd72.tar.gz abrt-80b386c9e03117e12699d22e24edd602011bcd72.tar.xz abrt-80b386c9e03117e12699d22e24edd602011bcd72.zip | |
new action tool: abrt-action-kerneloops
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'lib/plugins')
| -rw-r--r-- | lib/plugins/KerneloopsReporter.cpp | 188 | ||||
| -rw-r--r-- | lib/plugins/KerneloopsReporter.h | 6 | ||||
| -rw-r--r-- | lib/plugins/Makefile.am | 3 | ||||
| -rw-r--r-- | lib/plugins/RHTSupport.cpp | 2 |
4 files changed, 95 insertions, 104 deletions
diff --git a/lib/plugins/KerneloopsReporter.cpp b/lib/plugins/KerneloopsReporter.cpp index edb333b0..ae459737 100644 --- a/lib/plugins/KerneloopsReporter.cpp +++ b/lib/plugins/KerneloopsReporter.cpp @@ -18,125 +18,121 @@ */ #include "abrtlib.h" -#include "abrt_curl.h" -#include "KerneloopsReporter.h" #include "comm_layer_inner.h" #include "abrt_exception.h" +#include "KerneloopsReporter.h" -/* helpers */ -static size_t writefunction(void *ptr, size_t size, size_t nmemb, void *stream) -{ - size *= nmemb; -/* - char *c, *c1, *c2; - - 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; - c2 = strchr(c1, '\n'); - if (c2) - *c2 = 0; - } - free(c); -*/ +using namespace std; - return size; +CKerneloopsReporter::CKerneloopsReporter() +{ + m_pSettings["SubmitURL"] = "http://submit.kerneloops.org/submitoops.php"; } -/* Send oops data to kerneloops.org-style site, using HTTP POST */ -/* Returns 0 on success */ -static CURLcode http_post_to_kerneloops_site(const char *url, const char *oopsdata) +CKerneloopsReporter::~CKerneloopsReporter() { - CURLcode ret; - CURL *handle; - struct curl_httppost *post = NULL; - struct curl_httppost *last = NULL; - - handle = xcurl_easy_init(); - curl_easy_setopt(handle, CURLOPT_URL, url); - - curl_formadd(&post, &last, - CURLFORM_COPYNAME, "oopsdata", - CURLFORM_COPYCONTENTS, oopsdata, - CURLFORM_END); - curl_formadd(&post, &last, - CURLFORM_COPYNAME, "pass_on_allowed", - CURLFORM_COPYCONTENTS, "yes", - CURLFORM_END); - +} - curl_easy_setopt(handle, CURLOPT_HTTPPOST, post); - curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, writefunction); +void CKerneloopsReporter::SetSettings(const map_plugin_settings_t& pSettings) +{ + /* Can't simply do this: - ret = curl_easy_perform(handle); + m_pSettings = pSettings; - curl_formfree(post); - curl_easy_cleanup(handle); + * - it will erase keys which aren't present in pSettings. + * Example: if Bugzilla.conf doesn't have "Login = foo", + * then there's no pSettings["Login"] and m_pSettings = pSettings + * will nuke default m_pSettings["Login"] = "", + * making GUI think that we have no "Login" key at all + * and thus never overriding it - even if it *has* an override! + */ - return ret; + map_plugin_settings_t::iterator it = m_pSettings.begin(); + while (it != m_pSettings.end()) + { + map_plugin_settings_t::const_iterator override = pSettings.find(it->first); + if (override != pSettings.end()) + { + VERB3 log(" kerneloops settings[%s]='%s'", it->first.c_str(), it->second.c_str()); + it->second = override->second; + } + it++; + } } - -/* class CKerneloopsReporter */ -CKerneloopsReporter::CKerneloopsReporter() : - m_sSubmitURL("http://submit.kerneloops.org/submitoops.php") -{} - -std::string CKerneloopsReporter::Report(const map_crash_data_t& pCrashData, - const map_plugin_settings_t& pSettings, - const char *pArgs) +string CKerneloopsReporter::Report(const map_crash_data_t& crash_data, + const map_plugin_settings_t& settings, + const char *args) { - CURLcode ret = CURLE_OK; + /* abrt-action-kerneloops [-s] -c /etc/arbt/Kerneloops.conf -c - -d pCrashData.dir NULL */ + char *argv[9]; + char **pp = argv; + *pp++ = (char*)"abrt-action-kerneloops"; + +//We want to consume output, so don't redirect to syslog. +// if (logmode & LOGMODE_SYSLOG) +// *pp++ = (char*)"-s"; +//TODO: the actions<->daemon interaction will be changed anyway... + + *pp++ = (char*)"-c"; + *pp++ = (char*)(PLUGINS_CONF_DIR"/Kerneloops."PLUGINS_CONF_EXTENSION); + *pp++ = (char*)"-c"; + *pp++ = (char*)"-"; + *pp++ = (char*)"-d"; + *pp++ = (char*)get_crash_data_item_content_or_NULL(crash_data, CD_DUMPDIR); + *pp = NULL; + int pipefds[2]; + pid_t pid = fork_execv_on_steroids(EXECFLG_INPUT + EXECFLG_OUTPUT + EXECFLG_ERR2OUT, + argv, + pipefds, + /* unsetenv_vec: */ NULL, + /* dir: */ NULL, + /* uid(unused): */ 0 + ); - update_client(_("Creating and submitting a report...")); + /* Write the configuration to stdin */ + map_plugin_settings_t::const_iterator it = settings.begin(); + while (it != settings.end()) + { + full_write_str(pipefds[1], it->first.c_str()); + full_write_str(pipefds[1], "="); + full_write_str(pipefds[1], it->second.c_str()); + full_write_str(pipefds[1], "\n"); + it++; + } + close(pipefds[1]); - map_crash_data_t::const_iterator it = pCrashData.find(FILENAME_BACKTRACE); - if (it == pCrashData.end()) - throw CABRTException(EXCEP_PLUGIN, "Error sending kernel oops due to missing backtrace"); + FILE *fp = fdopen(pipefds[0], "r"); + if (!fp) + die_out_of_memory(); - ret = http_post_to_kerneloops_site( - m_sSubmitURL.c_str(), - it->second[CD_CONTENT].c_str() - ); - if (ret != CURLE_OK) + /* Consume log from stdout */ + string bug_status; + char *buf; + while ((buf = xmalloc_fgetline(fp)) != NULL) { - char* err_str = xasprintf("Kernel oops has not been sent due to %s", curl_easy_strerror(ret)); - CABRTException e(EXCEP_PLUGIN, err_str); - free(err_str); - throw e; + if (strncmp(buf, "STATUS:", 7) == 0) + bug_status = buf + 7; + else + if (strncmp(buf, "EXCEPT:", 7) == 0) + { + CABRTException e(EXCEP_PLUGIN, "%s", buf + 7); + free(buf); + fclose(fp); + waitpid(pid, NULL, 0); + throw e; + } + update_client("%s", buf); + free(buf); } - /* Server replies with: - * 200 thank you for submitting the kernel oops information - * RemoteIP: 34192fd15e34bf60fac6a5f01bba04ddbd3f0558 - * - no URL or bug ID apparently... - */ - return "Kernel oops report was uploaded"; -} + fclose(fp); /* this also closes pipefds[0] */ + /* wait for child to actually exit, and prevent leaving a zombie behind */ + waitpid(pid, NULL, 0); -void CKerneloopsReporter::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("SubmitURL"); - if (it != end) - m_sSubmitURL = it->second; + return bug_status; } -//ok to delete? -//const map_plugin_settings_t& CKerneloopsReporter::GetSettings() -//{ -// m_pSettings["SubmitURL"] = m_sSubmitURL; -// -// return m_pSettings; -//} - PLUGIN_INFO(REPORTER, CKerneloopsReporter, "KerneloopsReporter", diff --git a/lib/plugins/KerneloopsReporter.h b/lib/plugins/KerneloopsReporter.h index 679e5b0b..e0f4a1bb 100644 --- a/lib/plugins/KerneloopsReporter.h +++ b/lib/plugins/KerneloopsReporter.h @@ -34,15 +34,11 @@ class CKerneloopsReporter : public CReporter { - private: - std::string m_sSubmitURL; - public: CKerneloopsReporter(); + ~CKerneloopsReporter(); virtual void SetSettings(const map_plugin_settings_t& pSettings); -//ok to delete? -// virtual const map_plugin_settings_t& GetSettings(); virtual std::string Report(const map_crash_data_t& pCrashData, const map_plugin_settings_t& pSettings, const char *pArgs); diff --git a/lib/plugins/Makefile.am b/lib/plugins/Makefile.am index 22a9bcd4..537589ec 100644 --- a/lib/plugins/Makefile.am +++ b/lib/plugins/Makefile.am @@ -81,8 +81,7 @@ libKerneloops_la_CPPFLAGS = -I$(INC_PATH) -I$(UTILS_PATH) # KerneloopsReporter libKerneloopsReporter_la_SOURCES = KerneloopsReporter.cpp KerneloopsReporter.h libKerneloopsReporter_la_LDFLAGS = -avoid-version -libKerneloopsReporter_la_LIBADD = $(CURL_LIBS) -libKerneloopsReporter_la_CPPFLAGS = -I$(INC_PATH) -I$(UTILS_PATH) $(CURL_CFLAGS) -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" +libKerneloopsReporter_la_CPPFLAGS = -I$(INC_PATH) -I$(UTILS_PATH) -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" # KerneloopsScanner libKerneloopsScanner_la_SOURCES = KerneloopsScanner.cpp KerneloopsScanner.h KerneloopsSysLog.cpp KerneloopsSysLog.h diff --git a/lib/plugins/RHTSupport.cpp b/lib/plugins/RHTSupport.cpp index c7a3c060..3732afe3 100644 --- a/lib/plugins/RHTSupport.cpp +++ b/lib/plugins/RHTSupport.cpp @@ -68,7 +68,7 @@ string CReporterRHticket::Report(const map_crash_data_t& crash_data, const map_plugin_settings_t& settings, const char *args) { - /* abrt-action-bugzilla [-s] -c /etc/arbt/Bugzilla.conf -c - -d pCrashData.dir NULL */ + /* abrt-action-rhtsupport [-s] -c /etc/arbt/RHTSupport.conf -c - -d pCrashData.dir NULL */ char *argv[9]; char **pp = argv; *pp++ = (char*)"abrt-action-rhtsupport"; |
