Try to fix a communication problem caused by different permissions under linux

This commit is contained in:
mutouyun 2024-12-01 19:53:40 +08:00
parent 5e5b347636
commit 84bb801b6e

View File

@ -68,13 +68,14 @@ id_t acquire(char const * name, std::size_t size, unsigned mode) {
flag |= O_CREAT; flag |= O_CREAT;
break; break;
} }
int fd = ::shm_open(op_name.c_str(), flag, S_IRUSR | S_IWUSR | int fd = ::shm_open(op_name.c_str(), flag, 0);
S_IRGRP | S_IWGRP |
S_IROTH | S_IWOTH);
if (fd == -1) { if (fd == -1) {
ipc::error("fail shm_open[%d]: %s\n", errno, op_name.c_str()); ipc::error("fail shm_open[%d]: %s\n", errno, op_name.c_str());
return nullptr; return nullptr;
} }
::fchmod(fd, S_IRUSR | S_IWUSR |
S_IRGRP | S_IWGRP |
S_IROTH | S_IWOTH);
auto ii = mem::alloc<id_info_t>(); auto ii = mem::alloc<id_info_t>();
ii->fd_ = fd; ii->fd_ = fd;
ii->size_ = size; ii->size_ = size;