Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-01

more questions regarding linux signals

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

ik

Hello,

I have read "man 7 signal" in Linux, and there are few sections regarding safe and unsafe system calls to be used inside a signal handler.

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

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 ? 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 ?

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

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

Thanks,
Ido

Reply by email

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

SIGKILL is supposed to be the "last resort" of the system (or the user). If it would be possible for the app to react on SIGKILL it could do things which would delay the termination of the app. SIGKILL kills the process immediatly. Without excuses (like killing an application using the Windows task manager).

Regards,
Sven

Reply by email

Sven Barth
to Sven Barth
Sven Barth wrote 9 lines
Am 04.01.2012 14:14, schrieb ik: > Another question, is it possible to use exitproc if SIGKILL is sent, or > there is nothing I can do at all ? SIGKILL is supposed to be the "last resort" of the system (or the user). If it would be possible for the app to react on SIGKILL it could do things which would delay the termination of the app. SIGKILL kills the process immediatly. Without excuses (like killing an application using the Windows task manager).

Before I forget it: If you want to react on normal termination of the program you should hook SIGTERM.

Regards,
Sven

Reply by email

Jonas Maebe
to ik: I have read "man 7 signal" in Linux, and there are few sections regarding safe and unsafe…
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

Reply by email