Mailinglist Archive: opensuse (3378 mails)
| < Previous | Next > |
FYI: possible bug in bash using traps
- From: Keith Winston <kwinston@xxxxxxxxxxx>
- Date: Tue, 16 Apr 2002 11:07:13 -0400
- Message-id: <20020416110713.A4676@xxxxxxxxxxxxxxxxxxxx>
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
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
| < Previous | Next > |