diff options
author | Zdenek Prikryl <zprikryl@redhat.com> | 2009-06-29 15:24:05 +0200 |
---|---|---|
committer | Zdenek Prikryl <zprikryl@redhat.com> | 2009-06-29 15:24:05 +0200 |
commit | 8feaaef63d35bd3f16a807a07d026ab3c620c702 (patch) | |
tree | 20dc77b015c443ca65efb54e4e80d0c172192dc2 /lib/Plugins | |
parent | 7171080b4efbc279408047a7a2bf49fec3866456 (diff) | |
download | abrt-8feaaef63d35bd3f16a807a07d026ab3c620c702.tar.gz abrt-8feaaef63d35bd3f16a807a07d026ab3c620c702.tar.xz abrt-8feaaef63d35bd3f16a807a07d026ab3c620c702.zip |
New SOSreport plugin. Written by Gavin Romig-Koch (gavin@redhat.com)
Diffstat (limited to 'lib/Plugins')
-rw-r--r-- | lib/Plugins/SOSreport.cpp | 116 | ||||
-rw-r--r-- | lib/Plugins/SOSreport.h | 49 |
2 files changed, 165 insertions, 0 deletions
diff --git a/lib/Plugins/SOSreport.cpp b/lib/Plugins/SOSreport.cpp new file mode 100644 index 00000000..2790cd25 --- /dev/null +++ b/lib/Plugins/SOSreport.cpp @@ -0,0 +1,116 @@ +/* + SOSreport.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 "SOSreport.h" + +#include <stdio.h> +#include <string.h> +#include <ext/stdio_filebuf.h> + +#include <fstream> +#include <sstream> + +#include "DebugDump.h" +#include "ABRTException.h" +#include "CommLayerInner.h" + + +void CActionSOSreport::CopyFile(const std::string& pSourceName, const std::string& pDestName) +{ + std::ifstream source(pSourceName.c_str(), std::fstream::binary); + + if (!source) + { + throw CABRTException(EXCEP_PLUGIN, "CActionSOSreport::CopyFile(): could not open input sosreport filename:" + pSourceName); + } + std::ofstream dest(pDestName.c_str(),std::fstream::trunc|std::fstream::binary); + if (!dest) + { + throw CABRTException(EXCEP_PLUGIN, "CActionSOSreport::CopyFile(): could not open output sosreport filename:" + pDestName); + } + dest << source.rdbuf(); +} + +void CActionSOSreport::ErrorCheck(const index_type pI) +{ + if (pI == std::string::npos) + { + throw CABRTException(EXCEP_PLUGIN, std::string("CActionSOSreport::ErrorCheck(): could not find filename in sosreport output")); + } +} + +std::string CActionSOSreport::ParseFilename(const std::string& pOutput) +{ + /* + 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. + */ + static const char sosreport_filename_marker[] = + "Your sosreport has been generated and saved in:"; + + index_type p = pOutput.find(sosreport_filename_marker); + ErrorCheck(p); + + p += strlen(sosreport_filename_marker); + + index_type filename_start = pOutput.find_first_not_of(" \n\t", p); + ErrorCheck(p); + + index_type line_end = pOutput.find_first_of('\n',filename_start); + ErrorCheck(p); + + index_type filename_end = pOutput.find_last_not_of(" \n\t",line_end); + ErrorCheck(p); + + return pOutput.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<char> 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 = ParseFilename(output); + std::string sosreport_dd_filename = pActionDir + "/sosreport.tar.bz2"; + + CDebugDump dd; + dd.Open(pActionDir); + CopyFile(sosreport_filename,sosreport_dd_filename); + dd.Close(); +} diff --git a/lib/Plugins/SOSreport.h b/lib/Plugins/SOSreport.h new file mode 100644 index 00000000..f08cd8ce --- /dev/null +++ b/lib/Plugins/SOSreport.h @@ -0,0 +1,49 @@ +/* + SOSreport.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 SOSREPORT_H_ +#define SOSREPORT_H_ + +#include "Action.h" + +class CActionSOSreport : public CAction +{ + private: + typedef std::string::size_type index_type; + + void CopyFile(const std::string& pSourceName, const std::string& pDestName); + void ErrorCheck(const index_type pI); + std::string ParseFilename(const std::string& pOutput); + + public: + virtual ~CActionSOSreport() {} + virtual void Run(const std::string& pActionDir, + const std::string& pArgs); +}; + +PLUGIN_INFO(ACTION, + CActionSOSreport , + "SOSreport", + "0.0.2", + "Run sosreport, save the output in the crash dump", + "gavin@redhat.com", + "https://fedorahosted.org/abrt/wiki"); + +#endif |