AU: Add support for reading the output of synchronous exec calls.

This will be used in a subsequent patch to invoke 'crossystem hwid' to read the
HWID.

BUG=chromium-os:15255
TEST=unit tests, tested AU on device

Change-Id: Ie26bae3621626d40f92f08e8549eefda77151102
Reviewed-on: http://gerrit.chromium.org/gerrit/1047
Reviewed-by: Thieu Le <thieule@chromium.org>
Tested-by: Darin Petkov <petkov@chromium.org>
diff --git a/subprocess.cc b/subprocess.cc
index 34f5994..a638145 100644
--- a/subprocess.cc
+++ b/subprocess.cc
@@ -117,7 +117,7 @@
 };
 }  // namespace {}
 
-uint32_t Subprocess::Exec(const std::vector<std::string>& cmd,
+uint32_t Subprocess::Exec(const vector<string>& cmd,
                           ExecCallback callback,
                           void* p) {
   GPid child_pid;
@@ -181,9 +181,13 @@
   subprocess_records_[tag]->callback = NULL;
 }
 
-bool Subprocess::SynchronousExecFlags(const std::vector<std::string>& cmd,
+bool Subprocess::SynchronousExecFlags(const vector<string>& cmd,
+                                      GSpawnFlags flags,
                                       int* return_code,
-                                      GSpawnFlags flags) {
+                                      string* stdout) {
+  if (stdout) {
+    *stdout = "";
+  }
   GError* err = NULL;
   scoped_array<char*> argv(new char*[cmd.size() + 1]);
   for (unsigned int i = 0; i < cmd.size(); i++) {
@@ -221,7 +225,9 @@
     g_error_free(err);
   }
   if (child_stdout) {
-    if (strlen(child_stdout)) {
+    if (stdout) {
+      *stdout = child_stdout;
+    } else if (*child_stdout) {
       LOG(INFO) << "Subprocess output:\n" << child_stdout;
     }
     g_free(child_stdout);
@@ -229,6 +235,15 @@
   return success;
 }
 
+bool Subprocess::SynchronousExec(const std::vector<std::string>& cmd,
+                                 int* return_code,
+                                 std::string* stdout) {
+  return SynchronousExecFlags(cmd,
+                              static_cast<GSpawnFlags>(0),
+                              return_code,
+                              stdout);
+}
+
 bool Subprocess::SubprocessInFlight() {
   for (std::map<int, shared_ptr<SubprocessRecord> >::iterator it =
            subprocess_records_.begin();