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 | |
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>
-rw-r--r-- | abrt.spec | 1 | ||||
-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 | ||||
-rw-r--r-- | src/daemon/Makefile.am | 23 | ||||
-rw-r--r-- | src/daemon/abrt-action-kerneloops.cpp | 193 |
7 files changed, 312 insertions, 104 deletions
@@ -419,6 +419,7 @@ fi %{_libdir}/%{name}/KerneloopsReporter.glade %{_mandir}/man7/abrt-KerneloopsReporter.7.gz %{_sbindir}/abrt-action-analyze-oops +%{_bindir}/abrt-action-kerneloops %files plugin-logger %defattr(-,root,root,-) 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"; diff --git a/src/daemon/Makefile.am b/src/daemon/Makefile.am index 06b1d44f..0129ffc6 100644 --- a/src/daemon/Makefile.am +++ b/src/daemon/Makefile.am @@ -13,6 +13,7 @@ sbin_PROGRAMS = abrtd \ bin_PROGRAMS = \ abrt-action-bugzilla \ abrt-action-rhtsupport \ + abrt-action-kerneloops \ abrt-action-print abrtd_SOURCES = \ @@ -201,6 +202,28 @@ abrt_action_rhtsupport_LDADD = \ ../../lib/utils/libABRTdUtils.la \ ../../lib/utils/libABRTUtils.la +abrt_action_kerneloops_SOURCES = \ + abrt-action-kerneloops.cpp +abrt_action_kerneloops_CPPFLAGS = \ + -I$(srcdir)/../../inc \ + -I$(srcdir)/../../lib/utils \ + -DBIN_DIR=\"$(bindir)\" \ + -DVAR_RUN=\"$(VAR_RUN)\" \ + -DCONF_DIR=\"$(CONF_DIR)\" \ + -DLOCALSTATEDIR='"$(localstatedir)"' \ + -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ + -DDEBUG_INFO_DIR=\"$(DEBUG_INFO_DIR)\" \ + -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \ + -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \ + $(GLIB_CFLAGS) \ + $(CURL_CFLAGS) \ + -D_GNU_SOURCE \ + -Wall -Werror +abrt_action_kerneloops_LDADD = \ + $(CURL_LIBS) \ + ../../lib/utils/libABRTdUtils.la \ + ../../lib/utils/libABRTUtils.la + abrt_action_print_SOURCES = \ abrt-action-print.cpp abrt_action_print_CPPFLAGS = \ diff --git a/src/daemon/abrt-action-kerneloops.cpp b/src/daemon/abrt-action-kerneloops.cpp new file mode 100644 index 00000000..0d0b35c4 --- /dev/null +++ b/src/daemon/abrt-action-kerneloops.cpp @@ -0,0 +1,193 @@ +/* + Copyright (C) 2010 ABRT team + Copyright (C) 2010 RedHat Inc + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + Authors: + Anton Arapov <anton@redhat.com> + Arjan van de Ven <arjan@linux.intel.com> + */ + +#include <curl/curl.h> +#include "abrtlib.h" +#include "crash_types.h" +#include "abrt_exception.h" + +#include "plugin.h" /* LoadPluginSettings */ + +#define PROGNAME "abrt-action-kerneloops" + +/* 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); +*/ + + return size; +} + +/* 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) +{ + CURLcode ret; + CURL *handle; + struct curl_httppost *post = NULL; + struct curl_httppost *last = NULL; + + handle = curl_easy_init(); + if (!handle) + error_msg_and_die("Can't create curl handle"); + + 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); + + ret = curl_easy_perform(handle); + + curl_formfree(post); + curl_easy_cleanup(handle); + + return ret; +} + +static void report_to_kerneloops( + const char *dump_dir_name, + /*const*/ map_plugin_settings_t& settings) +{ + struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); + if (!dd) + throw CABRTException(EXCEP_PLUGIN, _("Can't open '%s'"), dump_dir_name); + map_crash_data_t pCrashData; + load_crash_data_from_debug_dump(dd, pCrashData); + dd_close(dd); + + const char *backtrace = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_BACKTRACE); + if (!backtrace) + throw CABRTException(EXCEP_PLUGIN, "Error sending kernel oops due to missing backtrace"); +//TODO: check that analyzer == "oops" too? + + const char *submitURL = settings["SubmitURL"].c_str(); + if (!submitURL[0]) + submitURL = "http://submit.kerneloops.org/submitoops.php"; + + log(_("Submitting oops report to %s"), submitURL); + + CURLcode ret = http_post_to_kerneloops_site(submitURL, backtrace); + if (ret != CURLE_OK) + throw CABRTException(EXCEP_PLUGIN, "Kernel oops has not been sent due to %s", curl_easy_strerror(ret)); + + /* Server replies with: + * 200 thank you for submitting the kernel oops information + * RemoteIP: 34192fd15e34bf60fac6a5f01bba04ddbd3f0558 + * - no URL or bug ID apparently... + */ + printf("STATUS:Kernel oops report was uploaded\n"); +} + +int main(int argc, char **argv) +{ + char *env_verbose = getenv("ABRT_VERBOSE"); + if (env_verbose) + g_verbose = atoi(env_verbose); + + map_plugin_settings_t settings; + + const char *dump_dir_name = "."; + enum { + OPT_s = (1 << 0), + }; + int optflags = 0; + int opt; + while ((opt = getopt(argc, argv, "c:d:vs")) != -1) + { + switch (opt) + { + case 'c': + dump_dir_name = optarg; + VERB1 log("Loading settings from '%s'", optarg); + LoadPluginSettings(optarg, settings); + VERB3 log("Loaded '%s'", optarg); + break; + case 'd': + dump_dir_name = optarg; + break; + case 'v': + g_verbose++; + break; + case 's': + optflags |= OPT_s; + break; + default: + /* Careful: the string below contains tabs, dont replace with spaces */ + error_msg_and_die( + "Usage: "PROGNAME" -c CONFFILE -d DIR [-vs]" + "\n" + "\nReport a kernel oops to kerneloops.org (or similar) site" + "\n" + "\nOptions:" + "\n -c FILE Configuration file (may be given many times)" + "\n -d DIR Crash dump directory" + "\n -v Verbose" + "\n -s Log to syslog" + ); + } + } + + putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); + +//DONT! our stdout/stderr goes directly to daemon, don't want to have prefix there. +// msg_prefix = xasprintf(PROGNAME"[%u]", getpid()); + + if (optflags & OPT_s) + { + openlog(msg_prefix, 0, LOG_DAEMON); + logmode = LOGMODE_SYSLOG; + } + + try + { + report_to_kerneloops(dump_dir_name, settings); + } + catch (CABRTException& e) + { + printf("EXCEPT:%s\n", e.what()); + return 1; + } + + return 0; +} |