Home > Archive > Unix Programming > July 2007 > Question about core dump and signal handling.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Question about core dump and signal handling.
|
|
| Krivenok Dmitry 2007-07-12, 8:06 am |
| Hello!
I've registered signal handler for all of synchronous signals
(SIGSEGV, SIGFPE, SIGILL,etc).
It calls "async-signal safe" function sem_post.
My main thread is blocked in sem_wait call.
As soon as signal is delivered, main thread wakes up,
prints a message in a log file and then exits.
The problem is that when I handle SIGSEGV signal, core file
is NOT dumped.
However, I want to handle SIGSEGV to print a message in
the log file and I also want get core dump.
Is there a way to force core dumping regardless of whether
SIGSEGV signal is handled or not.
Thank you beforehand!
P.S.
develop ~ # uname -a
Linux develop 2.6.14-gentoo-r2 #1 SMP PREEMPT Wed Mar 21 18:43:52 MSK
2007 i686 Intel(R) Pentium(R) 4 CPU 2.80GHz GenuineIntel GNU/Linux
develop ~ # ulimit -c
unlimited
develop ~ #
| |
|
|
| William Pursell 2007-07-14, 7:06 pm |
| On Jul 12, 1:01 pm, Krivenok Dmitry <krivenok.dmi...@gmail.com> wrote:
>
> The problem is that when I handle SIGSEGV signal, core file
> is NOT dumped.
>
> However, I want to handle SIGSEGV to print a message in
> the log file and I also want get core dump.
>
> Is there a way to force core dumping regardless of whether
> SIGSEGV signal is handled or not.
#define _GNU_SOURCE /* for error() */
#include <errno.h>
#include <error.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
void check_args( char **argv );
int log_fd;
void
handle_segv( int sig )
{
char msg[]="Caught SIGSEGV\n";
/* Ignore errors */
write( log_fd, msg, sizeof msg );
close( log_fd );
raise( SIGSEGV );
}
void
set_signal_disposition( void )
{
struct sigaction sa;
sa.sa_handler = handle_segv;
/*
* Set SA_RESETHAND so that the signal handler
* can re-raise the signal and get the default
* action. (core dump)
*/
sa.sa_flags = SA_RESETHAND;
sigemptyset( &sa.sa_mask );
sigaction( SIGSEGV, &sa, NULL );
}
int
main( int argc, char **argv )
{
check_args( argv );
set_signal_disposition();
raise( SIGSEGV );
return 0;
}
void
check_args( char **argv )
{
char *filename = argv[ 1 ];
if( filename == NULL ) {
fprintf( stderr, "usage: %s logfile\n",
argv[ 0 ]);
exit( EXIT_FAILURE );
}
log_fd = open( filename, O_WRONLY | O_CREAT, 0777 );
if( log_fd == -1 )
error( EXIT_FAILURE, errno, filename );
}
|
|
|
|
|