mainThe GNU Bourne-Again SHell - Support: sr #110760, `read` in a PROMPT_COMMAND...

 
 

sr #110760: `read` in a PROMPT_COMMAND disables TMOUT

Submitter:  None
Submitted:  Sat 29 Oct 2022 06:10:44 PM UTC
   
 
Category:  None Priority:  5 - Normal
Severity:  3 - Normal Status:  Works For Me
Privacy:  Public Assigned to:  None
Originator Email:  -email is unavailable- Open/Closed:  Open
Operating System:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 31 Oct 2022 08:32:56 PM UTC, comment #2: 

Thank you for that explanation, much appreciated!

Anonymous
Mon 31 Oct 2022 07:34:35 PM UTC, comment #1: 

TMOUT, if set, is also the default timeout for the `read' builtin. In bash-5.1, both are implemented using alarm(3).

You can only have one alarm at a time, so the one set by the
read builtin in $PROMPT_COMMAND supersedes the one used for
the idle timeout.

Bash-5.2 uses a different framework for read builtin timeouts,
so this will work on systems that have a working select(2),
but it's not going to work in previous versions.

Chet Ramey <chet>
Group administrator
Sat 29 Oct 2022 06:10:44 PM UTC, original submission:  

Hi, I've been experiencing an issue on a system where a readonly TMOUT value is set in some /etc/profile.d/ file to force a logout of idle shells after 30 minutes.  I noticed that once I got my custom git bash prompt set up, my bash could stay logged in forever, so TMOUT was apparently being ignored.  I narrowed this down to the fact that I had a PROMPT_COMMAND that called the read builtin.  After modifying the custom prompt to use readarray or eval in place of read, the TMOUT automatic logout was working again.

The system I'm encountering this issue is ubuntu focal, which has bash 5.0 on it (iirc). I set up in a docker container using the ubuntu:latest image (which is jammy), and could reproduce the issue there:


testuser@8d499682ebfc:/$ bash --version | head -n1
GNU bash, version 5.1.16(1)-release (aarch64-unknown-linux-gnu)
testuser@8d499682ebfc:/$ cat /etc/profile.d/tmout.sh
TMOUT=60
readonly TMOUT
export TMOUT
testuser@8d499682ebfc:/$ cd /tmp
testuser@8d499682ebfc:/tmp$ echo $TMOUT
60
testuser@8d499682ebfc:/tmp$ unset TMOUT
bash: unset: TMOUT: cannot unset: readonly variable
testuser@8d499682ebfc:/tmp$ PROMPT_COMMAND='read -r XYZ <<< "xyz"; echo "XYZ=$XYZ"'
XYZ=xyz
testuser@8d499682ebfc:/tmp$
# remain logged in after 60 seconds
testuser@8d499682ebfc:/$ unset PROMPT_COMMAND
# and after after 60 seconds...
timed out waiting for input: auto-logout


Is this behavior correct?  One example of a git prompt script that uses 'read' is git-prompt.sh packaged with git itself, so I think including 'read' in a PROMPT_COMMAND should not have this side effect of preventing TMOUT auto-logout.

Thanks!

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by chet (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-10-31 chet StatusNone Works For Me

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code