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

No, because there is no way to pass a non-CLOEXEC FD to a process -- that the 
whole point of the flag. When the new process starts, the flag will always be 
cleared. The new process can (and should) set the CLOEXEC flag as soon as as 
possible (unless it intends to pass it to other processes of course).

I think part of the confusion here is that we're using the term "creating a 
process" very loosely. Naively the "new process" is the "`main` function of the 
new program", but that's not how it works at OS level. `fork` is the call which 
creates a new process. `execve` replaces the "program image executed by the 
current process". All FDs are passed through `fork` (so they technically end up 
in the new process) but only `~CLOEXEC` fds are passed through `execve` (so the 
"new program image" does not see them).

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