<div dir="ltr">Hi, please be careful with O_CLOEXEC in the future.  I've had to fix two patches on Windows in the past week because of it.  It's not the end of the world, but just keep in mind next time using it that it doesn't exist on Windows so you'll need to wrap its use in an #if defined(_MSC_VER)<br></div><br><div class="gmail_quote">On Mon Feb 09 2015 at 3:41:01 AM Pavel Labath <<a href="mailto:labath@google.com">labath@google.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">REPOSITORY<br>
  rL LLVM<br>
<br>
<a href="http://reviews.llvm.org/D7466" target="_blank">http://reviews.llvm.org/D7466</a><br>
<br>
Files:<br>
  lldb/trunk/source/Utility/<u></u>PseudoTerminal.cpp<br>
  lldb/trunk/test/<u></u>functionalities/avoids-fd-<u></u>leak/TestFdLeak.py<br>
<br>
Index: lldb/trunk/source/Utility/<u></u>PseudoTerminal.cpp<br>
==============================<u></u>==============================<u></u>=======<br>
--- lldb/trunk/source/Utility/<u></u>PseudoTerminal.cpp<br>
+++ lldb/trunk/source/Utility/<u></u>PseudoTerminal.cpp<br>
@@ -239,7 +239,7 @@<br>
         error_str[0] = '\0';<br>
<br>
     pid_t pid = LLDB_INVALID_PROCESS_ID;<br>
-    if (OpenFirstAvailableMaster (O_RDWR, error_str, error_len))<br>
+    if (OpenFirstAvailableMaster (O_RDWR | O_CLOEXEC, error_str, error_len))<br>
     {<br>
         // Successfully opened our master pseudo terminal<br>
<br>
@@ -258,7 +258,8 @@<br>
             if (OpenSlave (O_RDWR, error_str, error_len))<br>
             {<br>
                 // Successfully opened slave<br>
-                // We are done with the master in the child process so lets close it<br>
+<br>
+                // Master FD should have O_CLOEXEC set, but let's close it just in case...<br>
                 CloseMasterFileDescriptor ();<br>
<br>
 #if defined(TIOCSCTTY)<br>
Index: lldb/trunk/test/<u></u>functionalities/avoids-fd-<u></u>leak/TestFdLeak.py<br>
==============================<u></u>==============================<u></u>=======<br>
--- lldb/trunk/test/<u></u>functionalities/avoids-fd-<u></u>leak/TestFdLeak.py<br>
+++ lldb/trunk/test/<u></u>functionalities/avoids-fd-<u></u>leak/TestFdLeak.py<br>
@@ -36,6 +36,29 @@<br>
         self.assertTrue(process.<u></u>GetExitStatus() == 0,<br>
                 "Process returned non-zero status. Were incorrect file descriptors passed?")<br>
<br>
+    @skipIfWindows # The check for descriptor leakage needs to be implemented differently here.<br>
+    def test_fd_leak_multitarget (self):<br>
+        self.buildDefault()<br>
+        exe = os.path.join (os.getcwd(), "a.out")<br>
+<br>
+        target = self.dbg.CreateTarget(exe)<br>
+<br>
+        listener = lldb.SBListener()<br>
+        error = lldb.SBError()<br>
+        process1 = target.Launch (listener, None, None, None, None, None,<br>
+                self.get_process_working_<u></u>directory(), 0, True, # stop at entry<br>
+                error)<br>
+        self.assertTrue(process1, PROCESS_IS_VALID)<br>
+        self.assertTrue(process1.<u></u>GetState() == lldb.eStateStopped, "Process should have been stopped.")<br>
+<br>
+        target2 = self.dbg.CreateTarget(exe)<br>
+        process2 = target2.LaunchSimple (None, None, self.get_process_working_<u></u>directory())<br>
+        self.assertTrue(process2, PROCESS_IS_VALID)<br>
+<br>
+        self.assertTrue(process2.<u></u>GetState() == lldb.eStateExited, "Process should have exited.")<br>
+        self.assertTrue(process2.<u></u>GetExitStatus() == 0,<br>
+                "Process returned non-zero status. Were incorrect file descriptors passed?")<br>
+<br>
<br>
 if __name__ == '__main__':<br>
     import atexit<br>
<br>
EMAIL PREFERENCES<br>
  <a href="http://reviews.llvm.org/settings/panel/emailpreferences/" target="_blank">http://reviews.llvm.org/<u></u>settings/panel/<u></u>emailpreferences/</a><br>
______________________________<u></u>_________________<br>
lldb-commits mailing list<br>
<a href="mailto:lldb-commits@cs.uiuc.edu" target="_blank">lldb-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/lldb-commits</a><br>
</blockquote></div>