Merge pull request #139 from aengusjiang/master

acquire 仅open不存在的shm不应该打印错误日志
This commit is contained in:
木头云 2025-03-08 15:52:35 +08:00 committed by GitHub
commit f3bf137668
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

View File

@ -72,7 +72,10 @@ 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()); // only open shm not log error when file not exist
if (open != mode || ENOENT != errno) {
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();
} }