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

Side by Side Diff: base/memory/shared_memory_helper.cc

Issue 2969453002: Add FD exhaustion logging for Chrome OS. (Closed)
Patch Set: with setrlimit Created 3 years, 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/shared_memory_helper.h" 5 #include "base/memory/shared_memory_helper.h"
6 6
7 #if defined(OS_CHROMEOS)
8 #include <sys/resource.h>
9 #include <sys/time.h>
10 #endif // defined(OS_CHROMEOS)
11
7 #include "base/threading/thread_restrictions.h" 12 #include "base/threading/thread_restrictions.h"
8 13
9 namespace base { 14 namespace base {
10 15
11 struct ScopedPathUnlinkerTraits { 16 struct ScopedPathUnlinkerTraits {
12 static const FilePath* InvalidValue() { return nullptr; } 17 static const FilePath* InvalidValue() { return nullptr; }
13 18
14 static void Free(const FilePath* path) { 19 static void Free(const FilePath* path) {
15 if (unlink(path->value().c_str())) 20 if (unlink(path->value().c_str()))
16 PLOG(WARNING) << "unlink"; 21 PLOG(WARNING) << "unlink";
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 NOTREACHED(); 88 NOTREACHED();
84 if (st.st_dev != readonly_st.st_dev || st.st_ino != readonly_st.st_ino) { 89 if (st.st_dev != readonly_st.st_dev || st.st_ino != readonly_st.st_ino) {
85 LOG(ERROR) << "writable and read-only inodes don't match; bailing"; 90 LOG(ERROR) << "writable and read-only inodes don't match; bailing";
86 return false; 91 return false;
87 } 92 }
88 } 93 }
89 94
90 *mapped_file = HANDLE_EINTR(dup(fileno(fp.get()))); 95 *mapped_file = HANDLE_EINTR(dup(fileno(fp.get())));
91 if (*mapped_file == -1) { 96 if (*mapped_file == -1) {
92 NOTREACHED() << "Call to dup failed, errno=" << errno; 97 NOTREACHED() << "Call to dup failed, errno=" << errno;
98 #if defined(OS_CHROMEOS)
99 if (errno == EMFILE) {
100 // We're out of file descriptors and are probably about to crash somewhere
101 // else in Chrome anyway. Let's collect what FD information we can and
102 // crash.
103 // Added for debugging crbug.com/733718
104 struct rlimit rlim;
105 if (getrlimit(RLIMIT_NOFILE, &rlim) == 0) {
106 if (rlim.rlim_max > rlim.rlim_cur) {
107 // Increase fd limit so breakpad has a chance to write a minidump.
108 rlim.rlim_cur = rlim.rlim_max;
109 if (setrlimit(RLIMIT_NOFILE, &rlim) != 0) {
110 PLOG(ERROR) << "setrlimit() failed";
111 }
112 }
113 PLOG(ERROR) << "getrlimit() failed";
114
115 // Fall back to 16K if we can't call getrlimit().
116 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.
117 }
118
119 char buf[PATH_MAX];
120 char fd_path[PATH_MAX];
121 for (int i = 0; i < static_cast<int>(rlim.rlim_cur); i++) {
122 memset(buf, 0, PATH_MAX);
123 memset(fd_path, 0, PATH_MAX);
124 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.
125 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.
126 if (count >= 0) {
127 LOG(ERROR) << i << ": " << buf;
128 }
129 }
130
131 // TODO(teravest): Put fd information on the stack for breakpad.
132 CHECK(false) << "Logged for file descriptor exhaustion, crashing now";
133 }
134 #endif // defined(OS_CHROMEOS)
93 } 135 }
94 *readonly_mapped_file = readonly_fd.release(); 136 *readonly_mapped_file = readonly_fd.release();
95 137
96 return true; 138 return true;
97 } 139 }
98 #endif // !defined(OS_ANDROID) 140 #endif // !defined(OS_ANDROID)
99 141
100 } // namespace base 142 } // namespace base
OLDNEW
« 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