summaryrefslogtreecommitdiffstats
path: root/lldb/source/Host/posix/PipePosix.cpp
diff options
context:
space:
mode:
authorOleksiy Vyalov <ovyalov@google.com>2015-02-05 16:29:12 +0000
committerOleksiy Vyalov <ovyalov@google.com>2015-02-05 16:29:12 +0000
commit4536c458e1d9eb650a8bb487d82280afac64f4f1 (patch)
tree01c31ba537a11f2bd521e93335802c653424989e /lldb/source/Host/posix/PipePosix.cpp
parent72b3b62fac3fbe0c5eb84974495014c4e8d322ee (diff)
downloadbcm5719-llvm-4536c458e1d9eb650a8bb487d82280afac64f4f1.tar.gz
bcm5719-llvm-4536c458e1d9eb650a8bb487d82280afac64f4f1.zip
Fix warning about the use of mktemp and make platform agnostic by adding and using PipeBase::CreateWithUniqueName - on behalf of flackr.
http://reviews.llvm.org/D7348 llvm-svn: 228307
Diffstat (limited to 'lldb/source/Host/posix/PipePosix.cpp')
-rw-r--r--lldb/source/Host/posix/PipePosix.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/lldb/source/Host/posix/PipePosix.cpp b/lldb/source/Host/posix/PipePosix.cpp
index 02838ec5124..1650f1e7979 100644
--- a/lldb/source/Host/posix/PipePosix.cpp
+++ b/lldb/source/Host/posix/PipePosix.cpp
@@ -9,12 +9,16 @@
#include "lldb/Host/posix/PipePosix.h"
#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/FileSystem.h"
#include <functional>
#include <thread>
#include <errno.h>
#include <fcntl.h>
+#include <limits.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -183,6 +187,37 @@ PipePosix::CreateNew(llvm::StringRef name, bool child_process_inherit)
}
Error
+PipePosix::CreateWithUniqueName(llvm::StringRef prefix, bool child_process_inherit, llvm::SmallVectorImpl<char>& name)
+{
+ llvm::SmallString<PATH_MAX> named_pipe_path;
+ llvm::SmallString<PATH_MAX> pipe_spec((prefix + ".%%%%%%").str());
+ FileSpec tmpdir_file_spec;
+ tmpdir_file_spec.Clear();
+ if (HostInfo::GetLLDBPath(ePathTypeLLDBTempSystemDir, tmpdir_file_spec))
+ {
+ tmpdir_file_spec.AppendPathComponent(pipe_spec.c_str());
+ }
+ else
+ {
+ tmpdir_file_spec.AppendPathComponent("/tmp");
+ tmpdir_file_spec.AppendPathComponent(pipe_spec.c_str());
+ }
+
+ // It's possible that another process creates the target path after we've
+ // verified it's available but before we create it, in which case we
+ // should try again.
+ Error error;
+ do {
+ llvm::sys::fs::createUniqueFile(tmpdir_file_spec.GetPath().c_str(), named_pipe_path);
+ error = CreateNew(named_pipe_path, child_process_inherit);
+ } while (error.GetError() == EEXIST);
+
+ if (error.Success())
+ name = named_pipe_path;
+ return error;
+}
+
+Error
PipePosix::OpenAsReader(llvm::StringRef name, bool child_process_inherit)
{
if (CanRead() || CanWrite())
OpenPOWER on IntegriCloud