RE: [PATCH v3 2/4] terminal: don't assume stdin is /dev/tty
- From
rsbecker@nexbridge.com <rsbecker@nexbridge.com>
- Date
- Mar 15, 2022, 19:38 UTC
- Message-ID
- <031801d838a4$4d3c7770$e7b56650$@nexbridge.com>
- In-Reply-To
- <xmqqilsfdok0.fsf@gitster.g>
On March 15, 2022 3:05 PM, Junio C Hamano wrote:
Show 24 quoted lines
>To: rsbecker@nexbridge.com
>Cc: 'Phillip Wood' <phillip.wood123@gmail.com>; 'Git Mailing List'
><git@vger.kernel.org>; 'Phillip Wood' <phillip.wood@dunelm.org.uk>; 'Ævar
>Arnfjörð Bjarmason' <avarab@gmail.com>; 'Carlo Arenas' <carenas@gmail.com>;
>'Johannes Schindelin' <Johannes.Schindelin@gmx.de>; 'Ramsay Jones'
><ramsay@ramsayjones.plus.com>
>Subject: Re: [PATCH v3 2/4] terminal: don't assume stdin is /dev/tty
>
><rsbecker@nexbridge.com> writes:
>
>>>The check before closing it is wrong. It should be
>>>
>>> if (0 <= term_fd)
>>
>> Should this expression succeed if term_fd == stdin? I might be missing the point
>here.
>
>We could use "if (0 < term_fd)" to make this guard both about avoiding to call
>close() on an uninitialized FD and also about avoiding to close standard input. I'd
>prefer to see them handled separately as these live at different conceptual levels
>(i.e. closing -1 is a no-no no matter what, closing 0 is bad if it is what we did not
>open but what the caller supplied us via the SAVE_TERM_STDIN bit, but it may be
>warranted if it was what we obtained from an earlier call to open("/dev/tty") we
>did ourselves).Thanks. This is one of those situations where explaining magic numbers is important. I appreciate the insight.
Regards, Randall