diff options
author | Matthew Dempsky <mdempsky@google.com> | 2013-05-01 18:03:27 (GMT) |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2013-05-01 18:09:38 (GMT) |
commit | 65a58e37a7dd48cb336668351d1cab3db0e4d5fe (patch) | |
tree | 7c3658339ed087b0d9d078a37867b81be3dc372a /src/subprocess-posix.cc | |
parent | 4c552c2c3cbc07acce9c1a379fee054a3f680100 (diff) | |
download | Ninja-65a58e37a7dd48cb336668351d1cab3db0e4d5fe.zip Ninja-65a58e37a7dd48cb336668351d1cab3db0e4d5fe.tar.gz Ninja-65a58e37a7dd48cb336668351d1cab3db0e4d5fe.tar.bz2 |
Add support for OpenBSD.
Use ppoll() on OpenBSD. Also, fix interrupt handling to recognize
that on FreeBSD and OpenBSD, an interrupt might have been delivered
even if pselect()/ppoll() don't return -1/EINTR.
Diffstat (limited to 'src/subprocess-posix.cc')
-rw-r--r-- | src/subprocess-posix.cc | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/src/subprocess-posix.cc b/src/subprocess-posix.cc index 8f1a04e..fb6d272 100644 --- a/src/subprocess-posix.cc +++ b/src/subprocess-posix.cc @@ -49,12 +49,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(linux) - // On linux we use ppoll in DoWork(); elsewhere we use pselect and so must - // avoid overly-large FDs. +#if !defined(linux) && !defined(__OpenBSD__) + // On Linux and OpenBSD, we use ppoll in DoWork(); elsewhere we use pselect + // and so must avoid overly-large FDs. if (fd_ >= static_cast<int>(FD_SETSIZE)) Fatal("pipe: %s", strerror(EMFILE)); -#endif // !linux +#endif // !linux && !__OpenBSD__ SetCloseOnExec(fd_); pid_ = fork(); @@ -155,8 +155,6 @@ void SubprocessSet::SetInterruptedFlag(int signum) { } SubprocessSet::SubprocessSet() { - interrupted_ = false; - sigset_t set; sigemptyset(&set); sigaddset(&set, SIGINT); @@ -189,7 +187,7 @@ Subprocess *SubprocessSet::Add(const string& command) { return subprocess; } -#ifdef linux +#if defined(linux) || defined(__OpenBSD__) bool SubprocessSet::DoWork() { vector<pollfd> fds; nfds_t nfds = 0; @@ -204,15 +202,14 @@ bool SubprocessSet::DoWork() { ++nfds; } + interrupted_ = false; int ret = ppoll(&fds.front(), nfds, NULL, &old_mask_); if (ret == -1) { if (errno != EINTR) { perror("ninja: ppoll"); return false; } - bool interrupted = interrupted_; - interrupted_ = false; - return interrupted; + return interrupted_; } nfds_t cur_nfd = 0; @@ -233,10 +230,10 @@ bool SubprocessSet::DoWork() { ++i; } - return false; + return interrupted_; } -#else // linux +#else // linux || __OpenBSD__ bool SubprocessSet::DoWork() { fd_set set; int nfds = 0; @@ -252,15 +249,14 @@ bool SubprocessSet::DoWork() { } } + interrupted_ = false; int ret = pselect(nfds, &set, 0, 0, 0, &old_mask_); if (ret == -1) { if (errno != EINTR) { perror("ninja: pselect"); return false; } - bool interrupted = interrupted_; - interrupted_ = false; - return interrupted; + return interrupted_; } for (vector<Subprocess*>::iterator i = running_.begin(); @@ -277,9 +273,9 @@ bool SubprocessSet::DoWork() { ++i; } - return false; + return interrupted_; } -#endif // linux +#endif // linux || __OpenBSD__ Subprocess* SubprocessSet::NextFinished() { if (finished_.empty()) |