From: rsbecker@nexbridge.com Date: Tue, 15 Mar 2022 19:38:46 GMT Subject: RE: [PATCH v3 2/4] terminal: don't assume stdin is /dev/tty Message-ID: <031801d838a4$4d3c7770$e7b56650$@nexbridge.com> In-Reply-To: On March 15, 2022 3:05 PM, Junio C Hamano wrote: >To: rsbecker@nexbridge.com >Cc: 'Phillip Wood' ; 'Git Mailing List' >; 'Phillip Wood' ; 'Ævar >Arnfjörð Bjarmason' ; 'Carlo Arenas' ; >'Johannes Schindelin' ; 'Ramsay Jones' > >Subject: Re: [PATCH v3 2/4] terminal: don't assume stdin is /dev/tty > > 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