[fpc-pascal] more questions regarding linux signals

Jonas Maebe jonas.maebe at elis.ugent.be
Wed Jan 4 14:26:07 CET 2012


On 04 Jan 2012, at 14:14, ik wrote:

> As I understand (I hope I'm wrong), memory allocations inside a signal
> handler is unsafe. Is that true ?

Yes. The reason is that signals could be raised at any point during  
the execution, including e.g. while a heap manager routine was already  
being executed.

> Further-more, I wish to reload configuration under SIGHUP (it's a  
> daemon
> application). What is the safest way in your opinion to do so ?

The only safe way to do almost anything using a signal handler is to  
set a global variable in the handler and return, and in your program  
regularly check this global variable to see whether you have to do  
anything.

> For example let's say we have a configuration files regarding database
> access.
> How safe will it be to re-read the settings and close and reopen the
> connection on SIGHUP ?

About as unsafe as you can get.

> Another question, is it possible to use exitproc if SIGKILL is sent,  
> or
> there is nothing I can do at all ?

SIGKILL and SIGSTOP cannot be caught in any way.

> And last question for now, is there a more FPC way to handle such  
> issues ?

Unix signals are unix signals. There is no FPC wrapper over them.  
Adding one wouldn't help much, since as mentioned above you can do  
almost nothing from a signal handler.


Jonas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20120104/317db090/attachment.html>


More information about the fpc-pascal mailing list