For all you shell programmers out there, I ran across what I think is a bug in bash using traps. I wrote a script to trap signal 1 (SIGHUP) to make it behave like a daemon (reread a config file). If you trap exit, signal 0 AFTER trapping signal 1, the trap on signal 1 no longer works and the process is killed. For example, conf=~/daemon.conf tempfile=/tmp/DAEMON_$$ trap 'work=`cat $conf`' 1 trap 'rm -f $tempfile; exit' 0 15 Then, if you run the process and send signal 1, it dies. If you reverse the order of the trap statements... trap trap 'rm -f $tempfile; exit' 0 15 trap 'work=`cat $conf`' 1 Now, it works correctly, signal 1 is trapped and the process continues running. I originally posted this on comp.unix.shell and the bug was confirmed on Solaris and RH. It has since been posted to gnu.bash.bug and awaiting a reply. In the meantime, the work around seems to be to trap signal 0 first. Best Regards, Keith -- LPIC-2, MCSE, N+ I can C for miles and miles Got spam? Get SPASTIC http://spastic.sourceforge.net
[snip] Well, here is the answer from gnu.bash.bug...
I'm posting this from comp.unix.shell because a couple of us think it might represent a bug in bash'es 'trap' command.
Yes, it's a bug. It's already been fixed, and the fix will be in the next bash release. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ( ``Discere est Dolere'' -- chet) Chet Ramey, CWRU chet@po.CWRU.Edu http://cnswww.cns.cwru.edu/~chet/ So, use the work around if you use traps in your bash scripts. Best Regards, Keith -- LPIC-2, MCSE, N+ I can C for miles and miles Got spam? Get SPASTIC http://spastic.sourceforge.net
participants (1)
-
Keith Winston