From d69093462a6b44702682aee3a9fa079c87573d22 Mon Sep 17 00:00:00 2001 From: "Aengus.Jiang" Date: Fri, 7 Mar 2025 11:36:57 +0800 Subject: [PATCH 1/3] =?UTF-8?q?open=E7=9A=84=E6=97=B6=E5=80=99=E4=B8=8D?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E5=85=B1=E4=BA=AB=E5=86=85=E5=AD=98=EF=BC=8C?= =?UTF-8?q?=E5=88=99=E8=BF=94=E5=9B=9Efalse=EF=BC=8C=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=BF=85=E8=A6=81=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libipc/platform/posix/shm_posix.cpp | 4 +++- src/libipc/shm.cpp | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/libipc/platform/posix/shm_posix.cpp b/src/libipc/platform/posix/shm_posix.cpp index 621b2f4..d1f570e 100644 --- a/src/libipc/platform/posix/shm_posix.cpp +++ b/src/libipc/platform/posix/shm_posix.cpp @@ -72,7 +72,9 @@ id_t acquire(char const * name, std::size_t size, unsigned mode) { S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); 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; } ::fchmod(fd, S_IRUSR | S_IWUSR | diff --git a/src/libipc/shm.cpp b/src/libipc/shm.cpp index 32b761e..a6a00c7 100755 --- a/src/libipc/shm.cpp +++ b/src/libipc/shm.cpp @@ -78,8 +78,12 @@ bool handle::acquire(char const * name, std::size_t size, unsigned mode) { return false; } release(); + const auto id = shm::acquire(name, size, mode); + if (!id) { + return false; + } + impl(p_)->id_ = id; impl(p_)->n_ = name; - impl(p_)->id_ = shm::acquire(name, size, mode); impl(p_)->m_ = shm::get_mem(impl(p_)->id_, &(impl(p_)->s_)); return valid(); } From 5c36b1264f7763f241225b7bf69e59825dbce74a Mon Sep 17 00:00:00 2001 From: "Aengus.Jiang" Date: Fri, 7 Mar 2025 11:57:31 +0800 Subject: [PATCH 2/3] =?UTF-8?q?posix=20shm=20open=20=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E6=97=B6=E5=A6=82=E6=9E=9C=E6=96=87=E4=BB=B6=E4=B8=8D=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E6=89=93=E5=8D=B0log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libipc/platform/posix/shm_posix.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libipc/platform/posix/shm_posix.cpp b/src/libipc/platform/posix/shm_posix.cpp index d1f570e..08633e3 100644 --- a/src/libipc/platform/posix/shm_posix.cpp +++ b/src/libipc/platform/posix/shm_posix.cpp @@ -72,7 +72,8 @@ id_t acquire(char const * name, std::size_t size, unsigned mode) { S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); if (fd == -1) { - if (open != mode) { + // 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; From 06d4aec3200054f5efc3b52899b2b14f1c8bc8fe Mon Sep 17 00:00:00 2001 From: "Aengus.Jiang" Date: Fri, 7 Mar 2025 12:33:42 +0800 Subject: [PATCH 3/3] =?UTF-8?q?posix=20shm=20open=20=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E6=97=B6=E5=A6=82=E6=9E=9C=E6=96=87=E4=BB=B6=E4=B8=8D=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E6=89=93=E5=8D=B0log=20#2=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libipc/platform/posix/shm_posix.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libipc/platform/posix/shm_posix.cpp b/src/libipc/platform/posix/shm_posix.cpp index d1f570e..968a202 100644 --- a/src/libipc/platform/posix/shm_posix.cpp +++ b/src/libipc/platform/posix/shm_posix.cpp @@ -72,7 +72,8 @@ id_t acquire(char const * name, std::size_t size, unsigned mode) { S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); if (fd == -1) { - if (open != mode) { + // 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;