Proper cleanup techniques (was Re: How to restore terminal ...)

Ken Weaverling weave at chopin.udel.edu
Tue Feb 19 14:36:34 AEST 1991


In article <1991Feb13.233750.13206 at athena.mit.edu> 
       jik at athena.mit.edu (Jonathan I. Kamens) writes:
>
>   Your program should keep track of when curses is activated and when it
>isn't.  It should then install signal handlers for all of the fatal signals,
>and when it gets such a signal, restore the tty modes, remove the signal
>handler, and send itself the signal again (to get a coredump, which you
>presumably want for debugging).

Gads, I hate to bring this subject back up, for fear of igniting another
100 message thread on "what can I call from a signal handler" but this
is a variation of that.

Above, you mention retoring tty modes, then sending a signal again. This
implies a system call or two within the signal handler.

So my question is: Is it safe to call a system function from a signal
handler IFF THE HANDLER NEVER DOES A RETURN and intends to exit() at the
end of the handler?  I presume so since even if function isn't re-entrant,
your first interrupted call isn't going to resume again.

I had been up to now doing a longjmp back to main() and then performing
cleanup from that level. However, if I trap a seg violation and want to
send the signal again to get a core dump, it is useless since I already
popped the stack to kingdom come!!!!
-- 
>>>---> Ken Weaverling  >>>---->  weave at brahms.udel.edu



More information about the Comp.unix.programmer mailing list