Linux: Use poll instead of select to fix crash during startup (issue #2466)

This commit is contained in:
Marshall Greenblatt 2018-06-26 15:22:51 -04:00
parent 35830c88e5
commit b03c54bfbe
2 changed files with 53 additions and 0 deletions

View File

@ -373,4 +373,9 @@ patches = [
# https://bitbucket.org/chromiumembedded/cef/issues/2456
'name': 'content_runprocess_2456',
},
{
# Linux: Use poll instead of select to fix crash during startup.
# https://bitbucket.org/chromiumembedded/cef/issues/2466
'name': 'linux_poll_2466',
},
]

View File

@ -0,0 +1,48 @@
diff --git base/files/file_path_watcher_linux.cc base/files/file_path_watcher_linux.cc
index c58d6865c27b..6ab39432259d 100644
--- base/files/file_path_watcher_linux.cc
+++ base/files/file_path_watcher_linux.cc
@@ -5,6 +5,7 @@
#include "base/files/file_path_watcher.h"
#include <errno.h>
+#include <poll.h>
#include <stddef.h>
#include <string.h>
#include <sys/inotify.h>
@@ -13,6 +14,7 @@
#include <unistd.h>
#include <algorithm>
+#include <array>
#include <map>
#include <memory>
#include <set>
@@ -221,20 +223,15 @@ LazyInstance<InotifyReader>::Leaky g_inotify_reader = LAZY_INSTANCE_INITIALIZER;
void InotifyReaderThreadDelegate::ThreadMain() {
PlatformThread::SetName("inotify_reader");
- // Make sure the file descriptors are good for use with select().
- CHECK_LE(0, inotify_fd_);
- CHECK_GT(FD_SETSIZE, inotify_fd_);
+ std::array<pollfd, 1> fdarray
+ { {
+ { inotify_fd_, POLLIN, 0 }
+ } };
while (true) {
- fd_set rfds;
- FD_ZERO(&rfds);
- FD_SET(inotify_fd_, &rfds);
-
- // Wait until some inotify events are available.
- int select_result =
- HANDLE_EINTR(select(inotify_fd_ + 1, &rfds, nullptr, nullptr, nullptr));
- if (select_result < 0) {
- DPLOG(WARNING) << "select failed";
+ int poll_result = HANDLE_EINTR(poll(fdarray.data(), fdarray.size(), -1));
+ if (poll_result < 0) {
+ DPLOG(WARNING) << "poll failed";
return;
}