Re: unsafe functions from signal handler
- From: "bill pursell" <bill.pursell@xxxxxxxxx>
- Date: 26 Feb 2006 01:24:45 -0800
Kasper Dupont wrote:
bill pursell wrote:
It's not really a design at all! Just an academic question...I'm
just trying to see how it's done. Is siglongjmp safe to call from
the handler? It's not listed in signal(2) man page.
There is a difference between synchronous and asynchronous
signals. A lot of things is unsafe to do in an asynchronous
signal handler. However SIGSEGV is a synchronous signal
(unless some joker called kill(pid,SIGSEGV);).
Suppose I want to log (via syslog()) the receipt of a signal.
Is it any safer to long jump out of the handler to a block that
calls syslog() and then exit()s than it is to simply call
syslog() from the handler? ie, does the long jump give me
anything? It seems like it is not possible to safely log the
event.
To clarify, here's some code that does what I'm describing above.
I don't think it is reliable, as the output of strace for this
is nearly identical to the strace for the same code with the
syslog() being called from the handler. Is it possible to reliably
log the receipt of a signal? That seems like such a simple
task.
Also, the 3p man page for signal refers to "signal concepts" in the
body, and again in the "see also". What is that referring to?
-------------------with_jump.c-------------------
#include <setjmp.h>
#include <syslog.h>
#include <signal.h>
#include <stdlib.h>
jmp_buf env;
void
handle(int sig)
{
longjmp(env, sig);
}
int
main()
{
if (setjmp(env)) {
syslog(LOG_NOTICE,"some message");
exit(EXIT_FAILURE); /* should call _exit() */
}
signal(SIGSEGV, handle);
signal(SIGUSR1, handle);
pause();
}
.
- Follow-Ups:
- Re: unsafe functions from signal handler
- From: Paul Pluzhnikov
- Re: unsafe functions from signal handler
- References:
- Re: unsafe functions from signal handler
- From: bill pursell
- Re: unsafe functions from signal handler
- From: bill pursell
- Re: unsafe functions from signal handler
- From: bill pursell
- Re: unsafe functions from signal handler
- Prev by Date: Re: Trolltech QT license question
- Next by Date: strange behaviour of gcc 4.0.2
- Previous by thread: Re: unsafe functions from signal handler
- Next by thread: Re: unsafe functions from signal handler
- Index(es):
Relevant Pages
|