#1431 Issue closed: Using '2>&1' or '2>&8' for 'select' clause results '-D' debug output on terminal

Labels: enhancement, cleanup, no-issue-activity

jsmeix opened issue at 2017-07-26 14:08:

When rear is run in debugscript mode via 'rear -D'
using '2>&1' or '2>&8' for 'select' clauses
results 'set -x' debug output on the user's terminal.

For example in
layout/prepare/default/300_map_disks.sh
there is

    select choice in "${possible_targets[@]}" "Do not map disk." ; do
        n=( $REPLY ) # trim blanks from reply
        let n-- # because bash arrays count from 0
        if [ "$n" = "${#possible_targets[@]}" ] || [ "$n" -lt 0 ] || [ "$n" -ge "${#possible_targets[@]}" ] ; then
            LogPrint "Disk $(get_device_name $dev) not automatically replaced."
        else
            LogPrint "Disk $choice chosen as replacement for $(get_device_name $dev)."
            add_mapping "$dev" "$choice"
        fi
        break
    done 0<&6 1>&7 2>&8

which results longer possibly disturbing
'set -x' debug output on the user's terminal:

Comparing disks.
Device sda has size 26843545600, 21474836480 expected
Switching to manual disk layout configuration.
Original disk /dev/sda does not exist in the target system. Please choose an appropriate replacement.
++ select choice in '"${possible_targets[@]}"' '"Do not map disk."'
1) /dev/sda
2) Do not map disk.
#? 1
++ n=($REPLY)
++ let n--
++ '[' 0 = 1 ']'
++ '[' 0 -lt 0 ']'
++ '[' 0 -ge 1 ']'
+++ get_device_name /dev/sda
+++ local name=sda
+++ name=sda
+++ [[ -n sda ]]
+++ BugIfError 'Empty string passed to get_device_name'
+++ ((  0 != 0  ))
+++ local device dev_number mapper_number
+++ [[ -d /sys/block/sda ]]
+++ [[ -r /sys/block/sda/dm/name ]]
+++ dev_number=8:0
+++ for device in '/dev/mapper/*'
++++ dmsetup info -c --noheadings -o major,minor control
+++ mapper_number=
+++ '[' 8:0 = '' ']'
+++ [[ sda =~ ^mapper/ ]]
++++ readlink /dev/sda
+++ my_dm=
+++ name=sda
+++ echo /dev/sda
+++ return 1
++ LogPrint 'Disk /dev/sda chosen as replacement for /dev/sda.'
++ Log 'Disk /dev/sda chosen as replacement for /dev/sda.'
+++ date '+%Y-%m-%d %H:%M:%S.%N '
++ local 'timestamp=2017-07-26 13:07:10.557339060 '
++ test 1 -gt 0
++ echo '2017-07-26 13:07:10.557339060 Disk /dev/sda chosen as replacement for /dev/sda.'
2017-07-26 13:07:10.557339060 Disk /dev/sda chosen as replacement for /dev/sda.
++ Print 'Disk /dev/sda chosen as replacement for /dev/sda.'
++ test 1
++ echo -e 'Disk /dev/sda chosen as replacement for /dev/sda.'
Disk /dev/sda chosen as replacement for /dev/sda.
++ add_mapping /dev/sda /dev/sda
++ echo '/dev/sda /dev/sda'
++ break
This is the disk mapping table:
    /dev/sda /dev/sda

FYI: Here the main 'set -x' output comes from the
evaluation of the fixed $(get_device_name $dev)
inside the 'select' clause (where $dev does not change)
so that this should have better been done before
and outside of the 'select' clause.

For comparison how it looks without '-D'

Comparing disks.
Device sda has size 26843545600, 21474836480 expected
Switching to manual disk layout configuration.
Original disk /dev/sda does not exist in the target system. Please choose an appropriate replacement.
1) /dev/sda
2) Do not map disk.
#? 1
2017-07-26 12:50:57.705512775 Disk /dev/sda chosen as replacement for /dev/sda.
Disk /dev/sda chosen as replacement for /dev/sda.
This is the disk mapping table:
    /dev/sda /dev/sda

Via https://github.com/rear/rear/pull/1391
I implemented using the original fds
for actually intended user input/output
in particular for whole 'select' clauses like

    select choice in WORDS ; do
        COMMANDS
    done 0<&6 1>&7 2>&8

so that nowadays '2>&8' is used.

Before the code had been like

    select choice in WORDS ; do
        COMMANDS
    done 2>&1

where '2>&1' was needed because the expanded WORDS are
printed on stderr which is by default redirected into the log file
so that '2>&1' was needed to get the intended user output
of the 'select' clause on the user's terminal but then
also 'set -x' debug output appears on the user's terminal.

Therefore for ReaR v2.3 as many as possible 'select' (and 'read')
commands should be replaced by the UserInput function
cf. https://github.com/rear/rear/issues/1399
and this would - by the way - also fix this issue here.

gdha commented at 2017-11-27 16:51:

@jsmeix is this issue not fixed in the meantime?

jsmeix commented at 2017-11-28 10:54:

It is fixed where I replaced 'select' by UserInput()
but not where I used

select select choice in ...
    ...
done 0<&6 1>&7 2>&8

or

read ... 0<&6 1>&7 2>&8

so that it is not yet fixed really everywhere.

But this is nothing that must be done for the ReaR 2.3 release
because it was this way all the time before so that there are
no regressions.

I move the milestone to ReaR 2.4. to fix the remaining cases
(as time provides).

FYI:
A quick search for 'select choice in' in the scripts found
verify/RBME/default/540_choose_backup.sh
and
verify/USB/NETFS/default/540_choose_backup_archive.sh
where in the latter I had already implemented
a special workaround some time ago via

{ set +x ; } 2>/dev/null
select choice in
    ...
done 0<&6 1>&7 2>&8
apply_bash_flags_and_options_commands "$DEFAULT_BASH_FLAGS_AND_OPTIONS_COMMANDS"

gdha commented at 2018-05-10 08:41:

@jsmeix I think this issue is as good fixed as it possible can be, no?

jsmeix commented at 2018-05-14 07:44:

@gdha
I think it is not yet fixed at all places where it can be fixed
so that the issue is still not sufficiently done
but there is nothing urgent here
so that I postpone it for the next ReaR 2.5
and I remove the "minor bug" because I think
nothing goes actually wrong as it is now.

jsmeix commented at 2019-02-26 10:02:

This issue can wait => postponing to "ReaR v2.6" milestone.

jsmeix commented at 2020-04-29 15:23:

This issue can wait even longer => postponing to "ReaR v2.7" milestone.

github-actions commented at 2020-07-01 01:33:

Stale issue message


[Export of Github issue for rear/rear.]