Subject: bug#16940: [PATCH] tests: Do not access /dev/tty if it does not exist

From: Bernhard Voelker <[email-masked]>
Date: Wed, 05 Mar 2014 16:43:49 +0100

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

WDYT?

Thanks & have a nice day,
Berny