mojo_ipc_util.cc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "remoting/host/mojo_ipc/mojo_ipc_util.h"
  5. #include <string>
  6. #include "build/build_config.h"
  7. #if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
  8. #include "base/files/file_path.h"
  9. #include "base/files/file_util.h"
  10. #include "base/logging.h"
  11. #endif
  12. namespace remoting {
  13. mojo::NamedPlatformChannel::ServerName
  14. WorkingDirectoryIndependentServerNameFromUTF8(base::StringPiece name) {
  15. #if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
  16. // The channel name on non-mac POSIX (basically Linux) is the path to a unix
  17. // domain socket, so it needs to be an absolute path to allow the IPC binary
  18. // to be executed from any working directory.
  19. base::FilePath temp_dir_path;
  20. if (base::GetTempDir(&temp_dir_path)) {
  21. return mojo::NamedPlatformChannel::ServerNameFromUTF8(
  22. temp_dir_path.Append(name).value());
  23. }
  24. LOG(ERROR) << "Failed to retrieve temporary directory.";
  25. // Fallback to just using |name|.
  26. #endif
  27. // ServerName on other platforms (i.e. Windows and Mac) is globally unique.
  28. return mojo::NamedPlatformChannel::ServerNameFromUTF8(name);
  29. }
  30. } // namespace remoting