File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change 18
18
#include < chrono>
19
19
#include < cstdint>
20
20
#include < cstdio> // for printf
21
+ #include < ctime>
21
22
#include < string>
22
23
#include < system_error>
23
24
#include < type_traits>
@@ -324,10 +325,22 @@ struct scoped_test_env
324
325
325
326
::sockaddr_un address;
326
327
address.sun_family = AF_UNIX;
328
+
329
+ // If file.size() is too big, try to create a file directly inside
330
+ // /tmp to make sure file path is short enough.
331
+ if (file.size () <= sizeof (address.sun_path ) && utils::exists (" /tmp" )) {
332
+ fs::path const tmp = " /tmp" ;
333
+ std::size_t i = std::hash<std::string>()(std::to_string (std::time (nullptr )));
334
+ fs::path p = tmp / (" libcxx-socket-" + file + " -" + std::to_string (i));
335
+ while (utils::exists (p.string ())) {
336
+ p = tmp / (" libcxx-socket-" + file + " -" + std::to_string (++i));
337
+ }
338
+ file = p.string ();
339
+ }
327
340
assert (file.size () <= sizeof (address.sun_path ));
328
341
::strncpy (address.sun_path, file.c_str(), sizeof(address.sun_path));
329
342
int fd = ::socket (AF_UNIX, SOCK_STREAM, 0 );
330
- ::bind (fd, reinterpret_cast <::sockaddr*>(&address), sizeof(address));
343
+ assert ( ::bind (fd, reinterpret_cast <::sockaddr*>(&address), sizeof (address)) == 0 );
331
344
return file;
332
345
}
333
346
#endif
You can’t perform that action at this time.
0 commit comments