use Fatal() more
authorEvan Martin <martine@danga.com>
Tue, 30 Nov 2010 18:41:35 +0000 (10:41 -0800)
committerEvan Martin <martine@danga.com>
Tue, 30 Nov 2010 18:41:39 +0000 (10:41 -0800)
build.cc
subprocess.cc
subprocess.h
subprocess_test.cc

index fb6715e..90523ae 100644 (file)
--- a/build.cc
+++ b/build.cc
@@ -101,12 +101,11 @@ bool RealCommandRunner::CanRunMore() {
 }
 
 bool RealCommandRunner::StartCommand(Edge* edge) {
-  string err;
   string command = edge->EvaluateCommand();
   printf("  %s\n", command.c_str());
   Subprocess* subproc = new Subprocess;
   subproc_to_edge_.insert(make_pair(subproc, edge));
-  if (!subproc->Start(command, &err))
+  if (!subproc->Start(command))
     return false;
 
   subprocs_.Add(subproc);
index ece09e8..c08c314 100644 (file)
@@ -22,26 +22,22 @@ Subprocess::Subprocess() : pid_(-1) {}
 Subprocess::~Subprocess() {
 }
 
-bool Subprocess::Start(const string& command, string* err) {
+bool Subprocess::Start(const string& command) {
   int stdout_pipe[2];
-  if (pipe(stdout_pipe) < 0) {
-    *err = strerror(errno);
-    return false;
-  }
+  if (pipe(stdout_pipe) < 0)
+    Fatal("pipe: %s", strerror(errno));
   stdout_.fd_ = stdout_pipe[0];
 
   int stderr_pipe[2];
-  if (pipe(stderr_pipe) < 0) {
-    *err = strerror(errno);
-    return false;
-  }
+  if (pipe(stderr_pipe) < 0)
+    Fatal("pipe: %s", strerror(errno));
   stderr_.fd_ = stderr_pipe[0];
 
   pid_ = fork();
-  if (pid_ < 0) {
-    *err = strerror(errno);
-    return false;
-  } else if (pid_ == 0) {
+  if (pid_ < 0)
+    Fatal("fork: %s", strerror(errno));
+
+  if (pid_ == 0) {
     if (close(0) < 0 ||
         dup2(stdout_pipe[1], 1) < 0 ||
         dup2(stderr_pipe[1], 2) < 0 ||
index a65b729..a2ea66e 100644 (file)
@@ -10,7 +10,7 @@ using namespace std;
 struct Subprocess {
   Subprocess();
   ~Subprocess();
-  bool Start(const string& command, string* err);
+  bool Start(const string& command);
   void OnFDReady(int fd);
   bool Finish(string* err);
 
index b51bbe7..2ad99c9 100644 (file)
@@ -4,13 +4,12 @@
 
 TEST(Subprocess, Ls) {
   Subprocess ls;
-  string err;
-  EXPECT_TRUE(ls.Start("ls /", &err));
-  ASSERT_EQ("", err);
+  EXPECT_TRUE(ls.Start("ls /"));
 
   // Pretend we discovered that stdout was ready for writing.
   ls.OnFDReady(ls.stdout_.fd_);
 
+  string err;
   EXPECT_TRUE(ls.Finish(&err));
   ASSERT_EQ("", err);
   EXPECT_NE("", ls.stdout_.buf_);
@@ -19,13 +18,12 @@ TEST(Subprocess, Ls) {
 
 TEST(Subprocess, BadCommand) {
   Subprocess subproc;
-  string err;
-  EXPECT_TRUE(subproc.Start("ninja_no_such_command", &err));
-  ASSERT_EQ("", err);
+  EXPECT_TRUE(subproc.Start("ninja_no_such_command"));
 
   // Pretend we discovered that stderr was ready for writing.
   subproc.OnFDReady(subproc.stderr_.fd_);
 
+  string err;
   EXPECT_FALSE(subproc.Finish(&err));
   EXPECT_NE("", err);
   EXPECT_EQ("", subproc.stdout_.buf_);
@@ -35,11 +33,10 @@ TEST(Subprocess, BadCommand) {
 TEST(SubprocessSet, Single) {
   SubprocessSet subprocs;
   Subprocess* ls = new Subprocess;
-  string err;
-  EXPECT_TRUE(ls->Start("ls /", &err));
-  ASSERT_EQ("", err);
+  EXPECT_TRUE(ls->Start("ls /"));
   subprocs.Add(ls);
 
+  string err;
   while (!ls->done()) {
     subprocs.DoWork(&err);
     ASSERT_EQ("", err);
@@ -58,11 +55,9 @@ TEST(SubprocessSet, Multi) {
     "pwd",
   };
 
-  string err;
   for (int i = 0; i < 3; ++i) {
     processes[i] = new Subprocess;
-    EXPECT_TRUE(processes[i]->Start(kCommands[i], &err));
-    ASSERT_EQ("", err);
+    EXPECT_TRUE(processes[i]->Start(kCommands[i]));
     subprocs.Add(processes[i]);
   }
 
@@ -73,6 +68,7 @@ TEST(SubprocessSet, Multi) {
     ASSERT_EQ("", processes[i]->stderr_.buf_);
   }
 
+  string err;
   while (!processes[0]->done() || !processes[1]->done() ||
          !processes[2]->done()) {
     ASSERT_GT(subprocs.running_.size(), 0);