OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |