On Tue, Aug 08, 2000 at 04:41:46PM +0200, Nicolas Leonard wrote:
> Sorry, I wasn't precise enough .
> 
> In fact, I caught the SIGABRT signal (and the others signals which are
> ending the program)
> and I'm doing some ending stuff, and after that, I would like to dump a core
> file.
> 
> I could remove the handler of SIGABRT after my ending suff done, and kill
> myself another
> time, but I would like to know if it's possible to dump the core explicitly.
> (With a dumpcore()
> function or whatever )
> 

There's no need to remove the handler for SIGABRT, unless you exit
normally inside the handler.  If you would like to handle SIGABRT, and
you also want abort() to terminate the process and cause it to generate
a core file, just remove any calls to exit() inside the handler.  After
your handler returns, the process will abort and dump core.  If you use
the same handler for all signals, you can conditionally exit based on
the signal number.

This example (handler.c) illustrates:


#include <stdio.h>
#include <signal.h>
#include <sys/cdefs.h>

void     sig_handler __P((int));

int
main(argc, argv)
        int      argc;
        char    *argv[];
{
        sig_t    handler;

        handler = signal(SIGABRT, sig_handler);

        printf("Calling abort() ...\n");
        abort();

        printf("NOTREACHED\n");

        return 0;
}


void
sig_handler(sig)
        int      sig;
{
        printf("Caught signal %d\n", sig);

        /*
        exit(0);
         */

        return;
}



Note from the backtrace (included below the program output) that the
program dies at line 17.  This is in the kill() function (as called from
abort(), which never returns), but after the handler has returned (as
can be seen by the output).

[beastie:/home/brian]% cc -g handler.c -o handler

[beastie:/home/brian]% ./handler
Calling abort() ...
Caught signal 6
zsh: 97734 abort (core dumped)  ./handler

[beastie:/home/brian]% gdb handler handler.core
<snip>
(gdb) bt
#0  0x28094c78 in kill () from /usr/lib/libc.so.3
#1  0x280c8e57 in abort () from /usr/lib/libc.so.3
#2  0x80484a8 in main (argc=1, argv=0xbfbfd6ec) at handler.c:17
#3  0x8048419 in _start ()

-brian

-- 
Brian O'Shea
[EMAIL PROTECTED]


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to