assert(aSize > 0);
assert(theFD < 0);
- theFD = shm_open(theName.termedBuf(), O_CREAT | O_RDWR | O_TRUNC,
+ // OS X does not allow using O_TRUNC here.
+ theFD = shm_open(theName.termedBuf(), O_CREAT | O_RDWR,
S_IRUSR | S_IWUSR);
if (theFD < 0) {
debugs(54, 5, HERE << "shm_open " << theName << ": " << xstrerror());
}
if (ftruncate(theFD, aSize)) {
- debugs(54, 5, HERE << "ftruncate " << theName << ": " << xstrerror());
+ const int savedError = errno;
+ unlink();
+ debugs(54, 5, HERE << "ftruncate " << theName << ": " << xstrerr(savedError));
fatalf("Ipc::Mem::Segment::create failed to ftruncate(%s): %s\n",
- theName.termedBuf(), xstrerror());
+ theName.termedBuf(), xstrerr(savedError));
}
+ // We assume that the shm_open(O_CREAT)+ftruncate() combo zeros the segment.
- assert(statSize("Ipc::Mem::Segment::create") == aSize); // paranoid
+ theSize = statSize("Ipc::Mem::Segment::create");
+
+ // OS X will round up to a full page, so not checking for exact size match.
+ assert(theSize >= aSize);
- theSize = aSize;
theReserved = 0;
doUnlink = true;