Fix poll in unotify monitor

Fixes incorrect timeout calculation and increases the wakeup interval.
Also makes poll behave correctly in presence of signals.

PiperOrigin-RevId: 516514260
Change-Id: I035701e1bb351f9ad26157b59b13b4f300cc229a
This commit is contained in:
Wiktor Garbacz 2023-03-14 07:03:40 -07:00 committed by Copybara-Service
parent cb63dfead5
commit 5a2bdd436d

View File

@ -171,11 +171,17 @@ void UnotifyMonitor::Run() {
KillSandboxee();
break;
}
constexpr int64_t kMinWakeupMsec = 10000;
int timeout_msec = static_cast<int>(
std::min(kMinWakeupMsec,
std::max(int64_t{0}, absl::ToInt64Milliseconds(remaining))));
PCHECK(poll(pfds, ABSL_ARRAYSIZE(pfds), timeout_msec) != -1);
constexpr int64_t kMinWakeupMsec = 30000;
int timeout_msec = kMinWakeupMsec;
if (remaining > absl::ZeroDuration()) {
timeout_msec = static_cast<int>(
std::min(kMinWakeupMsec, absl::ToInt64Milliseconds(remaining)));
}
int ret = poll(pfds, ABSL_ARRAYSIZE(pfds), timeout_msec);
if (ret == 0 || (ret == -1 && errno == EINTR)) {
continue;
}
PCHECK(ret != -1);
if (pfds[2].revents & POLLIN) {
char c = ' ';
read(monitor_notify_pipe_[0].get(), &c, 1);