From d50e027402eb0c4f31ad9c2be53f5ddc48ca16f9 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Sun, 1 Jul 2018 14:27:56 +0200 Subject: [PATCH] Open cli pipe file as read-write - When vimr is `Ctrl-C`'ed, then O_WRONLY hangs. --- VimR/VimR/MainWindow+Delegates.swift | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/VimR/VimR/MainWindow+Delegates.swift b/VimR/VimR/MainWindow+Delegates.swift index 9ff34309..d944ce99 100644 --- a/VimR/VimR/MainWindow+Delegates.swift +++ b/VimR/VimR/MainWindow+Delegates.swift @@ -26,16 +26,18 @@ extension MainWindow { self.set(dirtyStatus: false) self.emit(self.uuidAction(for: .close)) - if let cliPipePath = self.cliPipePath { - let fd = Darwin.open(cliPipePath, O_WRONLY) - guard fd != -1 else { - return - } - - let handle = FileHandle(fileDescriptor: fd) - handle.closeFile() - _ = Darwin.close(fd) + guard let cliPipePath = self.cliPipePath, FileManager.default.fileExists(atPath: cliPipePath) else { + return } + + let fd = Darwin.open(cliPipePath, O_RDWR) + guard fd != -1 else { + return + } + + let handle = FileHandle(fileDescriptor: fd) + handle.closeFile() + _ = Darwin.close(fd) } func set(title: String) {