[Mlir-commits] [mlir] [mlir][lsp] Ensure stdin is blocking. (PR #74117)
Jacques Pienaar
llvmlistbot at llvm.org
Fri Dec 1 09:45:12 PST 2023
https://github.com/jpienaar updated https://github.com/llvm/llvm-project/pull/74117
>From a9a53aec73b66eb0f70f4c7f4a0412ead7c91f29 Mon Sep 17 00:00:00 2001
From: Jacques Pienaar <jpienaar at google.com>
Date: Fri, 1 Dec 2023 09:32:28 -0800
Subject: [PATCH] [mlir][lsp] Ensure stdin is blocking.
Without this/if forked where non-blocking is set, the input fails as
there are no retries while reading a line.
---
mlir/lib/Tools/mlir-lsp-server/MlirLspServerMain.cpp | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/mlir/lib/Tools/mlir-lsp-server/MlirLspServerMain.cpp b/mlir/lib/Tools/mlir-lsp-server/MlirLspServerMain.cpp
index 259bd2613a6ccdd..3d06d6f48893144 100644
--- a/mlir/lib/Tools/mlir-lsp-server/MlirLspServerMain.cpp
+++ b/mlir/lib/Tools/mlir-lsp-server/MlirLspServerMain.cpp
@@ -14,6 +14,10 @@
#include "mlir/Tools/lsp-server-support/Transport.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Program.h"
+#include <cerrno>
+#include <cstring>
+#include <fcntl.h>
+#include <unistd.h>
using namespace mlir;
using namespace mlir::lsp;
@@ -67,6 +71,11 @@ LogicalResult mlir::MlirLspServerMain(int argc, char **argv,
// Configure the transport used for communication.
llvm::sys::ChangeStdinToBinary();
JSONTransport transport(stdin, llvm::outs(), inputStyle, prettyPrint);
+ if (int flags = fcntl(STDIN_FILENO, F_GETFL, 0); flags < 0) {
+ Logger::debug("Error getting fcntl flags: %s\n", strerror(errno));
+ } else if (fcntl(STDIN_FILENO, F_SETFL, flags & ~(O_NONBLOCK)) < 0) {
+ Logger::debug("Error setting blocking stding: %s\n", strerror(errno));
+ }
// Register the additionally supported URI schemes for the MLIR server.
URIForFile::registerSupportedScheme("mlir.bytecode-mlir");
More information about the Mlir-commits
mailing list