[libcxx-commits] [libcxx] [libc++][test] try to directly create socket file in /tmp when filepath is too long (PR #77058)

Wu Yingcong via libcxx-commits libcxx-commits at lists.llvm.org
Sun Jan 7 17:20:24 PST 2024


================
@@ -320,15 +321,27 @@ struct scoped_test_env
   // allow tests to call this unguarded.
 #if !defined(__FreeBSD__) && !defined(__APPLE__) && !defined(_WIN32)
     std::string create_socket(std::string file) {
-        file = sanitize_path(std::move(file));
+      std::string socket_file = sanitize_path(file);
 
-        ::sockaddr_un address;
-        address.sun_family = AF_UNIX;
-        assert(file.size() <= sizeof(address.sun_path));
-        ::strncpy(address.sun_path, file.c_str(), sizeof(address.sun_path));
-        int fd = ::socket(AF_UNIX, SOCK_STREAM, 0);
-        ::bind(fd, reinterpret_cast<::sockaddr*>(&address), sizeof(address));
-        return file;
+      ::sockaddr_un address;
+      address.sun_family = AF_UNIX;
+
+      // If file.size() is too big, try to create a file directly inside
+      // /tmp to make sure file path is short enough.
----------------
yingcong-wu wrote:

Good advice, I will change to use that.

https://github.com/llvm/llvm-project/pull/77058


More information about the libcxx-commits mailing list