-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[lldb-dap] Ensure we do not print the close sentinel when closing stdout. #126833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| #include "DAP.h" | ||
| #include "llvm/ADT/StringRef.h" | ||
| #include "llvm/Support/Error.h" | ||
| #include <cstring> | ||
| #include <system_error> | ||
| #if defined(_WIN32) | ||
| #include <fcntl.h> | ||
|
|
@@ -25,6 +26,10 @@ using llvm::Expected; | |
| using llvm::inconvertibleErrorCode; | ||
| using llvm::StringRef; | ||
|
|
||
| namespace { | ||
| char kCloseSentinel[] = "\0"; | ||
| } // namespace | ||
|
|
||
| namespace lldb_dap { | ||
|
|
||
| int OutputRedirector::kInvalidDescriptor = -1; | ||
|
|
@@ -59,7 +64,10 @@ Error OutputRedirector::RedirectTo(std::function<void(StringRef)> callback) { | |
| while (!m_stopped) { | ||
| ssize_t bytes_count = ::read(read_fd, &buffer, sizeof(buffer)); | ||
| // EOF detected. | ||
| if (bytes_count == 0) | ||
| if (bytes_count == 0 || | ||
|
||
| (bytes_count == sizeof(kCloseSentinel) && | ||
| std::memcmp(buffer, kCloseSentinel, sizeof(kCloseSentinel)) == 0 && | ||
| m_fd == kInvalidDescriptor)) | ||
ashgti marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| break; | ||
| if (bytes_count == -1) { | ||
| // Skip non-fatal errors. | ||
|
|
@@ -85,8 +93,7 @@ void OutputRedirector::Stop() { | |
| // Closing the pipe may not be sufficient to wake up the thread in case the | ||
| // write descriptor is duplicated (to stdout/err or to another process). | ||
| // Write a null byte to ensure the read call returns. | ||
| char buf[] = "\0"; | ||
| (void)::write(fd, buf, sizeof(buf)); | ||
| (void)::write(fd, kCloseSentinel, sizeof(kCloseSentinel)); | ||
| ::close(fd); | ||
| m_forwarder.join(); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.