On Thu, Jun 25, 2026 at 02:15:22 -0400, Zachary Santer wrote:
> --close-from=100 might be the best way to go, if figuring out the
> specific fds that you don't want sudo to close, when you need to know,
> is at best not something that can be done everywhere.
I'd go with named pipes, if the goal is "everywhere". Nevertheless, as
an intellectual exercise:
sudowrap() {
local arg max=3
for arg; do
if [[ $arg =~ /dev/fd/([0-9]+)$ ]]; then
max=$(( BASH_REMATCH[1]+1 > max ? BASH_REMATCH[1]+1 : max ))
fi
done
sudo --close-from="$max" "$@"
}
On my system, this gives me:
hobbit:~$ sudowrap diff <(echo 1) <(echo 2)
sudo: you are not permitted to use the -C option
So, see sudoers(5) and good luck with that.
P.S. Out of curiosity, I looked at doas, but that one has the same issue.
hobbit:~$ doas diff <(echo 1) <(echo 2)
doas (greg@hobbit) password:
diff: /dev/fd/63: No such file or directory
diff: /dev/fd/62: No such file or directory
It's not even configurable: see
<https://github.com/Duncaen/OpenDoas/blob/master/doas.c#L265>
which just says
closefrom(STDERR_FILENO + 1);
It's literally the second command in the main() function after the
variable declarations.