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

Side by Side Diff: base/shared_memory_posix.cc

Issue 347012: Add a CHECK() around the SharedMemory ftruncate() call to finger it as a cras... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 1 month 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 | 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 (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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 file_closer.reset(fp); // close when we go out of scope 196 file_closer.reset(fp); // close when we go out of scope
197 197
198 // Make sure the (new) file is the right size. 198 // Make sure the (new) file is the right size.
199 if (size && (posix_flags & (O_RDWR | O_CREAT))) { 199 if (size && (posix_flags & (O_RDWR | O_CREAT))) {
200 // Get current size. 200 // Get current size.
201 struct stat stat; 201 struct stat stat;
202 if (fstat(fileno(fp), &stat) != 0) 202 if (fstat(fileno(fp), &stat) != 0)
203 return false; 203 return false;
204 const size_t current_size = stat.st_size; 204 const size_t current_size = stat.st_size;
205 if (current_size != size) { 205 if (current_size != size) {
206 if (ftruncate(fileno(fp), size) != 0) 206 // TODO(hawk): When finished with bug 16371, revert this CHECK() to:
207 return false; 207 // if (ftruncate(fileno(fp), size) != 0)
208 // return false;
209 CHECK(!ftruncate(fileno(fp), size));
208 if (fseeko(fp, size, SEEK_SET) != 0) 210 if (fseeko(fp, size, SEEK_SET) != 0)
209 return false; 211 return false;
210 } 212 }
211 } 213 }
212 214
213 mapped_file_ = dup(fileno(fp)); 215 mapped_file_ = dup(fileno(fp));
214 if (mapped_file_ == -1) { 216 if (mapped_file_ == -1) {
215 if (errno == EMFILE) { 217 if (errno == EMFILE) {
216 LOG(WARNING) << "Shared memory creation failed; out of file descriptors"; 218 LOG(WARNING) << "Shared memory creation failed; out of file descriptors";
217 return false; 219 return false;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 304
303 void SharedMemory::Unlock() { 305 void SharedMemory::Unlock() {
304 LockOrUnlockCommon(F_ULOCK); 306 LockOrUnlockCommon(F_ULOCK);
305 } 307 }
306 308
307 SharedMemoryHandle SharedMemory::handle() const { 309 SharedMemoryHandle SharedMemory::handle() const {
308 return FileDescriptor(mapped_file_, false); 310 return FileDescriptor(mapped_file_, false);
309 } 311 }
310 312
311 } // namespace base 313 } // 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