Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3037)

Unified Diff: base/memory/shared_memory_helper.cc

Issue 2969453002: Add FD exhaustion logging for Chrome OS. (Closed)
Patch Set: with setrlimit Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/shared_memory_helper.cc
diff --git a/base/memory/shared_memory_helper.cc b/base/memory/shared_memory_helper.cc
index e80083cf78d4e26550c6c9ff99b48f12e8087d1b..75fa97cfef5fb9fcb270b1b06c24696faa27739c 100644
--- a/base/memory/shared_memory_helper.cc
+++ b/base/memory/shared_memory_helper.cc
@@ -4,6 +4,11 @@
#include "base/memory/shared_memory_helper.h"
+#if defined(OS_CHROMEOS)
+#include <sys/resource.h>
+#include <sys/time.h>
+#endif // defined(OS_CHROMEOS)
+
#include "base/threading/thread_restrictions.h"
namespace base {
@@ -90,6 +95,43 @@ bool PrepareMapFile(ScopedFILE fp,
*mapped_file = HANDLE_EINTR(dup(fileno(fp.get())));
if (*mapped_file == -1) {
NOTREACHED() << "Call to dup failed, errno=" << errno;
+#if defined(OS_CHROMEOS)
+ if (errno == EMFILE) {
+ // We're out of file descriptors and are probably about to crash somewhere
+ // else in Chrome anyway. Let's collect what FD information we can and
+ // crash.
+ // Added for debugging crbug.com/733718
+ struct rlimit rlim;
+ if (getrlimit(RLIMIT_NOFILE, &rlim) == 0) {
+ if (rlim.rlim_max > rlim.rlim_cur) {
+ // Increase fd limit so breakpad has a chance to write a minidump.
+ rlim.rlim_cur = rlim.rlim_max;
+ if (setrlimit(RLIMIT_NOFILE, &rlim) != 0) {
+ PLOG(ERROR) << "setrlimit() failed";
+ }
+ }
+ PLOG(ERROR) << "getrlimit() failed";
+
+ // Fall back to 16K if we can't call getrlimit().
+ rlim.rlim_cur = 16384;
Daniel Erat 2017/06/29 19:26:04 i think you meant for this (and the PLOG(ERROR) ab
teravest 2017/06/29 19:50:25 Yep. Fixed, thanks.
+ }
+
+ char buf[PATH_MAX];
+ char fd_path[PATH_MAX];
+ for (int i = 0; i < static_cast<int>(rlim.rlim_cur); i++) {
+ memset(buf, 0, PATH_MAX);
+ memset(fd_path, 0, PATH_MAX);
+ sprintf(fd_path, "/proc/self/fd/%d", i);
Daniel Erat 2017/06/29 19:26:03 snprintf
teravest 2017/06/29 19:50:25 Done.
+ ssize_t count = readlink(fd_path, buf, PATH_MAX);
Daniel Erat 2017/06/29 19:26:03 arraysize(buf)-1 instead of PATH_MAX here, i think
teravest 2017/06/29 19:50:25 Done.
+ if (count >= 0) {
+ LOG(ERROR) << i << ": " << buf;
+ }
+ }
+
+ // TODO(teravest): Put fd information on the stack for breakpad.
+ CHECK(false) << "Logged for file descriptor exhaustion, crashing now";
+ }
+#endif // defined(OS_CHROMEOS)
}
*readonly_mapped_file = readonly_fd.release();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698