Skip to content

Commit f3bf137

Browse files
authored
Merge pull request #139 from aengusjiang/master
acquire 仅open不存在的shm不应该打印错误日志
2 parents df09c22 + 7bb5f2e commit f3bf137

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/libipc/platform/posix/shm_posix.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ id_t acquire(char const * name, std::size_t size, unsigned mode) {
7272
S_IRGRP | S_IWGRP |
7373
S_IROTH | S_IWOTH);
7474
if (fd == -1) {
75-
ipc::error("fail shm_open[%d]: %s\n", errno, op_name.c_str());
75+
// only open shm not log error when file not exist
76+
if (open != mode || ENOENT != errno) {
77+
ipc::error("fail shm_open[%d]: %s\n", errno, op_name.c_str());
78+
}
7679
return nullptr;
7780
}
7881
::fchmod(fd, S_IRUSR | S_IWUSR |

src/libipc/shm.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,12 @@ bool handle::acquire(char const * name, std::size_t size, unsigned mode) {
7878
return false;
7979
}
8080
release();
81+
const auto id = shm::acquire(name, size, mode);
82+
if (!id) {
83+
return false;
84+
}
85+
impl(p_)->id_ = id;
8186
impl(p_)->n_ = name;
82-
impl(p_)->id_ = shm::acquire(name, size, mode);
8387
impl(p_)->m_ = shm::get_mem(impl(p_)->id_, &(impl(p_)->s_));
8488
return valid();
8589
}

0 commit comments

Comments
 (0)