about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--sysdeps/generic/segfault.c41
2 files changed, 39 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 3f17ed712f..febfcfdfaf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+1999-03-17  Ulrich Drepper  <drepper@cygnus.com>
+
+	* sysdeps/generic/segfault.c (write_strsignal): New function.
+	(catch_segfault): Use it instead of calling strsignal.
+
 1999-03-16  Andreas Jaeger  <aj@arthur.rhein-neckar.de>
 
 	* iconv/gconv.c (__gconv): Change type of last_start to unsigned
diff --git a/sysdeps/generic/segfault.c b/sysdeps/generic/segfault.c
index 848dae43dc..37c43c9208 100644
--- a/sysdeps/generic/segfault.c
+++ b/sysdeps/generic/segfault.c
@@ -22,6 +22,7 @@
 #include <execinfo.h>
 #include <fcntl.h>
 #include <signal.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -67,6 +68,10 @@ extern void *__libc_stack_end;
 # define ADVANCE_STACK_FRAME(next) ((struct layout *) (next))
 #endif
 
+/* We'll use tis a lot.  */
+#define WRITE_STRING(s) write (fd, s, strlen (s))
+
+
 struct layout
 {
   void *next;
@@ -74,6 +79,27 @@ struct layout
 };
 
 
+/* Name of the output file.  */
+static const char *fname;
+
+
+/* We better should not use `strerror' since it can call far too many
+   other functions which might fail.  Do it here ourselves.  */
+static void
+write_strsignal (int fd, int signal)
+{
+  if (signal < 0 || signal >= _NSIG || _sys_siglist[signal] == NULL)
+    {
+      char buf[30];
+      char *ptr = _itoa_word (signal, &buf[sizeof (buf)], 10, 0);
+      WRITE_STRING ("signal ");
+      write (fd, buf, &buf[sizeof (buf)] - ptr);
+    }
+  else
+    WRITE_STRING (_sys_siglist[signal]);
+}
+
+
 /* This function is called when a segmentation fault is caught.  The system
    is in an instable state now.  This means especially that malloc() might
    not work anymore.  */
@@ -83,28 +109,23 @@ catch_segfault (int signal, SIGCONTEXT ctx)
   struct layout *current;
   void *top_frame;
   void *top_stack;
-  const char *fname;
   int fd;
   void **arr;
   size_t cnt;
   struct sigaction sa;
-  const char *sigstring;
 
   /* This is the name of the file we are writing to.  If none is given
      or we cannot write to this file write to stderr.  */
   fd = 2;
-  fname = getenv ("SEGFAULT_OUTPUT_NAME");
-  if (fname != NULL && fname[0] != '\0')
+  if (fname != NULL)
     {
       fd = open (fname, O_TRUNC | O_WRONLY | O_CREAT, 0666);
       if (fd == -1)
 	fd = 2;
     }
 
-#define WRITE_STRING(s) write (fd, s, strlen (s))
   WRITE_STRING ("*** ");
-  sigstring = strsignal (signal);
-  WRITE_STRING (sigstring);
+  write_strsignal (fd, signal);
   WRITE_STRING ("\n");
 
 #ifdef REGISTER_DUMP
@@ -164,6 +185,7 @@ install_handler (void)
 {
   struct sigaction sa;
   const char *sigs = getenv ("SEGFAULT_SIGNALS");
+  const char *name;
 
   sa.sa_handler = (void *) catch_segfault;
   sigemptyset (&sa.sa_mask);
@@ -214,4 +236,9 @@ install_handler (void)
       INSTALL_FOR_SIG (SIGABRT, "abrt");
       INSTALL_FOR_SIG (SIGFPE, "fpe");
     }
+
+  /* Preserve the output file name if there is any given.  */
+  name = getenv ("SEGFAULT_OUTPUT_NAME");
+  if (name != NULL && name[0] != '\0')
+    fname = __strdup (name);
 }