How to not write a Signal Handler... by example
Published February 4th, 2005
Read some scary code in Asterisk today:
Quote from Asterisk:
static void huphandler(int num)
if (optionverbose > 1) printf(“Received HUP signal — Reloading configs\n”); if (restartnow) execvp(argv, _argv); /* XXX This could deadlock XXX */
- printf should not be used in a signal. handler.
- Calling execvp here is completely bogus. Signals can come at any time, and Asterisk is a multithreaded program. The signal will be handled by a random thread, and this will not do any cleanup of the resources used by asterisk.
Written by Paul Querna, CTO @ ScaleFT. @pquerna