aboutsummaryrefslogtreecommitdiff
path: root/src/function
diff options
context:
space:
mode:
authorAdrian Kummerlaender2014-10-16 19:20:04 +0200
committerAdrian Kummerlaender2014-10-16 19:20:04 +0200
commitbc48696d7f463d0a230193f2173ec8516a2ca4b0 (patch)
tree152f1c9cf1009b3c3b7067704683ee1c9e88ac68 /src/function
parenta4a7ee4f614e85f9952a4a8ea418e263512fc2ba (diff)
downloadInputXSLT-bc48696d7f463d0a230193f2173ec8516a2ca4b0.tar
InputXSLT-bc48696d7f463d0a230193f2173ec8516a2ca4b0.tar.gz
InputXSLT-bc48696d7f463d0a230193f2173ec8516a2ca4b0.tar.bz2
InputXSLT-bc48696d7f463d0a230193f2173ec8516a2ca4b0.tar.lz
InputXSLT-bc48696d7f463d0a230193f2173ec8516a2ca4b0.tar.xz
InputXSLT-bc48696d7f463d0a230193f2173ec8516a2ca4b0.tar.zst
InputXSLT-bc48696d7f463d0a230193f2173ec8516a2ca4b0.zip
Changed FunctionExternalCommand stream read order
* long outputs to stdout from child processes filled up the `boost::process::pistream` buffer and caused `write` to block ** this issue was circumvented by reading the stream into a `std::stringstream` instance before retrieving the blocking exit status * modified document import implementation accordingly
Diffstat (limited to 'src/function')
-rw-r--r--src/function/external_command.cc24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/function/external_command.cc b/src/function/external_command.cc
index 3819a43..40b02b9 100644
--- a/src/function/external_command.cc
+++ b/src/function/external_command.cc
@@ -15,19 +15,22 @@ namespace {
using InputXSLT::XercesStringGuard;
-inline xercesc::DOMNode* importDocumentElement(
- boost::process::pistream& outputStream,
- xercesc::DOMDocument* const domDocument
-) {
- std::stringstream xmlStream(
+inline std::unique_ptr<std::stringstream> readOutput(
+ boost::process::pistream& outputStream) {
+ return std::make_unique<std::stringstream>(
"<output>" + std::string(
(std::istreambuf_iterator<char>(outputStream)),
(std::istreambuf_iterator<char>())
) + "</output>"
);
+}
+inline xercesc::DOMNode* importDocumentElement(
+ std::stringstream* const outputStream,
+ xercesc::DOMDocument* const domDocument
+) {
xercesc::XercesDOMParser parser;
- parser.parse(xalan::XSLTInputSource(xmlStream));
+ parser.parse(xalan::XSLTInputSource(*outputStream));
return domDocument->importNode(
parser.getDocument()->getDocumentElement(),
@@ -66,8 +69,11 @@ DomDocumentCache::document_ptr FunctionExternalCommand::constructDocument(
inputStream.close();
}
- boost::process::pistream& outputStream = commandProcess.get_stdout();
- boost::process::status status = commandProcess.wait();
+ std::unique_ptr<std::stringstream> outputStream{
+ readOutput(commandProcess.get_stdout())
+ };
+
+ boost::process::status status = commandProcess.wait();
ResultNodeFacade result(domDocument.get(), "command");
result.setAttribute("executed", command);
@@ -77,7 +83,7 @@ DomDocumentCache::document_ptr FunctionExternalCommand::constructDocument(
try {
result.setContent(
importDocumentElement(
- outputStream,
+ outputStream.get(),
domDocument.get()
)->getChildNodes()
);