From 690b31a038af9b7318a9420689269b45f9edeb5c Mon Sep 17 00:00:00 2001 From: Wiktor Garbacz Date: Tue, 14 Mar 2023 09:18:47 -0700 Subject: [PATCH] Fix the poll in wait_for_sandboxee branch PiperOrigin-RevId: 516544270 Change-Id: Ibb10611b9b7713ac6513199b6213c15d22772ea5 --- sandboxed_api/sandbox2/monitor_unotify.cc | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/sandboxed_api/sandbox2/monitor_unotify.cc b/sandboxed_api/sandbox2/monitor_unotify.cc index 80a39d3..3d0aefc 100644 --- a/sandboxed_api/sandbox2/monitor_unotify.cc +++ b/sandboxed_api/sandbox2/monitor_unotify.cc @@ -203,9 +203,21 @@ void UnotifyMonitor::Run() { } } if (wait_for_sandboxee) { - int timeout_ms = 1000; // 1 sec - PCHECK(poll(pfds, 1, timeout_ms) != -1); - if (pfds[0].revents & POLLIN) { + absl::Time deadline = absl::Now() + absl::Seconds(1); + int ret = 0; + do { + absl::Duration remaining = deadline - absl::Now(); + if (remaining <= absl::ZeroDuration()) { + ret = 0; + break; + } + ret = + poll(pfds, 1, static_cast(absl::ToInt64Milliseconds(remaining))); + } while (ret == -1 && errno == EINTR); + PCHECK(ret != -1); + if (ret == 0) { + LOG(WARNING) << "Waiting for sandboxee exit timed out"; + } else if (pfds[0].revents & POLLIN) { SetExitStatusFromStatusPipe(); } else if (pfds[0].revents & POLLHUP) { SetExitStatusCode(Result::INTERNAL_ERROR, Result::FAILED_MONITOR);