================
@@ -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) {
----------------
labath wrote:

Can you explain your reasoning?

This is something I have considered, and I came to the opposite conclusion. The 
reason is that I think this fits nicely into the `DuplicateFileAction(from, 
to)` interface. You're saying "I want to take fd `from` from my process and 
pass it as fd `to` to the child process". That statement makes sense regardless 
of whether `from` and `to` have the same value or not. The fact that one needs 
to use a different sequence of calls to achieve this effect is (can be) an 
implementation detail.

Imagine I have some file descriptor open, and for whatever reason, I want to 
pass it to the child process exactly as fd 47. That's something I can freely 
do, as I control all of the FDs of the child process, but if this were to be 
controlled by a separate flag, I would have to write special code to handle the 
case where the my own copy of that FD happens to be 47:
```
if (fd_I_want_to_pass != 47)
  info.AppendDuplicateFileAction(47, fd_I_want_to_pass);
else
  info.InheritFileAction(47);
```

>From a windows point of view, I agree that a separate action makes sense, but 
>if we can agree that the above makes sense for posix, then I think it also 
>makes sense to reuse the same thing here (we're sort of doing the same thing, 
>except that we only support the case where the two numbers are the same).

That said, since the `from==to` is going to be the only case that is going to 
work in cross-platform code, I can imagine having some wrapper/helper function, 
which lets you avoid specifying the same FD twice, but then calls 
`DuplicateFileAction(fd, fd)` under the hood. Would that address your concerns?

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

Reply via email to