Jui-min Lee has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/65153?usp=email )

Change subject: mem: Fix SHM server path cleanup logic
......................................................................

mem: Fix SHM server path cleanup logic

Previously, shared memory server remove old socket *before* filling the
target path into API's data structure. However, the target path might
get truncated hence the path we check against might not be the one we
will be using in the end.

In a case where the path specified by user is free while the truncated
path is in used, gem5 will get a mysterious EADDRINUSE.

We swap the two steps in the CL, so we'll be checking against the actual
path we use, instead of the path user request to use.

Change-Id: Ib34f8b00ea1d2f15dcd4e7b6d2d4a6d6ddc4e411
---
M src/mem/shared_memory_server.cc
1 file changed, 35 insertions(+), 11 deletions(-)



diff --git a/src/mem/shared_memory_server.cc b/src/mem/shared_memory_server.cc
index ae5043f..52f599f 100644
--- a/src/mem/shared_memory_server.cc
+++ b/src/mem/shared_memory_server.cc
@@ -56,14 +56,6 @@
       system(params.system), serverFd(-1)
 {
     fatal_if(system == nullptr, "Requires a system to share memory from!");
-    // Ensure the unix socket path to use is not occupied. Also, if there's
- // actually anything to be removed, warn the user something might be off.
-    if (unlink(unixSocketPath.c_str()) == 0) {
-        warn(
-            "The server path %s was occupied and will be replaced. Please "
-            "make sure there is no other server using the same path.",
-            unixSocketPath.c_str());
-    }
     // Create a new unix socket.
     serverFd = ListenSocket::socketCloexec(AF_UNIX, SOCK_STREAM, 0);
panic_if(serverFd < 0, "%s: cannot create unix socket: %s", name().c_str(),
@@ -73,9 +65,21 @@
     serv_addr.sun_family = AF_UNIX;
     strncpy(serv_addr.sun_path, unixSocketPath.c_str(),
             sizeof(serv_addr.sun_path) - 1);
-    warn_if(strlen(serv_addr.sun_path) != unixSocketPath.size(),
-            "%s: unix socket path truncated, expect '%s' but get '%s'",
-            name().c_str(), unixSocketPath.c_str(), serv_addr.sun_path);
+ // If the target path is truncated, warn the user that the actual path is
+    // different and update the target path.
+    if (strlen(serv_addr.sun_path) != unixSocketPath.size()) {
+        warn("%s: unix socket path truncated, expect '%s' but get '%s'",
+             name().c_str(), unixSocketPath.c_str(), serv_addr.sun_path);
+        unixSocketPath = serv_addr.sun_path;
+    }
+    // Ensure the unix socket path to use is not occupied. Also, if there's
+ // actually anything to be removed, warn the user something might be off.
+    if (unlink(unixSocketPath.c_str()) == 0) {
+        warn(
+            "The server path %s was occupied and will be replaced. Please "
+            "make sure there is no other server using the same path.",
+            unixSocketPath.c_str());
+    }
     int bind_retv = bind(serverFd, reinterpret_cast<sockaddr*>(&serv_addr),
                          sizeof(serv_addr));
fatal_if(bind_retv != 0, "%s: cannot bind unix socket: %s", name().c_str(),

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/65153?usp=email To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Ib34f8b00ea1d2f15dcd4e7b6d2d4a6d6ddc4e411
Gerrit-Change-Number: 65153
Gerrit-PatchSet: 1
Gerrit-Owner: Jui-min Lee <f...@google.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org

Reply via email to