From 267cc3292ec4f6a7ea062b3551d20ea4692b6b78 Mon Sep 17 00:00:00 2001 From: Michal Gorny Date: Wed, 23 Oct 2019 06:17:25 -0700 Subject: [lldb] [Python] Do not attempt to flush() a read-only fd Summary: When creating a FileSP object, do not flush() the underlying file unless it is open for writing. Attempting to flush() a read-only fd results in EBADF on NetBSD. Reviewers: lawrence_danna, labath, krytarowski Reviewed By: lawrence_danna, labath Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D69320 --- .../Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp') diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp index 70d9342..2b85ebf 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp @@ -1385,11 +1385,13 @@ llvm::Expected PythonFile::ConvertToFile(bool borrowed) { if (!options) return options.takeError(); - // LLDB and python will not share I/O buffers. We should probably - // flush the python buffers now. - auto r = CallMethod("flush"); - if (!r) - return r.takeError(); + if (options.get() & File::eOpenOptionWrite) { + // LLDB and python will not share I/O buffers. We should probably + // flush the python buffers now. + auto r = CallMethod("flush"); + if (!r) + return r.takeError(); + } FileSP file_sp; if (borrowed) { -- cgit v1.1