[m-rev.] For review: Re-throw unhandled signals.
Paul Bone
pbone at csse.unimelb.edu.au
Thu May 13 15:57:58 AEST 2010
For review by anyone.
Re-throw unhandled signals.
The Mercury runtime uses signal handlers to implement redzones and to provide
extra information in the case of a segmentation violation. However this
prevents Mercury programs from dumping core. It can also prevent the parent
process from knowing that the program was killed by a signal rather than exited
with exit status 1. This change re-throws signals that cannot be handled so
that the program can dump core and does this compatibly with the existing
signal handlers.
runtime/mercury_memory_handlers.c:
Use MR_reset_signal() and raise() to re-throw signals that we can't handle.
runtime/mercury_signal.h:
runtime/mercury_signal.c:
Create MR_reset_signal() that resets the handler for a signal back to the
default (SIG_DFL).
Index: runtime/mercury_memory_handlers.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_memory_handlers.c,v
retrieving revision 1.32
diff -u -p -b -r1.32 mercury_memory_handlers.c
--- runtime/mercury_memory_handlers.c 30 Oct 2007 00:46:22 -0000 1.32
+++ runtime/mercury_memory_handlers.c 13 May 2010 03:34:06 -0000
@@ -401,7 +401,8 @@ MR_explain_context(void *the_context)
MR_print_dump_stack();
MR_dump_prev_locations();
fprintf(stderr, "exiting from signal handler\n");
- exit(1);
+ MR_reset_signal(sig);
+ raise(sig);
} /* end complex_sighandler() */
#elif defined(MR_HAVE_SIGINFO_T)
@@ -480,7 +481,8 @@ complex_bushandler(int sig, siginfo_t *i
MR_print_dump_stack();
MR_dump_prev_locations();
fprintf(stderr, "exiting from signal handler\n");
- exit(1);
+ MR_reset_signal(sig);
+ raise(sig);
} /* end complex_bushandler() */
static void
@@ -557,7 +559,8 @@ complex_segvhandler(int sig, siginfo_t *
MR_print_dump_stack();
MR_dump_prev_locations();
fprintf(stderr, "exiting from signal handler\n");
- exit(1);
+ MR_reset_signal(sig);
+ raise(sig);
} /* end complex_segvhandler */
#else /* not MR_HAVE_SIGINFO_T && not MR_HAVE_SIGCONTEXT_STRUCT */
@@ -588,7 +591,8 @@ simple_sighandler(int sig)
MR_print_dump_stack();
MR_dump_prev_locations();
fprintf(stderr, "exiting from signal handler\n");
- exit(1);
+ MR_reset_signal(sig);
+ raise(sig);
}
#endif /* not MR_HAVE_SIGINFO_T && not MR_HAVE_SIGCONTEXT_STRUCT */
Index: runtime/mercury_signal.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_signal.c,v
retrieving revision 1.16
diff -u -p -b -r1.16 mercury_signal.c
--- runtime/mercury_signal.c 14 Nov 2006 00:15:41 -0000 1.16
+++ runtime/mercury_signal.c 13 May 2010 03:34:06 -0000
@@ -85,6 +85,26 @@ MR_do_setup_signal(int sig, MR_Code *han
}
void
+MR_reset_signal(int sig)
+{
+ MR_signal_action act;
+
+#ifdef MR_HAVE_SIGACTION
+ if (sigemptyset(&(act.sa_mask)) != 0) {
+ MR_perror("cannot set clear signal mask");
+ exit(1);
+ }
+ errno = 0;
+
+ act.sa_flags = 0;
+ act.sa_handler = SIG_DFL;
+#else
+ act = SIG_DFL;
+#endif
+ MR_set_signal_action(sig, &act, "Couldn't reset signal");
+}
+
+void
MR_init_signal_action(MR_signal_action *act, MR_Code *handler,
MR_bool need_info, MR_bool restart)
{
Index: runtime/mercury_signal.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_signal.h,v
retrieving revision 1.14
diff -u -p -b -r1.14 mercury_signal.h
--- runtime/mercury_signal.h 20 Jun 2005 02:16:44 -0000 1.14
+++ runtime/mercury_signal.h 13 May 2010 03:34:06 -0000
@@ -81,6 +81,11 @@ extern void MR_setup_signal_no_restart(i
MR_bool need_info, const char * error_message);
/*
+** Reset a signal to its default configuration.
+*/
+extern void MR_reset_signal(int sig);
+
+/*
** As above, but initialize a signal action suitable to be
** passed to MR_set_signal_action rather than setting a
** signal handler for a signal.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 489 bytes
Desc: Digital signature
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20100513/6a4d9fba/attachment.sig>
More information about the reviews
mailing list