* Wed Jun 24 2009 Gavin Romig-Koch - add and Action plugin that creates an sosreport and copies it into the Debug Dump directory. diff --git a/abrt.spec b/abrt.spec index 0518641..1a8260a 100644 --- a/abrt.spec +++ b/abrt.spec @@ -128,6 +128,14 @@ Requires: %{name} = %{version}-%{release} %description plugin-runapp Plugin to run external programs. +%package plugin-sosreportaction +Summary: %{name}'s sosreport plugin +Group: System Environment/Libraries +Requires: %{name} = %{version}-%{release} + +%description plugin-sosreportaction +Plugin to include an sosreport in an abrt report. + %package plugin-bugzilla Summary: %{name}'s bugzilla plugin Group: System Environment/Libraries @@ -277,6 +285,10 @@ fi %{_libdir}/%{name}/libRunApp.so* %{_mandir}/man7/%{name}-RunApp.7.gz +%files plugin-sosreportaction +%defattr(-,root,root,-) +%{_libdir}/%{name}/libsosreportaction.so* + %files plugin-bugzilla %defattr(-,root,root,-) %config(noreplace) %{_sysconfdir}/%{name}/plugins/Bugzilla.conf diff --git a/lib/Plugins/Makefile.am b/lib/Plugins/Makefile.am index 4a0bd2b..97a80a8 100644 --- a/lib/Plugins/Makefile.am +++ b/lib/Plugins/Makefile.am @@ -8,6 +8,7 @@ pluginslib_LTLIBRARIES = libCCpp.la \ libKerneloopsReporter.la\ libKerneloops.la \ libRunApp.la \ + libSOSreportAction.la \ libBugzilla.la \ libPython.la \ libFileTransfer.la @@ -61,6 +62,10 @@ libLogger_la_LDFLAGS = -avoid-version libRunApp_la_SOURCES = RunApp.h RunApp.cpp libRunApp_la_LDFLAGS = -avoid-version +# SOSreportAction +libSOSreportAction_la_SOURCES = SOSreportAction.cpp SOSreportAction.h +libSOSreportAction_la_LDFLAGS = -avoid-version + # Bugzilla libBugzilla_la_SOURCES = Bugzilla.h Bugzilla.cpp PluginSettings.h libBugzilla_la_LIBADD = $(XMLRPC_CPP_LIBS) $(XMLRPC_CLIENT_CPP_LIBS) $(NSS_LIBS) diff --git a/lib/Plugins/SOSreportAction.cpp b/lib/Plugins/SOSreportAction.cpp new file mode 100644 index 0000000..facdc5b --- /dev/null +++ b/lib/Plugins/SOSreportAction.cpp @@ -0,0 +1,128 @@ +/* + SOSreportAction.cpp + + Copyright (C) 2009 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. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "SOSreportAction.h" + +#include +#include +#include + +#include +#include + +#include "DebugDump.h" +#include "ABRTException.h" +#include "CommLayerInner.h" + + + +static void copy_file(std::string source_name, std::string dest_name) +{ + std::ifstream source(source_name.c_str(), std::fstream::binary); + + if (!source) + { + throw CABRTException(EXCEP_PLUGIN, "CActionSOSreport::Run(): could not open input sosreport filename:" + source_name); + } + std::ofstream dest(dest_name.c_str(),std::fstream::trunc|std::fstream::binary); + if (!dest) + { + throw CABRTException(EXCEP_PLUGIN, "CActionSOSreport::Run(): could not open output sosreport filename:" + dest_name); + } + dest << source.rdbuf(); +} + + + + +static const char sosreport_filename_marker[] = + "Your sosreport has been generated and saved in:"; + +typedef std::string::size_type index_type; +static void error_check(index_type i) +{ + if (i == std::string::npos) + { + throw CABRTException(EXCEP_PLUGIN, std::string("CActionSOSreport::Run(): could not find filename in sosreport output")); + } +} + +static std::string parse_filename(std::string output) +{ + /* + the sosreport's filename is embedded in sosreport's output. + It appears on the line after the string in 'sosreport_filename_marker', + it has leading spaces, and a trailing newline. This function trims + any leading and trailing whitespace from the filename. + */ + + + index_type p = output.find(sosreport_filename_marker); + error_check(p); + + p += strlen(sosreport_filename_marker); + + index_type filename_start = output.find_first_not_of(" \n\t", p); + error_check(p); + + index_type line_end = output.find_first_of('\n',filename_start); + error_check(p); + + index_type filename_end = output.find_last_not_of(" \n\t",line_end); + error_check(p); + + return output.substr(filename_start,(filename_end-filename_start)+1); +} + + + + +void CActionSOSreport::Run(const std::string& pActionDir, + const std::string& pArgs) +{ + comm_layer_inner_status("Executing SOSreportAction plugin..."); + + const char command[] = "sosreport --batch --no-progressbar -k rpm.rpmva=off 2>&1"; + + FILE *fp = popen(command, "r"); + if (fp == NULL) + { + throw CABRTException(EXCEP_PLUGIN, std::string("CActionSOSreport::Run(): cannot execute ") + command); + } + + std::ostringstream output_stream; + __gnu_cxx::stdio_filebuf command_output_buffer(fp, std::ios_base::in); + + output_stream << std::string(command) << std::endl; + output_stream << &command_output_buffer; + + pclose(fp); + + std::string output = output_stream.str(); + std::string sosreport_filename = parse_filename(output); + std::string sosreport_dd_filename = pActionDir + "/sosreport.tar.bz2"; + + CDebugDump dd; + dd.Open(pActionDir); + dd.SaveText("sosreportoutput", output); + copy_file(sosreport_filename,sosreport_dd_filename); + + dd.Close(); +} diff --git a/lib/Plugins/SOSreportAction.h b/lib/Plugins/SOSreportAction.h new file mode 100644 index 0000000..1db1a8d --- /dev/null +++ b/lib/Plugins/SOSreportAction.h @@ -0,0 +1,42 @@ +/* + SOSreportAction.h - Attach an sosreport to a crash dump + + Copyright (C) 2009 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. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef SOSREPORTACTION_H_ +#define SOSREPORTACTION_H_ + +#include "Action.h" + +class CActionSOSreport : public CAction +{ + public: + virtual ~CActionSOSreport() {} + virtual void Run(const std::string& pActionDir, + const std::string& pArgs); +}; + +PLUGIN_INFO(ACTION, + CActionSOSreport , + "SOSreportAction", + "0.0.1", + "Run sosreport, save the output in the crash dump", + "gavin@redhat.com", + "https://fedorahosted.org/crash-catcher/wiki"); + +#endif