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

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

Issue 2969453002: Add FD exhaustion logging for Chrome OS. (Closed)
Patch Set: fix for derat 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
11 #include "base/debug/alias.h"
12 #endif // defined(OS_CHROMEOS)
13
7 #include "base/threading/thread_restrictions.h" 14 #include "base/threading/thread_restrictions.h"
8 15
9 namespace base { 16 namespace base {
10 17
11 struct ScopedPathUnlinkerTraits { 18 struct ScopedPathUnlinkerTraits {
12 static const FilePath* InvalidValue() { return nullptr; } 19 static const FilePath* InvalidValue() { return nullptr; }
13 20
14 static void Free(const FilePath* path) { 21 static void Free(const FilePath* path) {
15 if (unlink(path->value().c_str())) 22 if (unlink(path->value().c_str()))
16 PLOG(WARNING) << "unlink"; 23 PLOG(WARNING) << "unlink";
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 NOTREACHED(); 90 NOTREACHED();
84 if (st.st_dev != readonly_st.st_dev || st.st_ino != readonly_st.st_ino) { 91 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"; 92 LOG(ERROR) << "writable and read-only inodes don't match; bailing";
86 return false; 93 return false;
87 } 94 }
88 } 95 }
89 96
90 *mapped_file = HANDLE_EINTR(dup(fileno(fp.get()))); 97 *mapped_file = HANDLE_EINTR(dup(fileno(fp.get())));
91 if (*mapped_file == -1) { 98 if (*mapped_file == -1) {
92 NOTREACHED() << "Call to dup failed, errno=" << errno; 99 NOTREACHED() << "Call to dup failed, errno=" << errno;
100
101 #if defined(OS_CHROMEOS)
102 if (errno == EMFILE) {
103 // We're out of file descriptors and are probably about to crash somewhere
104 // else in Chrome anyway. Let's collect what FD information we can and
105 // crash.
106 // Added for debugging crbug.com/733718
107 int original_fd_limit = 16384;
108 struct rlimit rlim;
109 if (getrlimit(RLIMIT_NOFILE, &rlim) == 0) {
110 original_fd_limit = rlim.rlim_cur;
111 if (rlim.rlim_max > rlim.rlim_cur) {
112 // Increase fd limit so breakpad has a chance to write a minidump.
113 rlim.rlim_cur = rlim.rlim_max;
114 if (setrlimit(RLIMIT_NOFILE, &rlim) != 0) {
115 PLOG(ERROR) << "setrlimit() failed";
116 }
117 }
118 } else {
119 PLOG(ERROR) << "getrlimit() failed";
120 }
121
122 const char kFileDataMarker[] = "FDATA";
123 char buf[PATH_MAX];
124 char fd_path[PATH_MAX];
125 char crash_buffer[32 * 1024] = {0};
126 char* crash_ptr = crash_buffer;
127 base::debug::Alias(crash_buffer);
128
129 // Put a marker at the start of our data so we can confirm where it
130 // begins.
131 crash_ptr = strncpy(crash_ptr, kFileDataMarker, strlen(kFileDataMarker));
132 for (int i = original_fd_limit; i >= 0; --i) {
133 memset(buf, 0, arraysize(buf));
134 memset(fd_path, 0, arraysize(fd_path));
135 snprintf(fd_path, arraysize(fd_path) - 1, "/proc/self/fd/%d", i);
136 ssize_t count = readlink(fd_path, buf, arraysize(buf) - 1);
137 if (count < 0) {
138 PLOG(ERROR) << "readlink failed for: " << fd_path;
139 continue;
140 }
141
142 if (crash_ptr + count + 1 < crash_buffer + arraysize(crash_buffer)) {
143 crash_ptr = strncpy(crash_ptr, buf, count + 1);
144 }
145 LOG(ERROR) << i << ": " << buf;
146 }
147 LOG(FATAL) << "Logged for file descriptor exhaustion, crashing now";
148 }
149 #endif // defined(OS_CHROMEOS)
93 } 150 }
94 *readonly_mapped_file = readonly_fd.release(); 151 *readonly_mapped_file = readonly_fd.release();
95 152
96 return true; 153 return true;
97 } 154 }
98 #endif // !defined(OS_ANDROID) 155 #endif // !defined(OS_ANDROID)
99 156
100 } // namespace base 157 } // 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