bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bash trap ignore signal - race condition


From: Roman Rakus
Subject: bash trap ignore signal - race condition
Date: Tue, 12 Apr 2011 14:33:50 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Lightning/1.0b3pre Thunderbird/3.1.7

There's a race condition when you can hit following:
      set_signal_handler (sig, SIG_IGN);
      change_signal (sig, savestring (string));
      set_signal_handler (sig, trap_handler);
in trap.c file, set_signal() function.
So bash set signal to be ignored and then set it to be handled by trap_handler. However how should bash behave when the signal is received when the trap_handler has been set before. Check the following reproducer:

#!/bin/bash

cat>  traploop.sh<<EOF
while true; do
    trap exit SIGUSR1;
done
EOF

chmod a+x traploop.sh

i=0
while true; do
    ./traploop.sh&
    sleep 1
    echo "Sending SIGUSR1 to $!"
    kill -SIGUSR1 $!
    wait $!
    echo "No. $i: OK"
    i=$((i+1))
done


You can send SIGUSR1 to bash running traploop.sh in the state, when the signal is ignored, but shouldn't be. Is there any reason why is the signal for short time ignored?

RR



reply via email to

[Prev in Thread] Current Thread [Next in Thread]