[Lldb-commits] [lldb] [lldb/Host] Enable inheriting "non-inheritable" FDs (PR #126935)
David Spickett via lldb-commits
lldb-commits at lists.llvm.org
Fri May 2 06:46:22 PDT 2025
================
@@ -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)
----------------
DavidSpickett wrote:
I don't think I knew what I was asking either tbh but I think I understand a bit more now.
You, the current process, are about to exec. So trying to give the new process an fd with O_CLOEXEC set wouldn't make any sense. By the time the new process tried to use it, it's already been closed.
I will see if the code makes more sense to me now.
https://github.com/llvm/llvm-project/pull/126935
More information about the lldb-commits
mailing list