CVS commit by ossi: 

crash handler that launches gdb. activated when started with -D option.
simplifies debugging crashes during the reg-tests.


  M +37 -0     main.c   1.52


--- isync/src/main.c  #1.51:1.52
@@ -27,4 +27,7 @@
 #include <unistd.h>
 #include <string.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <sys/wait.h>
 
 int Pid;               /* for maildir and imap */
@@ -80,4 +83,32 @@ PACKAGE " " VERSION " - mailbox synchron
 }
 
+static void
+crashHandler( int n )
+{
+       int dpid;
+       char pbuf[10], pabuf[20];
+
+       close( 0 );
+       open( "/dev/tty", O_RDWR );
+       dup2( 0, 1 );
+       dup2( 0, 2 );
+       fprintf( stderr, "*** " EXE " caught signal %d. Starting debugger 
...\n", n );
+       switch ((dpid = fork ())) {
+       case -1:
+               perror( "fork()" );
+               break;
+       case 0:
+               sprintf( pbuf, "%d", Pid );
+               sprintf( pabuf, "/proc/%d/exe", Pid );
+               execlp( "gdb", "gdb", pabuf, pbuf, (char *)0 );
+               perror( "execlp()" );
+               _exit( 1 );
+       default:
+               waitpid( dpid, 0, 0 );
+               break;
+       }
+       exit( 3 );
+}
+
 static int
 matches( const char *t, const char *p )
@@ -386,4 +417,10 @@ main( int argc, char **argv )
        }
 
+       if (DFlags & DEBUG) {
+               signal( SIGSEGV, crashHandler );
+               signal( SIGBUS, crashHandler );
+               signal( SIGILL, crashHandler );
+       }
+
        if (merge_ops( cops, ops ))
                return 1;




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
isync-devel mailing list
isync-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/isync-devel

Reply via email to