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(); KillSandboxee();
break; break;
} }
constexpr int64_t kMinWakeupMsec = 10000; constexpr int64_t kMinWakeupMsec = 30000;
int timeout_msec = static_cast<int>( int timeout_msec = kMinWakeupMsec;
std::min(kMinWakeupMsec, if (remaining > absl::ZeroDuration()) {
std::max(int64_t{0}, absl::ToInt64Milliseconds(remaining)))); timeout_msec = static_cast<int>(
PCHECK(poll(pfds, ABSL_ARRAYSIZE(pfds), timeout_msec) != -1); 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) { if (pfds[2].revents & POLLIN) {
char c = ' '; char c = ' ';
read(monitor_notify_pipe_[0].get(), &c, 1); read(monitor_notify_pipe_[0].get(), &c, 1);