helpThe GNU Bourne-Again SHell - Support: sr #109608, Read timeout in trap of a read...

 
 

sr #109608: Read timeout in trap of a read with a timeout leads to stuck script

Submitted by:  None
Submitted on:  Wed 26 Dec 2018 08:17:15 AM UTC  
 
Category:  None Priority:  5 - Normal
Severity:  2 - Minor Status:  Done
Privacy:  Public Assigned to:  None
Originator Email:  -email is unavailable- Open/Closed:  Open
Operating System:  GNU/Linux

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Wed 26 Dec 2018 03:53:28 PM UTC, comment #1: 

Bash uses real-time interval timers to implement read timeouts (the ones that deliver SIGALRM when they expire). A process can only have one itimer at a time; the one started by the trap command overwrites the previous one.

Chet Ramey <chet>
Project Administrator
Wed 26 Dec 2018 08:17:15 AM UTC, original submission:  

GNU bash, version 4.4.19(1)-release (x86_64-pc-linux-gnu)

When reading with a timeout in a trap that is trapping a read  with a timeout, the original read never times out.

The following script will reproduce the behavior.

#!/bin/bash
trap_int()
{
    read -t2 -ru ${fd} line
    echo $line
}

msg_trap()
{
    echo trapped
}

trap 'echo terminated; exit 2' SIGTERM
trap 'trap_int' SIGINT

exec {fd}< <(msg_trap)
read  -t10 line

echo "res $?line: $line"

./test
^Ctrapped

The script never ends, the read in the main function will no longer time out.
The bug can be worked around by doing a read -t0 first in the trap.
When the read in the trap function has no time out it also works.

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)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

     

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-12-26 chet StatusNone => Done

    Back to the top


    Powered by Savane 3.5