#include #include #include /* jmp_buf context; */ sigjmp_buf context; int yog(int n) { char *p=NULL; printf("pass %d\n", n); if (n<=2) return 1; strcpy(p, "dfldflflmflkklfklflkmfdlfldfldlfdlkfd"); // must crash of course !!! return 1; } void resume(int sig) { /* longjmp(context, 6); */ siglongjmp(context, 6); //signal(SIGSEGV, resume); } int main(void) { int sig, i; char *x=NULL; sigset_t nset, oset; for (i=0; i<3; i++) { /* Remove SIGSEGV from the list of blocked signals if you use * setjmp/longjmp instead of sigsetjmp/siglongjmp. */ sigemptyset (&nset); sigaddset(&nset, SIGSEGV); sigprocmask (SIG_UNBLOCK, &nset, &oset); signal(SIGSEGV, resume); /* sig = setjmp(context);*/ sig = sigsetjmp(context, 1); if (sig == 0) { yog(1); yog(2); yog(3); //return 555; } else { fprintf(stderr, "ouch -- signal %d\n", sig); } } puts("end"); return 0; }