From 2f2fb3813f59922156258b816ea50d49a70d617c Mon Sep 17 00:00:00 2001 From: Kevin Lindkvist Date: Tue, 7 Sep 2021 14:56:27 -0700 Subject: Conditionally use GetAbsoluteTestTmpdir() rather than hard-code "/tmp" NewTempAbsPathInDir("/tmp") prevents the generated socket address from exceeding sizeof(addr.sun_path). However, existing systems that are built with the ANDROID configuration have their temp directory in a different location. This change allows those systems to run tests that depend on UniqueUnixAddr. PiperOrigin-RevId: 395336483 --- test/util/socket_util.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/util/socket_util.cc b/test/util/socket_util.cc index f2360b732..650b422ae 100644 --- a/test/util/socket_util.cc +++ b/test/util/socket_util.cc @@ -57,7 +57,19 @@ Creator SyscallSocketCreator(int domain, int type, PosixErrorOr UniqueUnixAddr(bool abstract, int domain) { struct sockaddr_un addr = {}; + +#ifdef ANDROID + // Using NewTempAbsPath() can cause the tmp directory path to exceed the max + // length (i.e., sizeof(addr.sun_path)). + // + // However, existing systems that are built with the ANDROID configuration + // have their temp directory in a different location, and must respect the + // TEST_TMPDIR. + std::string path = NewTempAbsPath(); +#else std::string path = NewTempAbsPathInDir("/tmp"); +#endif // ANDROID + if (path.size() >= sizeof(addr.sun_path)) { return PosixError(EINVAL, "Unable to generate a temp path of appropriate length"); -- cgit v1.2.3