www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/08/23/05:41:49

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <4a03a72c050823024012eb6fe7@mail.gmail.com>
Date: Tue, 23 Aug 2005 11:40:19 +0200
From: znort <stef DOT pellegrino AT gmail DOT com>
Reply-To: znort AT delorie DOT com
To: cygwin AT cygwin DOT com
Subject: signal trouble
Mime-Version: 1.0
X-IsSubscribed: yes
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id j7N9flfZ006893

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/


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019