[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Odd behaviour when running exec inside a signal handler
From: |
Greg Wooledge |
Subject: |
Re: Odd behaviour when running exec inside a signal handler |
Date: |
Mon, 26 Jul 2010 08:16:51 -0400 |
User-agent: |
Mutt/1.4.2.3i |
On Sun, Jul 25, 2010 at 04:54:53PM -0400, Chet Ramey wrote:
> On 7/25/10 8:51 AM, Julien Dessaux wrote:
> > I have a script that trap USR1 for reloading purpose. The signal handler
> > then does some cleaning, then exec $0.
>
> With BSD and Posix-style signals, the caught signal is automatically
> blocked by the kernel when executing its signal handler. If you exec
> a new program out of the signal handler, it's going to be executed
> with that signal blocked. From the new program's perspective, it really
> is as if you never left the signal handler.
I believe the typical workaround for this type of issue is to set a
variable in the signal handler, and then (outside the trap, in some sort
of main loop) check for that variable and do the real handling.
I've never developed a bash script that needed that sort of sophistication,
but that's how it's generally done in C.