summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2010-10-25 18:45:26 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2010-10-25 18:45:26 +0200
commit80b386c9e03117e12699d22e24edd602011bcd72 (patch)
tree340deb0ec37dfcdfda52f854c2a73ad8d5bbcbdd /src
parentd50f3cd388ebc2c8772d874aae0340489957fbcb (diff)
downloadabrt-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 'src')
-rw-r--r--src/daemon/Makefile.am23
-rw-r--r--src/daemon/abrt-action-kerneloops.cpp193
2 files changed, 216 insertions, 0 deletions
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;
+}