Hi, I found a very odd behaviour in bash. It's about a problem I encounter when I do a exec from the inside of a signal handler. I can reproduce 100% sure on my bash 4.0.35 on OpenBSD, and on a bash 4.1.7 on archlinux, and people on #bash seem to agree with me.
I have a script that trap USR1 for reloading purpose. The signal handler then does some cleaning, then exec $0. The script then reloads itself and rearm the signal. The problem is that the script will never be able to catch a USR1 signal again, that's really just as if bash believes we never got out of the previous handler. I tried to de-init the trap before exec, did nothing. It also appens with various signals. I attached an exemple program that trigers the bug. When you run it it sets trap for USR1 and USR2. If you kill it with USR1 it reloads itself threw exec, and you won't be able to trap it anymore in the new process. If you kill this new process with USR2, the script reloads itself (again), and now you are no longer able to trap USR1 or USR2. For my own use I managed to work around it : in the signal handler I set a trap for SIG_EXIT to 'exec $0', then I exit... This way it behave as I expect, but I find that kinda ugly! Do you have any clue about what looks like a bug? Thanks in advance, -- Julien Dessaux
test.sh
Description: Bourne shell script