================
@@ -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:

I'm not sure this answers your question, but here it goes:

In both cases, this code ensures that `action.fd` is passed (as `action.arg`) 
to the new process. The difference between the new and old versions of the code 
is in what flags does the new fd have. Before this patch, if the two FDs were 
different, the new fd would have O_CLOEXEC cleared (as that's the default). If 
they were the same, then the flags would be unchanged (as `dup2` is a no-op in 
this case). This made the "same" case useless, because if the FD had O_CLOEXEC 
clear, then you wouldn't need to do anything to pass it; and if it would be 
set, then it wouldn't make it past `execve` anyway.

What this patch does is make sure the O_CLOEXEC flags is cleared in the "same" 
case -- just like it would be if the fd numbers were different.


If this doesn't help, then I think I don't understand your question. :)

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