return Status("Pipe is already opened");
Status error;
- if (::mkfifo(name.data(), 0660) != 0)
+ if (::mkfifo(name.str().c_str(), 0660) != 0)
error.SetErrorToErrno();
return error;
// try again.
Status error;
do {
- llvm::sys::fs::createUniqueFile(tmpdir_file_spec.GetPath(),
- named_pipe_path);
+ llvm::sys::fs::createUniquePath(tmpdir_file_spec.GetPath(), named_pipe_path,
+ /*MakeAbsolute=*/false);
error = CreateNew(named_pipe_path, child_process_inherit);
} while (error.GetError() == EEXIST);
flags |= O_CLOEXEC;
Status error;
- int fd = llvm::sys::RetryAfterSignal(-1, ::open, name.data(), flags);
+ int fd = llvm::sys::RetryAfterSignal(-1, ::open, name.str().c_str(), flags);
if (fd != -1)
m_fds[READ] = fd;
else
}
errno = 0;
- int fd = ::open(name.data(), flags);
+ int fd = ::open(name.str().c_str(), flags);
if (fd == -1) {
const auto errno_copy = errno;
// We may get ENXIO if a reader side of the pipe hasn't opened yet.
--- /dev/null
+//===-- PipeTest.cpp ------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Host/Pipe.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "gtest/gtest.h"
+
+using namespace lldb_private;
+
+class PipeTest : public testing::Test {
+public:
+ SubsystemRAII<FileSystem, HostInfo> subsystems;
+};
+
+TEST_F(PipeTest, CreateWithUniqueName) {
+ Pipe pipe;
+ llvm::SmallString<0> name;
+ ASSERT_THAT_ERROR(pipe.CreateWithUniqueName("PipeTest-CreateWithUniqueName",
+ /*child_process_inherit=*/false,
+ name)
+ .ToError(),
+ llvm::Succeeded());
+}
+
+TEST_F(PipeTest, OpenAsReader) {
+ Pipe pipe;
+ llvm::SmallString<0> name;
+ ASSERT_THAT_ERROR(pipe.CreateWithUniqueName("PipeTest-OpenAsReader",
+ /*child_process_inherit=*/false,
+ name)
+ .ToError(),
+ llvm::Succeeded());
+
+ // Ensure name is not null-terminated
+ size_t name_len = name.size();
+ name += "foobar";
+ llvm::StringRef name_ref(name.data(), name_len);
+ ASSERT_THAT_ERROR(
+ pipe.OpenAsReader(name_ref, /*child_process_inherit=*/false).ToError(),
+ llvm::Succeeded());
+}