Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase USER_INPUT_INTERRUPT_TIMEOUT default from 10 to 30 seconds #2981

Merged
merged 2 commits into from
May 8, 2023

Conversation

jsmeix
Copy link
Member

@jsmeix jsmeix commented May 5, 2023

  • Type: Enhancement

  • Impact: Normal

  • How was this pull request tested?

In current GitHub master code since DISKS_TO_BE_WIPED="" cf.
#2859
there is in layout/recreate/default/120_confirm_wipedisk_disks.sh
a UserInput() dialog like

Disks to be wiped: /dev/sda /dev/sdb /dev/sdd
...
Confirm disks to be wiped and continue 'rear recover'

which has usually (i.e. when not in MIGRATION_MODE)
a timeout of USER_INPUT_INTERRUPT_TIMEOUT.

During my tests with current GitHub master code
I learned that 10 seconds is far too little time
to read and understand that UserInput message and
then some more time to make a decision whether or not
the automated action is actually the right one.

I.e. 10 seconds was far too little time even for me
where I expected that UserInput dialog but even I
could not actually comprehend what disks will be wiped
and I could not at all make a decision whether or not
those are the right disks.

So the same applies to any UserInput dialog
(in prticular to any unexpected UserInput dialog)
where USER_INPUT_INTERRUPT_TIMEOUT is used
i.e. any UserInput() dialog with a predefined input.

In general a default timeout is useless when it is too short
to let the user understand what is going on and let him
make a decision so in practice such a too short timeout
behaves very user unfiendly.

  • Brief description of the changes in this pull request:

In default.conf increased the default USER_INPUT_INTERRUPT_TIMEOUT
from 10 seconds to 30 seconds because 10 seconds is far too little time
to read and understand a possibly unexpected UserInput() message
and then some more time to make a decision whether or not
the automated action is actually the right one.

In default.conf incresed the default USER_INPUT_INTERRUPT_TIMEOUT
from 10 seconds to 30 seconds because 10 seconds is far too little time
to read and understand the possibly unexpected UserInput() message
and then some more time to make a decision whether or not
the automated action is actually the right one.
@jsmeix jsmeix added the enhancement Adaptions and new features label May 5, 2023
@jsmeix jsmeix added this to the ReaR v2.8 milestone May 5, 2023
@jsmeix jsmeix self-assigned this May 5, 2023
@jsmeix jsmeix requested review from schlomo and a team and removed request for schlomo May 5, 2023 13:42
Copy link
Member

@schlomo schlomo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good change.
In general I feel that we don't need to explain how export works for every variable that can be set from the outside.

If we use the :- syntax consistently then it becomes very simple to quickly check for such variables via grep:

$ grep :- usr/share/rear/conf/default.conf 
KERNEL_VERSION="${KERNEL_VERSION:-$( uname -r )}"
GALAXY11_BACKUPSET=${GALAXY11_BACKUPSET:-}
GALAXY11_PIT_RECOVERY=${GALAXY11_PIT_RECOVERY:-}
GALAXY11_USER=${GALAXY11_USER:-}
GALAXY11_PASSWORD=${GALAXY11_PASSWORD:-}

Whereas grepping for test yields way too many false positives.

usr/share/rear/conf/default.conf Outdated Show resolved Hide resolved
usr/share/rear/conf/default.conf Outdated Show resolved Hide resolved
In default.conf use VAR="${VAR:-default value}" instead of
test "$VAR"|| VAR="default value"
because 'grep' for ':-' works better to find those assignments
in contrast to 'grep' for 'test' that also shows many false positives
see #2981
Furthermore regarding why we do not use
: "${VAR:=default value}"
see https://stackoverflow.com/questions/4437573/bash-assign-default-value
i.e. VAR="${VAR:-default value}" is found by 'grep' for 'VAR=' and
with 'set -x' it shows VAR='default value' (instead of : 'default value')
which makes this code easier to understand, debug and maintain,
cf. https://github.com/rear/rear/wiki/Coding-Style
@jsmeix
Copy link
Member Author

jsmeix commented May 8, 2023

@schlomo
thank you for your review.
I fully agree with your above comment
#2981 (review)

Additionlly
https://stackoverflow.com/questions/4437573/bash-assign-default-value
explains why

VAR="${VAR:-default value}"

is better in practice than

: "${VAR:=default value}"

cf. my comment in
a436ad5
excerpt:

VAR="${VAR:-default value}" is found by 'grep' for 'VAR=' and
with 'set -x' it shows VAR='default value' (instead of : 'default value')
which makes this code easier to understand, debug and maintain,
cf. https://github.com/rear/rear/wiki/Coding-Style

@jsmeix
Copy link
Member Author

jsmeix commented May 8, 2023

I am wondering why we use

VAR="${VAR:-default value}"

and not

VAR="${VAR-default value}"

i.e. why we assign 'defult value' via :-
if VAR is unset or null (i.e. unset or empty)
instead of assigning 'defult value' via -
only if VAR is unset?

In the former case the user cannot set an empty value via

export VAR=""

which he could do (if needed) in the latter case.

As far as I see this does not matter with the current
config variables that are set this way because
for none of those which get a non-empty default set
it makes sense for the user to set them to be empty.

So my question is currently only out of curiosity.

@jsmeix
Copy link
Member Author

jsmeix commented May 8, 2023

I have another question:

What is "the best" way to assign a string of words
via bash parameter expansion?

Currenly I use an unquoted string

VAR="${VAR:-default value}"

in

USER_INPUT_PROMPT="${USER_INPUT_PROMPT:-enter your input}"

because we do it this way already in
rear/output/RAWDISK/Linux-i386/280_create_bootable_disk_image.sh

"${RAWDISK_GPT_PARTITION_NAME:-Rescue System}"
${RAWDISK_BOOT_SYSLINUX_START_INFORMATION:-Starting the rescue system...}

and
rear/output/RAWDISK/Linux-i386/270_create_grub2_efi_bootloader.sh

"${RAWDISK_BOOT_GRUB_MENUENTRY_TITLE:-Recovery System}"

Alternatively

VAR="${VAR:-"default value"}"

would work but the nested double quotes look confusing.
In contrast single quotes like

VAR="${VAR:-'default value'}"

do not work because (at least with bash version 4.4.23)

# unset VAR

# VAR="${VAR:-'default value'}"

# declare -p VAR
declare -- VAR="'default value'"

the single quotes become part of the assigned value.

@schlomo
Copy link
Member

schlomo commented May 8, 2023

@jsmeix the examples in
https://tldp.org/LDP/abs/html/parameter-substitution.html#:~:text=variable%3D%0A%23%20variable%20has%20been%20declared%2C%20but%20is%20set%20to%20null.%0A%0Aecho%20%22%24%7Bvariable%2D0%7D%22%20%20%20%20%23%20(no%20output)%0Aecho%20%22%24%7Bvariable%3A%2D1%7D%22%20%20%20%23%201%0A%23%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5E
led me (long long time ago and now again) to always use :- syntax as it also handles null set variables.

What is bad with VAR="${VAR:-default value}" if it works as expected?
Even VAR=${VAR:-default value} works the same.

I don't see a need to change anything from our current use of this parameter substitution and it seems to me that there is no need for inner quotes around multi word default values either.

@schlomo schlomo merged commit 6f5e049 into master May 8, 2023
16 checks passed
@schlomo schlomo deleted the jsmeix-USER_INPUT_INTERRUPT_TIMEOUT-30 branch May 8, 2023 08:27
@jsmeix
Copy link
Member Author

jsmeix commented May 8, 2023

By the way regarding ${VAR-value}:

As far as I found we have only one case where this is used:
rear/lib/layout-functions.sh

function get_device_from_partition() {
    ...
    partition_number=${2-$(get_partition_number $partition_block_device )}

It seems to be allowed to call get_device_from_partition
with an empty second argument?

get_device_from_partition is only called in
finalize/Linux-i386/670_run_efibootmgr.sh

@pcahyna
as far as I see from
git log --follow -p usr/share/rear/lib/layout-functions.sh
this ${VAR-value} parameter expansion is from you in
fae98be
that belongs to
#2608
which has very many comments.
Do you perhaps remember why not ${VAR:-value} is used in this case?

@schlomo
Copy link
Member

schlomo commented May 8, 2023

No memories, most likely I did it wrong. Off the top of my head I'm not aware of any reason to use VAR-value instead of VAR:-value

Personally, I also find :- easier to read and notice

@jsmeix
Copy link
Member Author

jsmeix commented May 8, 2023

@schlomo I guess you are not @pcahyna :-)

@schlomo
Copy link
Member

schlomo commented May 8, 2023

Ah yes, that would explain my lack of memory. Well spotted 😄

jsmeix added a commit that referenced this pull request May 8, 2023
In default.conf use the VAR="${VAR:-default value}" form also for
{ BACKUP_PROG_CRYPT_KEY="${BACKUP_PROG_CRYPT_KEY:-}" ; } 2>/dev/null
see #2981 (comment)
and explain why the confidential way via { confidential_command ; } 2>/dev/null
is also used in default.conf (as template how to do it properly in etc/rear/local.conf)
cf. #2967 (comment)
@jsmeix
Copy link
Member Author

jsmeix commented May 8, 2023

I did
ad5cac2
as addednum to this (already merged) pull request.

@jsmeix
Copy link
Member Author

jsmeix commented May 8, 2023

Oh - right now I found in default.conf

OPAL_PBA_DEBUG_PASSWORD=''

@jsmeix
Copy link
Member Author

jsmeix commented May 9, 2023

I will do a new pull request to clean up in default.conf
all cases of config variables for confidential values
i.e. have a generic explanation comment at the beginning
instead of several similar comments at each place:
#2982

@jsmeix jsmeix mentioned this pull request May 9, 2023
jsmeix added a commit that referenced this pull request Nov 8, 2023
In layout/recreate/default/120_confirm_wipedisk_disks.sh
fixed comment about the USER_INPUT_INTERRUPT_TIMEOUT default
because since #2981
USER_INPUT_INTERRUPT_TIMEOUT is by default 30 seconds
jsmeix added a commit that referenced this pull request Nov 8, 2023
In layout/prepare/Linux-s390/370_confirm_dasd_format_code.sh
fixed comment about the USER_INPUT_INTERRUPT_TIMEOUT default
because since #2981
USER_INPUT_INTERRUPT_TIMEOUT is by default 30 seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Adaptions and new features fixed / solved / done
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants