Re: [PATCH v3] redir: Handle nested exec within REALLY_CLOSED redirection

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 16/01/2019 21:53, Martijn Dekker wrote:
Op 16-01-19 om 22:39 schreef Martijn Dekker:
Op 16-01-19 om 14:32 schreef Herbert Xu:
Thanks for the patch.  I took a deeper look into the history of
the bug and it turned out that I added REALLY_CLOSED as an
optimisation in order to avoid an unnecessary close(2) syscall.

Does this actually save cycles? I'm probably missing something, but that
code looks to me like it probably uses more cycles than close(2) going
'descriptor not open, return'.

Never mind, stupid question that I should have googled before asking it.
The answer is that a switch to kernel mode and back is expensive.

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.

Cheers,
Harald van Dijk



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux