On 17/01/2019 07:01, Herbert Xu wrote:
On Wed, Jan 16, 2019 at 10:29:50PM +0000, Harald van Dijk wrote:
Still, if that's slow enough and happens commonly enough that it's worth
avoiding, it seems like it would still be simpler, shorter and probably
faster to just write
if (fd != -1)
close(fd);
in a few places, since we know that the only invalid fd that ever gets
passed to close() is -1. That avoids the other cases where dash already
happily calls close(-1) as well.
The issue is not close(-1), it's close(8) for 8>&- where we already
know that fd 8 was closed to start with (because the first dup
returned -1 on it).
Oh, okay. In that case, the fact that there are code paths in which dash
ends up calling close(-1) may be another issue to look at, since that is
known before the call to be a wasted syscall as well.
Cheers,
Harald van Dijk