Re: unsafe functions from signal handler



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();
}

.



Relevant Pages

  • Re: Using SetConsoleCtrlHandler
    ... "bare minimum" principal should work even in multithreaded POSIX apps, ... you rely on recursive lock acqusition in your "signal handler" - hard to ... POSIX signals to POSIX processes". ... "Kernel mode APCs interrupt a thread and execute a procedure without ...
    (microsoft.public.win32.programmer.kernel)
  • Re: SetConsoleCtrlHandler
    ... This modified handler does not call ... signals. ... This allows the service to continue running after the user logs ... If the service installs its own console control handler, ...
    (microsoft.public.win32.programmer.kernel)
  • Re: pitfalls of signals
    ... If you have a signal handler that was invoked as a result of your program ... in that case you've invoked undefined behavior ... without invoking undefined behavior ... -Temporarily block a set of signals that includes the one the handler ...
    (comp.lang.c)
  • Re: Mars Rover Controlled By Java
    ... When handling signals Ada provides a higher level abstraction that ... -- Defines the interface for a signal handler ... task Responder is ... interrupt is handled only once. ...
    (comp.programming)
  • Re: Using SetConsoleCtrlHandler
    ... Assuming the signal handler does the minimum (ie. set a global, ... Only a single-threaded POSIX ... POSIX signals to POSIX processes". ... "Kernel mode APCs interrupt a thread and execute a procedure without the ...
    (microsoft.public.win32.programmer.kernel)