Skip to content

Commit d690934

Browse files
author
Aengus.Jiang
committed
open的时候不存在共享内存,则返回false,没有必要报错
1 parent df09c22 commit d690934

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/libipc/platform/posix/shm_posix.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ 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+
if (open != mode) {
76+
ipc::error("fail shm_open[%d]: %s\n", errno, op_name.c_str());
77+
}
7678
return nullptr;
7779
}
7880
::fchmod(fd, S_IRUSR | S_IWUSR |

src/libipc/shm.cpp

Lines changed: 5 additions & 1 deletion
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)