summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--inc/abrtlib.h4
-rw-r--r--lib/Plugins/SOSreport.cpp22
-rw-r--r--lib/Utils/Makefile.am3
-rw-r--r--lib/Utils/popen_and_save_output.cpp30
-rw-r--r--lib/Utils/stringops.cpp2
5 files changed, 39 insertions, 22 deletions
diff --git a/inc/abrtlib.h b/inc/abrtlib.h
index b6fb1721..257f5571 100644
--- a/inc/abrtlib.h
+++ b/inc/abrtlib.h
@@ -203,8 +203,6 @@ bool dot_or_dotdot(const char *filename);
char *last_char_is(const char *s, int c);
bool string_to_bool(const char *s);
-void parse_args(const char *psArgs, vector_string_t& pArgs, const char quote = -1);
-
/* C++ style stuff */
std::string ssprintf(const char *format, ...);
@@ -220,6 +218,8 @@ to_string(T x)
return o.str();
}
+std::string popen_and_save_output(const char *cmd);
+void parse_args(const char *psArgs, vector_string_t& pArgs, int quote = -1);
void parse_release(const char *pRelease, std::string& pProduct, std::string& pVersion);
#endif
diff --git a/lib/Plugins/SOSreport.cpp b/lib/Plugins/SOSreport.cpp
index b949339f..287c01e9 100644
--- a/lib/Plugins/SOSreport.cpp
+++ b/lib/Plugins/SOSreport.cpp
@@ -18,7 +18,6 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include <ext/stdio_filebuf.h>
#include <fstream>
#include <sstream>
#include "abrtlib.h"
@@ -56,7 +55,7 @@ static std::string ParseFilename(const std::string& pOutput)
int filename_start = pOutput.find_first_not_of(" \n\t", p);
ErrorCheck(p);
- int line_end = pOutput.find_first_of('\n',filename_start);
+ int line_end = pOutput.find_first_of('\n', filename_start);
ErrorCheck(p);
int filename_end = pOutput.find_last_not_of(" \n\t", line_end);
@@ -90,24 +89,11 @@ void CActionSOSreport::Run(const char *pActionDir, const char *pArgs)
}
update_client(_("running sosreport: %s"), command.c_str());
- FILE *fp = popen(command.c_str(), "r");
- if (fp == NULL)
- {
- throw CABRTException(EXCEP_PLUGIN, ssprintf("Can't execute '%s'", command.c_str()));
- }
-
-//vda TODO: fix this mess
- std::ostringstream output_stream;
- __gnu_cxx::stdio_filebuf<char> command_output_buffer(fp, std::ios_base::in);
-
- output_stream << command << std::endl;
- output_stream << &command_output_buffer;
-
- pclose(fp);
+ std::string output = command;
+ output += '\n';
+ output += popen_and_save_output(command.c_str());
update_client(_("done running sosreport"));
- std::string output = output_stream.str();
-
std::string sosreport_filename = ParseFilename(output);
std::string sosreport_dd_filename = concat_path_file(pActionDir, "sosreport.tar.bz2");
diff --git a/lib/Utils/Makefile.am b/lib/Utils/Makefile.am
index 0ca7a2b1..f752992d 100644
--- a/lib/Utils/Makefile.am
+++ b/lib/Utils/Makefile.am
@@ -5,13 +5,14 @@ lib_LTLIBRARIES = libABRTUtils.la
# xconnect.cpp
libABRTUtils_la_SOURCES = \
- stringops.cpp \
+ stringops.cpp \
xfuncs.cpp \
encbase64.cpp \
read_write.cpp \
logging.cpp \
copyfd.cpp \
skip_whitespace.cpp \
+ popen_and_save_output.cpp \
parse_release.cpp \
CrashTypesSocket.cpp \
DebugDump.h DebugDump.cpp \
diff --git a/lib/Utils/popen_and_save_output.cpp b/lib/Utils/popen_and_save_output.cpp
new file mode 100644
index 00000000..4bcbcac4
--- /dev/null
+++ b/lib/Utils/popen_and_save_output.cpp
@@ -0,0 +1,30 @@
+/*
+ * Utility routines.
+ *
+ * Licensed under GPLv2 or later, see file COPYING in this tarball for details.
+ */
+#include "abrtlib.h"
+
+using namespace std;
+
+string popen_and_save_output(const char *cmd)
+{
+ string result;
+
+ FILE *fp = popen(cmd, "r");
+ if (fp == NULL) /* fork or pipe failed; or out-of-mem */
+ {
+ return result;
+ }
+
+ size_t sz;
+ char buf[BUFSIZ + 1];
+ while ((sz = fread(buf, 1, sizeof(buf)-1, fp)) > 0)
+ {
+ buf[sz] = '\0';
+ result += buf;
+ }
+ pclose(fp);
+
+ return result;
+}
diff --git a/lib/Utils/stringops.cpp b/lib/Utils/stringops.cpp
index 73084fc1..1b3793fc 100644
--- a/lib/Utils/stringops.cpp
+++ b/lib/Utils/stringops.cpp
@@ -1,6 +1,6 @@
#include "abrtlib.h"
-void parse_args(const char *psArgs, vector_string_t& pArgs, const char quote)
+void parse_args(const char *psArgs, vector_string_t& pArgs, int quote)
{
unsigned ii;
bool is_quote = false;