Fixes to utility / unit test related code.

* Eliminated bugs related to reading content from pipes/files, including
  general cleanup/refactoring of these code pieces and API.

* Eliminated bugs related binding/unbinding of loopback devices, which
  are used in unit testing.

BUG=chromium-os:31082
TEST=Builds and runs unit tests

CQ-DEPEND=Ib7b3552e98ca40b6141688e2dea5a1407db12b2a

Change-Id: Ifaab8697602a35ce7d7fb9384fdcb1ca64b72515
Reviewed-on: https://gerrit.chromium.org/gerrit/27911
Reviewed-by: Don Garrett <dgarrett@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
Commit-Ready: Gilad Arnold <garnold@chromium.org>
diff --git a/utils.h b/utils.h
index 67e8062..1b3095b 100644
--- a/utils.h
+++ b/utils.h
@@ -48,9 +48,18 @@
 bool PReadAll(int fd, void* buf, size_t count, off_t offset,
               ssize_t* out_bytes_read);
 
-// Returns the entire contents of the file at path. Returns true on success.
-bool ReadFile(const std::string& path, std::vector<char>* out);
-bool ReadFileToString(const std::string& path, std::string* out);
+// Opens |path| for reading and appends its entire content to the container
+// pointed to by |out_p|. Returns true upon successfully reading all of the
+// file's content, false otherwise, in which case the state of the output
+// container is unknown.
+bool ReadFile(const std::string& path, std::vector<char>* out_p);
+bool ReadFile(const std::string& path, std::string* out_p);
+
+// Invokes |cmd| in a pipe and appends its stdout to the container pointed to by
+// |out_p|. Returns true upon successfully reading all of the output, false
+// otherwise, in which case the state of the output container is unknown.
+bool ReadPipe(const std::string& cmd, std::vector<char>* out_p);
+bool ReadPipe(const std::string& cmd, std::string* out_p);
 
 // Returns the size of the file at path. If the file doesn't exist or some
 // error occurrs, -1 is returned.