aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorLester Solbakken <lesters@users.noreply.github.com>2022-02-16 09:36:51 +0100
committerGitHub <noreply@github.com>2022-02-16 09:36:51 +0100
commit16088244d35a723256287553555fec62cbe93d9b (patch)
tree15a18c3509b860daa893a9e83177a4539933fac4 /vespalib
parent80bf8df285a1ecf1f5f253eeb4e49f600fcbad9a (diff)
parentfd4cde251f9c4d9b8913f2389d7a3f473b6263ac (diff)
Merge pull request #21207 from vespa-engine/havardpe/better-error-messages
better error messages
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/vespa/vespalib/util/child_process.cpp20
-rw-r--r--vespalib/src/vespa/vespalib/util/child_process.h13
2 files changed, 29 insertions, 4 deletions
diff --git a/vespalib/src/vespa/vespalib/util/child_process.cpp b/vespalib/src/vespa/vespalib/util/child_process.cpp
index 7193a445f9a..694bed60f1b 100644
--- a/vespalib/src/vespa/vespalib/util/child_process.cpp
+++ b/vespalib/src/vespa/vespalib/util/child_process.cpp
@@ -67,7 +67,9 @@ ChildProcess::Reader::OnReceiveData(const void *data, size_t length)
return;
}
if (buf == nullptr) { // EOF
- _gotEOF = true;
+ if (--_num_streams == 0) {
+ _gotEOF = true;
+ }
} else {
_queue.push(std::string(buf, length));
}
@@ -107,11 +109,12 @@ ChildProcess::Reader::updateEOF()
}
-ChildProcess::Reader::Reader()
+ChildProcess::Reader::Reader(int num_streams)
: _lock(),
_cond(),
_queue(),
_data(),
+ _num_streams(num_streams),
_gotEOF(false),
_waitCnt(0),
_readEOF(false)
@@ -203,7 +206,7 @@ ChildProcess::checkProc()
ChildProcess::ChildProcess(const char *cmd)
- : _reader(),
+ : _reader(1),
_proc(cmd, true, &_reader),
_running(false),
_failed(false),
@@ -213,6 +216,17 @@ ChildProcess::ChildProcess(const char *cmd)
_failed = !_running;
}
+ChildProcess::ChildProcess(const char *cmd, capture_stderr_tag)
+ : _reader(2),
+ _proc(cmd, true, &_reader, &_reader),
+ _running(false),
+ _failed(false),
+ _exitCode(-918273645)
+{
+ _running = _proc.CreateWithShell();
+ _failed = !_running;
+}
+
ChildProcess::~ChildProcess() = default;
diff --git a/vespalib/src/vespa/vespalib/util/child_process.h b/vespalib/src/vespa/vespalib/util/child_process.h
index 646a2c7c6c9..877c56a8cb1 100644
--- a/vespalib/src/vespa/vespalib/util/child_process.h
+++ b/vespalib/src/vespa/vespalib/util/child_process.h
@@ -28,6 +28,7 @@ private:
std::condition_variable _cond;
std::queue<std::string> _queue;
std::string _data;
+ int _num_streams;
bool _gotEOF;
int _waitCnt;
bool _readEOF;
@@ -38,7 +39,7 @@ private:
void updateEOF();
public:
- Reader();
+ Reader(int num_streams);
~Reader() override;
uint32_t read(char *buf, uint32_t len, int msTimeout);
@@ -57,6 +58,7 @@ private:
public:
ChildProcess(const ChildProcess &) = delete;
ChildProcess &operator=(const ChildProcess &) = delete;
+ struct capture_stderr_tag{};
/**
* @brief Run a child process
@@ -66,6 +68,15 @@ public:
**/
explicit ChildProcess(const char *cmd);
+ /**
+ * @brief Run a child process
+ *
+ * Starts a process running the given command. stderr is
+ * redirected into stdout.
+ * @param cmd A shell command line to run
+ **/
+ explicit ChildProcess(const char *cmd, capture_stderr_tag);
+
/** @brief destructor doing cleanup if needed */
~ChildProcess();