debugd: switch from dbus-c++ to chromeos-dbus-bindings
This allows us to remove a major user of dbus-c++, which does
not play nicely with chrome code, as it uses exceptions. It
also uses non-const references for multiple return values and
errors which is strictly disallowed. This also allows us to use
the libchrome message loop.
Most of this is a replacement of types:
* DBus::Connection -> dbus::Bus
* DBus::Error -> brillo::ErrorPtr
* DBus::FileDescriptor -> dbus::FileDescriptor
* std::map<std::string, DBus::Variant> -> brillo::VariantDictionary
as well as use of libchrome dbus objects where debugd calls out
to other D-Bus services.
CQ-DEPEND=CL:495412
BUG=chromium:705051
TEST=emerge, unit tests, autotests, deploy and use from crosh
Change-Id: I5a7d34be6eec5f88949551dde2f02110b8c90487
Reviewed-on: https://chromium-review.googlesource.com/490830
Commit-Ready: Eric Caruso <ejcaruso@chromium.org>
Tested-by: Eric Caruso <ejcaruso@chromium.org>
Reviewed-by: Eric Caruso <ejcaruso@chromium.org>
diff --git a/debugd/src/process_with_output.cc b/debugd/src/process_with_output.cc
index fb5453f..f9b3c29 100644
--- a/debugd/src/process_with_output.cc
+++ b/debugd/src/process_with_output.cc
@@ -9,6 +9,8 @@
#include <base/files/file_util.h>
#include <base/strings/string_split.h>
+#include "debugd/src/error_utils.h"
+
namespace debugd {
namespace {
@@ -19,13 +21,6 @@
const char kInputErrorString[] = "Process input write failure.";
const char kPathLengthErrorString[] = "Path length is too long.";
-// Sets the D-Bus error if it's non-NULL.
-void SetError(const char* message, DBus::Error* error) {
- if (error) {
- error->set(kDBusErrorString, message);
- }
-}
-
} // namespace
ProcessWithOutput::ProcessWithOutput()
@@ -95,7 +90,7 @@
const std::string* stdin,
std::string* stdout,
std::string* stderr,
- DBus::Error* error) {
+ brillo::ErrorPtr* error) {
ProcessWithOutput process;
if (requires_root) {
process.SandboxAs("root", "root");
@@ -110,10 +105,10 @@
const std::string* stdin,
std::string* stdout,
std::string* stderr,
- DBus::Error* error) {
+ brillo::ErrorPtr* error) {
std::string helper_path;
if (!SandboxedProcess::GetHelperPath(helper, &helper_path)) {
- SetError(kPathLengthErrorString, error);
+ DEBUGD_ADD_ERROR(error, kDBusErrorString, kPathLengthErrorString);
return kRunError;
}
return RunProcess(
@@ -137,11 +132,11 @@
const std::string* stdin,
std::string* stdout,
std::string* stderr,
- DBus::Error* error,
+ brillo::ErrorPtr* error,
ProcessWithOutput* process) {
process->set_separate_stderr(true);
if (!process->Init()) {
- SetError(kInitErrorString, error);
+ DEBUGD_ADD_ERROR(error, kDBusErrorString, kInitErrorString);
return kRunError;
}
@@ -160,22 +155,22 @@
stdin->length()) ||
IGNORE_EINTR(close(stdin_fd)) < 0) {
process->Kill(SIGKILL, 0);
- SetError(kInputErrorString, error);
+ DEBUGD_ADD_ERROR(error, kDBusErrorString, kInputErrorString);
}
result = process->Wait();
} else {
- SetError(kStartErrorString, error);
+ DEBUGD_ADD_ERROR(error, kDBusErrorString, kStartErrorString);
}
} else {
result = process->Run();
}
- if (stdout) {
+ if (stdout)
process->GetOutput(stdout);
- }
- if (stderr) {
+
+ if (stderr)
process->GetError(stderr);
- }
+
return result;
}