in cachelib/shm/SysVShmSegment.cpp [35:89]
int shmGetImpl(key_t key, size_t size, int flags) {
if (key == IPC_PRIVATE) {
util::throwSystemError(EINVAL, "Cannot create private segment");
}
const int shmid = shmget(key, size, flags);
if (shmid != kInvalidShmId) {
return shmid;
}
switch (errno) {
case EACCES:
case EINVAL:
case ENOSPC:
case ENOMEM:
case ENFILE:
util::throwSystemError(
errno,
folly::sformat(
"Failed to create segment with key {}, size {}, flags {}",
key,
size,
flags));
break;
case ENOENT:
if (!(flags & IPC_CREAT)) { // trying to attach
util::throwSystemError(errno);
} else {
util::throwSystemError(errno, "Invalid errno");
}
break;
case EEXIST:
if (flags & (IPC_CREAT | IPC_EXCL)) { // trying to create
util::throwSystemError(errno);
} else {
XDCHECK(false);
util::throwSystemError(errno, "Invalid errno");
}
break;
case EPERM:
#ifdef __linux__
if (flags & SHM_HUGETLB) {
util::throwSystemError(errno);
break;
}
#endif
XDCHECK(false);
util::throwSystemError(errno, "Invalid errno");
default:
XDCHECK(false);
util::throwSystemError(errno, "Invalid errno");
}
return kInvalidShmId;
}