[Mlir-commits] [mlir] [mlir][lsp] Ensure stdin is blocking. (PR #74117)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Dec 1 09:41:42 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Jacques Pienaar (jpienaar)

<details>
<summary>Changes</summary>

Without this/if forked where non-blocking is set, the input fails as there are no retries while reading a line.

Not sure if this is a bit of a hammer, but avoids surprises depending on how server is "launched".

---
Full diff: https://github.com/llvm/llvm-project/pull/74117.diff


1 Files Affected:

- (modified) mlir/lib/Tools/mlir-lsp-server/MlirLspServerMain.cpp (+9) 


``````````diff
diff --git a/mlir/lib/Tools/mlir-lsp-server/MlirLspServerMain.cpp b/mlir/lib/Tools/mlir-lsp-server/MlirLspServerMain.cpp
index 259bd2613a6ccdd..3cc218aa2a527ed 100644
--- a/mlir/lib/Tools/mlir-lsp-server/MlirLspServerMain.cpp
+++ b/mlir/lib/Tools/mlir-lsp-server/MlirLspServerMain.cpp
@@ -7,6 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "mlir/Tools/mlir-lsp-server/MlirLspServerMain.h"
+#include <cerrno>
+#include <cstring>
+#include <fcntl.h>
+#include <unistd.h>
 #include "LSPServer.h"
 #include "MLIRServer.h"
 #include "mlir/IR/Dialect.h"
@@ -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");

``````````

</details>


https://github.com/llvm/llvm-project/pull/74117


More information about the Mlir-commits mailing list