================
@@ -122,8 +123,14 @@ struct ForkLaunchInfo {
         ExitWithError(error_fd, "close");
       break;
     case FileAction::eFileActionDuplicate:
-      if (dup2(action.fd, action.arg) == -1)
-        ExitWithError(error_fd, "dup2");
+      if (action.fd != action.arg) {
+        if (dup2(action.fd, action.arg) == -1)
+          ExitWithError(error_fd, "dup2");
+      } else {
+        if (fcntl(action.fd, F_SETFD,
+                  fcntl(action.fd, F_GETFD) & ~FD_CLOEXEC) == -1)
----------------
labath wrote:

Yes, I guess.

It's a potential leak, but it's not one that this code, or anything in the 
parent process can fix. Directly after an execve, all FDs will have the CLOEXEC 
flag cleared -- by definition. No matter what you do, if you want to pass an FD 
through execve, you have to ensure that flag is cleared at the time you call 
execve. Previously we did that by doing nothing. Now we do it by setting the 
flag as early as possible (ideally when the FD is created), and clearing it 
after the fork.

What the happens to the FD afterwards is out of our hands. If the process 
doesn't want to pass the fd on, it should set the flag, or otherwise ensure it 
gets closed. But there's nothing we can do to about it if it chooses to ignore 
that.

https://github.com/llvm/llvm-project/pull/126935
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to