This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

signal trouble


Could you tell/help me why the little code :

#include <signal.h>
#include <setjmp.h>
#include <stdio.h>

jmp_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);
   //signal(SIGSEGV, resume);

}

int main(void)
{
   int sig, i;
   char *x=NULL;

   for (i=0; i<3; i++)
   {
     signal(SIGSEGV, resume);

     sig = setjmp(context);

     if (sig == 0)
     {
       yog(1);
       yog(2);
       yog(3);
       //return 555;
     }
     else
     {
       fprintf(stderr, "ouch -- signal %d\n", sig);
     }
   }

   puts("end");
   return 0;

}

gives just :

pass 1
pass 2
pass 3
ouch -- signal 6
pass 1
pass 2
pass 3
Segmentation fault

and not

pass 1
pass 2
pass 3
ouch -- signal 6
pass 1
pass 2
pass 3
ouch -- signal 6
pass 1
pass 2
pass 3
ouch -- signal 6

Under cygwin gcc version 3.4.4 (cygming special) and Linux with gcc 3.3.5
same "strange" results... (no segmentation fault with cygwin anyway)

(notes : Under Solaris x86 (gcc3.4.4) it works perfectly !?)

I think I've forgotten something but where ? 

help me please

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]