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

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

Issue 2969453002: Add FD exhaustion logging for Chrome OS. (Closed)
Patch Set: add stack data for breakpad 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 #if defined(OS_CHROMEOS)
101 if (errno == EMFILE) {
102 // We're out of file descriptors and are probably about to crash somewhere
103 // else in Chrome anyway. Let's collect what FD information we can and
104 // crash.
105 // Added for debugging crbug.com/733718
106 struct rlimit rlim;
107 if (getrlimit(RLIMIT_NOFILE, &rlim) == 0) {
108 if (rlim.rlim_max > rlim.rlim_cur) {
109 // Increase fd limit so breakpad has a chance to write a minidump.
110 rlim.rlim_cur = rlim.rlim_max;
111 if (setrlimit(RLIMIT_NOFILE, &rlim) != 0) {
112 PLOG(ERROR) << "setrlimit() failed";
113 }
114 }
115 } else {
116 PLOG(ERROR) << "getrlimit() failed";
117 // Fall back to 16K if we can't call getrlimit().
118 rlim.rlim_cur = 16384;
119 }
120
121 static const char* kFileDataMarker = "FDATA";
Lei Zhang 2017/06/29 22:06:29 Can this be trully const as const char kFileDataMa
teravest 2017/06/29 22:17:44 Done.
122 char buf[PATH_MAX];
Lei Zhang 2017/06/29 22:06:29 Declare |buf| and |fd_path| closer to where they a
teravest 2017/06/29 22:17:44 This is gross, but I want crash_buffer to be as cl
123 char fd_path[PATH_MAX];
124 char crash_buffer[2 * 1024 * 1024]; // 2M
125 char *crash_ptr = crash_buffer;
126 memset(crash_buffer, 0, arraysize(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 = 0; i < static_cast<int>(rlim.rlim_cur); i++) {
133 memset(buf, 0, arraysize(buf));
134 memset(fd_path, 0, arraysize(fd_path));
135 sprintf(fd_path, "/proc/self/fd/%d", i, arraysize(fd_path) - 1);
Lei Zhang 2017/06/29 22:06:29 Did you mean to use snprintf() here? I only see "%
teravest 2017/06/29 22:17:44 Fixed.
136 ssize_t count = readlink(fd_path, buf, arraysize(buf) - 1);
Lei Zhang 2017/06/29 22:06:28 Do you care if readlink() fails and returns -1?
teravest 2017/06/29 22:17:44 Hmm. Probably not, but I'll add a log anyway.
137
138 if (crash_ptr + count + 1 < crash_buffer + arraysize(crash_buffer)) {
139 crash_ptr = strncpy(crash_ptr, buf, count + 1);
140 }
141
142 if (count >= 0) {
143 LOG(ERROR) << i << ": " << buf;
144 }
145 }
146 CHECK(false) << "Logged for file descriptor exhaustion, crashing now";
Lei Zhang 2017/06/29 22:06:29 super nitty: I like LOG(FATAL) better when it's ac
teravest 2017/06/29 22:17:44 Done.
147 }
148 #endif // defined(OS_CHROMEOS)
93 } 149 }
94 *readonly_mapped_file = readonly_fd.release(); 150 *readonly_mapped_file = readonly_fd.release();
95 151
96 return true; 152 return true;
97 } 153 }
98 #endif // !defined(OS_ANDROID) 154 #endif // !defined(OS_ANDROID)
99 155
100 } // namespace base 156 } // 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