Re: [PATCH] setup: avoid unconditional open with write flags
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Dec 6, 2022, 23:39 UTC
- Message-ID
- <xmqqr0xc85l4.fsf@gitster.g>
- In-Reply-To
- <f49b915e-46d1-7e53-ae4f-b01c2028b70d@web.de>
René Scharfe <l.s.r@web.de> writes:
> Can opening /dev/null (or NUL on Windows) multiple times instead of dup'ing > cause issues? Can we e.g. lock ourselves out?
258e93a1 (daemon: if one of the standard fds is missing open it to /dev/null, 2006-07-13) unfortunately does not explain why it was done this way.
Given that "command </dev/null >/dev/null 2>/dev/null" should work fine, I suspect that the "once we open a throw-away descriptor, instead of opening the same file again, dup the fd and reuse" was done not for correctness but for performance, under the assumption that open() is more expensive?