open的时候不存在共享内存,则返回false,没有必要报错

This commit is contained in:
Aengus.Jiang 2025-03-07 11:36:57 +08:00
parent df09c22738
commit d69093462a
2 changed files with 8 additions and 2 deletions

View File

@ -72,7 +72,9 @@ id_t acquire(char const * name, std::size_t size, unsigned mode) {
S_IRGRP | S_IWGRP | S_IRGRP | S_IWGRP |
S_IROTH | S_IWOTH); S_IROTH | S_IWOTH);
if (fd == -1) { if (fd == -1) {
ipc::error("fail shm_open[%d]: %s\n", errno, op_name.c_str()); if (open != mode) {
ipc::error("fail shm_open[%d]: %s\n", errno, op_name.c_str());
}
return nullptr; return nullptr;
} }
::fchmod(fd, S_IRUSR | S_IWUSR | ::fchmod(fd, S_IRUSR | S_IWUSR |

View File

@ -78,8 +78,12 @@ bool handle::acquire(char const * name, std::size_t size, unsigned mode) {
return false; return false;
} }
release(); release();
const auto id = shm::acquire(name, size, mode);
if (!id) {
return false;
}
impl(p_)->id_ = id;
impl(p_)->n_ = name; impl(p_)->n_ = name;
impl(p_)->id_ = shm::acquire(name, size, mode);
impl(p_)->m_ = shm::get_mem(impl(p_)->id_, &(impl(p_)->s_)); impl(p_)->m_ = shm::get_mem(impl(p_)->id_, &(impl(p_)->s_));
return valid(); return valid();
} }