This is the mail archive of the libc-alpha@sourceware.cygnus.com mailing list for the glibc project.


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

Re: [sbachman@saveware.com] libc/1534: When a program execl()'s in a signal function, the new program no longer responds to any


Roland McGrath <roland@frob.com> writes:

> your program conform to 1003.1-1996.  (Actually, if you ask me, you want to
> figure out what bonehead notion is leading to you thining you want to call
> exec in a signal handler and remove that bone from that head, but I don't
> think you asked me that.)

 Well one place I've seen this, which didn't seem such a bonehead
thing to do, is to re-exec the same process after a SIGSEGV/SIGBUS (so
you keep all the fd's open, and can try and act like nothing has
happened).

 Then again, I was pretty sure that SEGV wasn't blocked/blockable.
 Indeed, the following code counts to 4...

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

static int num = 0;

static void catch_sig(int dummy)
{
 ++num;

 printf("got num %d\n", num);
 fflush(NULL);

 if (num >= 4)
   exit (EXIT_FAILURE);

 *(char *)0 = 0;
}

int main(void)
{
 struct sigaction sa;

 if (sigemptyset(&sa.sa_mask) == -1)
   fprintf(stderr, "Error: %d\n", __LINE__);

 sa.sa_flags = SA_RESTART;
 sa.sa_handler = catch_sig;

 if (sigaction(SIGSEGV, &sa, NULL) == -1) 
   fprintf(stderr, "Error: %d\n", __LINE__);

 *(char *)0 = 0;

 exit (EXIT_SUCCESS);
}

-- 
James Antill -- james@and.org
I am always an optimist, but frankly there is no hope.
   -Hosni Mubarek

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