diff options
author | Ami Fischman <fischman@chromium.org> | 2012-03-04 03:58:09 (GMT) |
---|---|---|
committer | Ami Fischman <fischman@chromium.org> | 2012-03-04 03:58:09 (GMT) |
commit | f6887638b7327f45ff8fa8a29420c48c059182c4 (patch) | |
tree | 4513041bf3dfc7cfc94840d690f65d8bb9b3f480 /src | |
parent | cd2e3c9115bd2df3db0d11cfc38ab82a17fcac06 (diff) | |
download | Ninja-f6887638b7327f45ff8fa8a29420c48c059182c4.zip Ninja-f6887638b7327f45ff8fa8a29420c48c059182c4.tar.gz Ninja-f6887638b7327f45ff8fa8a29420c48c059182c4.tar.bz2 |
addressed pcc comments
Diffstat (limited to 'src')
-rw-r--r-- | src/subprocess.cc | 19 | ||||
-rw-r--r-- | src/subprocess_test.cc | 12 |
2 files changed, 19 insertions, 12 deletions
diff --git a/src/subprocess.cc b/src/subprocess.cc index 3de574b..99de93f 100644 --- a/src/subprocess.cc +++ b/src/subprocess.cc @@ -42,12 +42,12 @@ bool Subprocess::Start(SubprocessSet* set, const string& command) { if (pipe(output_pipe) < 0) Fatal("pipe: %s", strerror(errno)); fd_ = output_pipe[0]; -#if !defined(OS_LINUX) +#if !defined(linux) // On linux we use ppoll in DoWork(); elsewhere we use pselect and so must // avoid overly-large FDs. if (fd_ >= FD_SETSIZE) Fatal("pipe: %s", strerror(EMFILE)); -#endif // !OS_LINUX +#endif // !linux SetCloseOnExec(fd_); pid_ = fork(); @@ -182,10 +182,9 @@ Subprocess *SubprocessSet::Add(const string &command) { return subprocess; } -#ifdef OS_LINUX +#ifdef linux bool SubprocessSet::DoWork() { - struct pollfd* fds = new pollfd[running_.size()](); // XXX: scoped_array? - memset(fds, 0, running_.size() * sizeof(struct pollfd)); + vector<pollfd> fds; nfds_t nfds = 0; for (vector<Subprocess*>::iterator i = running_.begin(); @@ -193,12 +192,12 @@ bool SubprocessSet::DoWork() { int fd = (*i)->fd_; if (fd < 0) continue; - fds[nfds].fd = fd; - fds[nfds].events = POLLIN | POLLPRI | POLLRDHUP; + pollfd pfd = { fd, POLLIN | POLLPRI | POLLRDHUP, 0 }; + fds.push_back(pfd); ++nfds; } - int ret = ppoll(fds, nfds, NULL, &old_mask_); + int ret = ppoll(&fds.front(), nfds, NULL, &old_mask_); if (ret == -1) { if (errno != EINTR) { perror("ninja: ppoll"); @@ -230,7 +229,7 @@ bool SubprocessSet::DoWork() { return false; } -#else // OS_LINUX +#else // linux bool SubprocessSet::DoWork() { fd_set set; int nfds = 0; @@ -273,7 +272,7 @@ bool SubprocessSet::DoWork() { return false; } -#endif // OS_LINUX +#endif // linux Subprocess* SubprocessSet::NextFinished() { if (finished_.empty()) diff --git a/src/subprocess_test.cc b/src/subprocess_test.cc index d7ecb33..c155012 100644 --- a/src/subprocess_test.cc +++ b/src/subprocess_test.cc @@ -142,11 +142,19 @@ TEST_F(SubprocessTest, SetWithMulti) { } } -#ifdef OS_LINUX +#ifdef linux TEST_F(SubprocessTest, SetWithLots) { // Arbitrary big number; needs to be over 1024 to confirm we're no longer // hostage to pselect. const size_t kNumProcs = 1025; + + // Make sure [ulimit -n] isn't going to stop us from working. + rlimit rlim; + ASSERT_EQ(0, getrlimit(RLIMIT_NOFILE, &rlim)); + ASSERT_GT(rlim.rlim_cur, kNumProcs) + << "Raise [ulimit -n] well above " << kNumProcs + << " to make this test go"; + vector<Subprocess*> procs; for (size_t i = 0; i < kNumProcs; ++i) { Subprocess* subproc = subprocs_.Add("/bin/echo"); @@ -161,4 +169,4 @@ TEST_F(SubprocessTest, SetWithLots) { } ASSERT_EQ(kNumProcs, subprocs_.finished_.size()); } -#endif +#endif // linux |