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

Side by Side Diff: base/shared_memory_posix.cc

Issue 125024: Handle file descriptor exhaustions a little more gracefully. This prevents th... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/renderer_host/buffered_resource_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/shared_memory.h" 5 #include "base/shared_memory.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <sys/mman.h> 9 #include <sys/mman.h>
10 #include <sys/stat.h> 10 #include <sys/stat.h>
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 } else if (current_size > size) { 218 } else if (current_size > size) {
219 // possibly shrink. 219 // possibly shrink.
220 if ((ftruncate(fileno(fp), size) != 0) || 220 if ((ftruncate(fileno(fp), size) != 0) ||
221 (fflush(fp) != 0)) { 221 (fflush(fp) != 0)) {
222 return false; 222 return false;
223 } 223 }
224 } 224 }
225 } 225 }
226 226
227 mapped_file_ = dup(fileno(fp)); 227 mapped_file_ = dup(fileno(fp));
228 DCHECK(mapped_file_ >= 0); 228 if (mapped_file_ == -1) {
229 if (errno == EMFILE) {
230 LOG(WARNING) << "Shared memory creation failed; out of file descriptors";
231 return false;
232 } else {
233 NOTREACHED() << "Call to dup failed, errno=" << errno;
234 }
235 }
229 236
230 struct stat st; 237 struct stat st;
231 if (fstat(mapped_file_, &st)) 238 if (fstat(mapped_file_, &st))
232 NOTREACHED(); 239 NOTREACHED();
233 inode_ = st.st_ino; 240 inode_ = st.st_ino;
234 241
235 return true; 242 return true;
236 } 243 }
237 244
238 bool SharedMemory::Map(size_t bytes) { 245 bool SharedMemory::Map(size_t bytes) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 316
310 void SharedMemory::Unlock() { 317 void SharedMemory::Unlock() {
311 LockOrUnlockCommon(F_ULOCK); 318 LockOrUnlockCommon(F_ULOCK);
312 } 319 }
313 320
314 SharedMemoryHandle SharedMemory::handle() const { 321 SharedMemoryHandle SharedMemory::handle() const {
315 return FileDescriptor(mapped_file_, false); 322 return FileDescriptor(mapped_file_, false);
316 } 323 }
317 324
318 } // namespace base 325 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/renderer_host/buffered_resource_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698