diff options
author | 2018-03-16 15:07:20 -0700 | |
---|---|---|
committer | 2018-03-18 09:02:43 -0700 | |
commit | 68b39240e53f77dd59f69a7443d0ac1c83bce2c9 (patch) | |
tree | 972744d3991a4cae9611f36b932ad114cc6ec08e | |
parent | 152e3179d603465c2235e2089af6934aa29f31ba (diff) |
Always prefer poll over select.
Even with the fd leak fixed, we were still calling this code with fds
greater than 1024. From a tombstone from a dumpstate crash:
open files:
fd 0: /dev/pts/0
...
fd 18: /dev/stune/rt/tasks
fd 1806: /data/anr/anr_2018-03-15-15-39-43-990
fd 1807: /data/anr/anr_2018-03-15-15-39-43-991
fd 1808: /data/anr/anr_2018-03-15-15-39-43-992
fd 1809: /data/anr/anr_2018-03-15-15-39-43-993
fd 1810: /data/anr/anr_2018-03-15-15-39-43-994
fd 1811: /data/anr/anr_2018-03-15-15-39-43-995
fd 1812: /data/anr/anr_2018-03-15-15-39-43-996
fd 1813: /data/anr/anr_2018-03-15-15-39-43-997
fd 1814: /data/anr/anr_2018-03-15-15-39-43-998
fd 1815: /data/anr/anr_2018-03-15-15-39-43-999
Bug: http://b/73140330
Test: filled /data/anr/ with 2000 fake anrs, ran `dumpstate`
(cherry picked from commit ec616bc96e742d9f526d5594d077f8bff0ded835)
Change-Id: Id3265e86fd987853e59261ae5f8e3bd03d618374
-rw-r--r-- | cmds/dumpstate/DumpstateInternal.cpp | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/cmds/dumpstate/DumpstateInternal.cpp b/cmds/dumpstate/DumpstateInternal.cpp index 819d5b91f5..33e35f7274 100644 --- a/cmds/dumpstate/DumpstateInternal.cpp +++ b/cmds/dumpstate/DumpstateInternal.cpp @@ -20,6 +20,7 @@ #include <errno.h> #include <grp.h> +#include <poll.h> #include <pwd.h> #include <stdint.h> #include <stdio.h> @@ -35,6 +36,7 @@ #include <vector> #include <android-base/file.h> +#include <android-base/macros.h> #include <log/log.h> uint64_t Nanotime() { @@ -154,22 +156,16 @@ int DumpFileFromFdToFd(const std::string& title, const std::string& path_string, return 0; } bool newline = false; - fd_set read_set; - timeval tm; while (true) { - FD_ZERO(&read_set); - FD_SET(fd, &read_set); - /* Timeout if no data is read for 30 seconds. */ - tm.tv_sec = 30; - tm.tv_usec = 0; - uint64_t elapsed = Nanotime(); - int ret = TEMP_FAILURE_RETRY(select(fd + 1, &read_set, nullptr, nullptr, &tm)); + uint64_t start_time = Nanotime(); + pollfd fds[] = { { .fd = fd, .events = POLLIN } }; + int ret = TEMP_FAILURE_RETRY(poll(fds, arraysize(fds), 30 * 1000)); if (ret == -1) { - dprintf(out_fd, "*** %s: select failed: %s\n", path, strerror(errno)); + dprintf(out_fd, "*** %s: poll failed: %s\n", path, strerror(errno)); newline = true; break; } else if (ret == 0) { - elapsed = Nanotime() - elapsed; + uint64_t elapsed = Nanotime() - start_time; dprintf(out_fd, "*** %s: Timed out after %.3fs\n", path, (float)elapsed / NANOS_PER_SEC); newline = true; break; |