Not returning a function in a signal handler?

consider a signal handler that calls exit () as the last command: is it safe to call non-reentor functions (for example, free ()) in this handler?

IMHO this would be legal due to the fact that the handler does not return to the normal sequence of execution.

Thanks in advance.

+4
source share
3 answers

No, it is illegal, moreover, there are very few safe functions to call.

There is a list of safe functions to call, see http://linux.die.net/man/2/signal .

+5
source

You must distinguish between two signals: those that tell the daemons to "reload" and those that complete the daemon ("kill"). In the case of "kill" you do not need to let go of anything. Your process will die, the OS will clear everything that you allocated. If you use shared memory, you must perform a cleanup on restart. Do not do anything in the kill handler, which can cause problems. Just die.

In the event of a reboot, you can call any function that you like, as the user wants you to "close orderly." In this case, there is little chance that you will get the same signal again (so it doesn’t matter if the function is reentrant or not).

+1
source

Reentrancy is more connected with the "entry" into the function, and the side effects and state supported by the specified function than the exit ...

You can refer to this manual page .

0
source

All Articles