diff options
author | Kevin Lindkvist <lindkvist@google.com> | 2021-09-07 14:56:27 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-09-07 14:58:39 -0700 |
commit | 2f2fb3813f59922156258b816ea50d49a70d617c (patch) | |
tree | 3b731c418617cf1c3bb36270b394dafb276a036b | |
parent | dfc518005bf9fd6abdc8dc906d7572f6cc2c5a35 (diff) |
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
-rw-r--r-- | test/util/socket_util.cc | 12 |
1 files changed, 12 insertions, 0 deletions
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<FileDescriptor> SyscallSocketCreator(int domain, int type, PosixErrorOr<struct sockaddr_un> 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"); |