[FFmpeg-devel] [PATCH] ffmpeg: use isatty() before messing with the terminal state

Reimar Döffinger Reimar.Doeffinger at gmx.de
Wed Jun 6 09:27:14 CEST 2012


On 6 Jun 2012, at 03:55, Michael Niedermayer <michaelni at gmx.at> wrote:
> On Tue, Jun 05, 2012 at 08:36:50PM +0200, François Revol wrote:
>> On 05/06/2012 20:24, Michael Niedermayer wrote:
>>> This fixes terminal messup in case of crashes (like in make fate)
>>> 
>>> Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
>>> ---
>>> ffmpeg.c |    4 +++-
>>> 1 file changed, 3 insertions(+), 1 deletion(-)
>>> 
>>> diff --git a/ffmpeg.c b/ffmpeg.c
>>> index a897c9e..8d5c1af 100644
>>> --- a/ffmpeg.c
>>> +++ b/ffmpeg.c
>>> @@ -1369,7 +1369,9 @@ static void term_init(void)
>>> #if HAVE_TERMIOS_H
>>>     if(!run_as_daemon){
>>>         struct termios tty;
>>> -
>>> +#if HAVE_ISATTY
>>> +        if(isatty(0) && isatty(2))
>>> +#endif
>>>         if (tcgetattr (0, &tty) == 0) {
>>>             oldtty = tty;
>>>             restore_tty = 1;
>> 
>> indentation seems odd but on the principle this looks ok to me.
> 
> dunno what i could do about the indention, reindenting the code
> after the #if#else would look odd too i think, so ill leave the
> indention for now

Just avoid the issue? These kind of ifs are confusing anyway and easy to break, better to avoid them in the first place. E.g.
int istty = 1;
#if HAVE_ISATTY
istty = isatty(0) && isatty(2);
#endif
if (istty && tcgetattr(...


More information about the ffmpeg-devel mailing list