GNU bug report logs -
#16940
[PATCH] tests: Do not access /dev/tty if it does not exist
Previous Next
Reported by: Cyril Roelandt <tipecaml <at> gmail.com>
Date: Wed, 5 Mar 2014 03:42:01 UTC
Severity: normal
Tags: fixed, patch
Done: Assaf Gordon <assafgordon <at> gmail.com>
Bug is archived. No further changes may be made.
Full log
Message #26 received at 16940 <at> debbugs.gnu.org (full text, mbox):
On 03/05/2014 03:43 PM, Bernhard Voelker wrote:
> On 03/05/2014 04:21 PM, Pádraig Brady wrote:
>> Ondřej Vašík ran the rawhide build again producing:
>>
>> ./tests/misc/nohup.sh: line 66: /dev/tty: No such device or address
>> + fail=1
>>
>> So exec >/dev/tty is throwing ENXIO and exiting the subshell.
>> ENXIO is fine and corresponds to the process not having a controlling tty.
>>
>> I guessed the change here is with the newly released bash 4.3
>> which is exiting the subshell immediately in this case, and confirmed
>> the following fails:
>>
>> setsid make SHELL=~/bash-4.3/bash TESTS=tests/misc/nohup.sh SUBDIRS=. check
>>
>> Now reducing the case and comparing different shells we get:
>>
>> $ setsid bash --posix -c 'echo $BASH_VERSION; (exec >/dev/tty; exit 0) || echo failed_early'
>> 4.2.45(1)-release
>> bash: /dev/tty: No such device or address
>>
>> $ setsid ./bash --posix -c 'echo $BASH_VERSION; (exec >/dev/tty; exit 0) || echo failed_early'
>> 4.3.0(1)-release
>> ./bash: /dev/tty: No such device or address
>> failed_early
>>
>> $ setsid ksh -c '(exec >/dev/tty; exit 0) || echo failed_early'
>> $ ksh: /dev/tty: cannot create [No such device or address]
>> failed_early
>>
>> $ setsid dash -c '(exec >/dev/tty; exit 0) || echo failed_early'
>> dash: 1: cannot create /dev/tty: No such device or address
>> failed_early
>
> oh, that's a tricky one.
> Thanks for the in-depth analysis.
>
>> So rather than newer bash being the difference here,
>> it's the older bash that is the outlier.
>> So we should adjust the test case to handle all shells.
>> Proposed patch attached.
>
>> + # POSIX shells immediately exit the subshell on exec error.
>> + # So check we can write to /dev/tty before the exec, which
>> + # isn't possible if we've no controlling tty for example.
>> + >/dev/tty || exit 0
>> +
>
> The above '>/dev/tty' would also work if /dev/tty does not exist
> and /dev is writable. Therefore - although the reason of the failure
> originates from something completely different -, I think it'd be better
> to go back to checking explicitly for a character device again:
>
> test -c /dev/tty && :>/dev/tty || exit 0
The test -c is safer. I'll add that.
Note the ':>' is problematic though as the : always returns true.
Well it does for solaris, freebsd, dash, bash-4.3 at least.
In ksh and bash<=4.2 it does return an error as you assumed.
The ':>' construct is only needed for csh anyway I think
which we don't support.
I notice a few more cases: git grep ": *>.*"
which I'll fix in a follow up patch with maybe a syntax check.
thanks,
Pádraig.
This bug report was last modified 6 years and 227 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.