bash: Readline + timeout

Programming languages, Coding, executables, and scripting.
Post Reply
Message
Author
linuxCowboy
Posts: 5
Joined: 2022-09-22 09:02

bash: Readline + timeout

#1 Post by linuxCowboy »

Lately I discovered a regression of one of my aliases:

Code: Select all

reads -t5
which is

Code: Select all

alias reads='read -sep enter'
It closes the tab or window!


Please test with bash in a terminal:

Code: Select all

read -et0
ret:1 okay

Code: Select all

read -et1
ret:142 + exit!

rbash or --norc --noprofile doesn't fix it.

Is it me or just another enhancement went south?

bash/testing,now 5.2~rc2-2 amd64 [installed]
libreadline8/testing,now 8.2~rc2-2 amd64 [installed]

User avatar
fabien
Posts: 139
Joined: 2019-12-03 12:51
Location: Toulouse, France
Has thanked: 9 times
Been thanked: 24 times

Re: bash: Readline + timeout

#2 Post by fabien »

linuxCowboy wrote: 2022-09-22 09:24 Lately I discovered a regression of one of my aliases:

Code: Select all

reads -t5
which is

Code: Select all

alias reads='read -sep enter'
It closes the tab or window!
One thing is unclear in what you describes. It seems you have identified an issue with timing (-t option), but your alias has no such timing option. Can you please clarify this?
linuxCowboy wrote: 2022-09-22 09:24Please test with bash in a terminal:

Code: Select all

read -et0
ret:1 okay

Code: Select all

read -et1
ret:142 + exit!
I think that exit code 142 is normal behaviour.
Based on What are Bash Exit Codes in Linux, 142 is 128+14 (128 + signal 14).
'man 7 signal' identify code 14 to SIGALRM and points to 'man 2 alarm':
alarm - set an alarm clock for delivery of a signal
[...]
alarm() arranges for a SIGALRM signal to be delivered to the calling process in seconds seconds.
If seconds is zero, any pending alarm is canceled.
[...]
sleep(3) may be implemented using SIGALRM
That is to say, if seconds is zero, pending alarm is canceled and Bash returns default error code 1 (because nothing is read), and it returns 128+SIGALRM code if seconds is more than zero and nothing is read.

I have tested (xterm, lxterminal, xfce4-terminal, even if this has certainly nothing to do with terminals): the error codes are the same as yours (which in my understanding is normal), but my terminals, as expected, don't exit. Regarding this unexpected exit, could you please post the output of:

Code: Select all

echo "$SHELLOPTS"
What is weird is that, if I understand well what you say, your terminal doesn't exit with signal 1 but exits when signal 142 occurs. Can you confirm this?

linuxCowboy
Posts: 5
Joined: 2022-09-22 09:02

Re: bash: Readline + timeout

#3 Post by linuxCowboy »

fabien wrote: 2022-09-22 15:30
linuxCowboy wrote: 2022-09-22 09:24 Lately I discovered a regression of one of my aliases:

Code: Select all

reads -t5
which is

Code: Select all

alias reads='read -sep enter'
It closes the tab or window!
One thing is unclear in what you describes. It seems you have identified an issue with timing (-t option), but your alias has no such timing option. Can you please clarify this?
This is on purpose. So I get a wait in a lengthy script, but sometimes add a timeout with -t.
I have tested (xterm, lxterminal, xfce4-terminal, even if this has certainly nothing to do with terminals)
Thanks. Return value 1 and 142 are okay. SHELLOPTS and BASHOPTS are okay.

My Preliminary status is - its bash.

bash 5.2.0(1)-alpha is the culprit. I thought at first libreadline8, but bash his own version off it.

You can load bash-5.2-alpha.tar.gz, or use it in git tag: bash-5.2-alpha

But thats a huge commit! The CHANGES file has 10,000+ lines.

User avatar
fabien
Posts: 139
Joined: 2019-12-03 12:51
Location: Toulouse, France
Has thanked: 9 times
Been thanked: 24 times

Re: bash: Readline + timeout

#4 Post by fabien »

I overlooked your Bash version. I tested with testing, still no problem.

Code: Select all

$> read -t0 || echo "$?" ; read -t1 || echo "$?" ; echo -e "\n$BASHOPTS\n\n$SHELLOPTS\n\n$BASH_VERSION" ; cat /etc/debian_version ; uname -a
1
142

checkwinsize:cmdhist:complete_fullquote:expand_aliases:extglob:extquote:force_fignore:globasciiranges:globskipdots:interactive_comments:login_shell:patsub_replacement:progcomp:promptvars:sourcepath

braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor

5.2.0(1)-rc2
bookworm/sid
Linux virtdeb9 5.19.0-1-amd64 #1 SMP PREEMPT_DYNAMIC Debian 5.19.6-1 (2022-09-01) x86_64 GNU/Linux
What we can say for sure is that testing is for testing and alpha is... alpha.

linuxCowboy
Posts: 5
Joined: 2022-09-22 09:02

Re: bash: Readline + timeout

#5 Post by linuxCowboy »

You're right, it's testing.

And a case for git bisect!

The culprit is:

Code: Select all

commit 2fe2e8197eb8f05c22a23b9d1e115d74febc8325
Author: Chet Ramey <chet.ramey@case.edu>
Date:   Thu Mar 11 18:41:17 2021 -0500

    application-settable readline timeouts
The error-test is

Code: Select all

$ echo $SHLVL
1

$ ./bash
$ read -et1
$ echo $SHLVL
1  # error: 1  okay: 2

User avatar
fabien
Posts: 139
Joined: 2019-12-03 12:51
Location: Toulouse, France
Has thanked: 9 times
Been thanked: 24 times

Re: bash: Readline + timeout

#6 Post by fabien »

See https://mail.gnu.org/archive/html/bug-b ... 00129.html
This document details the changes between this version, bash-5.2-beta, and
the previous version, bash-5.2-alpha.
[...]
1. Changes to Bash
[...]
e. Fixed an issue with read timeouts in posix mode.

This document details the changes between this version, bash-5.2-alpha, and
the previous version, bash-5.1-release.
[...]
3. New Features in Bash
[...]
b. There is a new internal timer framework used for read builtin timeouts.
[...]
4. New Features in Readline
[...]
c. There is a new framework for readline timeouts, including new public
functions to set timeouts and query how much time is remaining before a
timeout hits, and a hook function that can trigger when readline times
out. There is a new state value to indicate a timeout.
So do you confirm that Bash 5.2.0(1)-rc2 solved your issue?

Post Reply