Preserve message printed before abort.
authorUlrich Drepper <drepper@redhat.com>
Mon, 15 Jun 2009 23:17:09 +0000 (16:17 -0700)
committerUlrich Drepper <drepper@redhat.com>
Mon, 15 Jun 2009 23:17:09 +0000 (16:17 -0700)
The terminal output etc is not visible in a core file.  The new
libc-internal variable __abort_msg will point to a string with the
message which has been printed before the abort in case abort is
called from inside libc.  BZ #10217

ChangeLog
assert/assert-perr.c
assert/assert.c
include/stdlib.h
stdlib/Versions
stdlib/abort.c
sysdeps/posix/libc_fatal.c
sysdeps/unix/sysv/linux/libc_fatal.c

index 9e13cb7..6c97032 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2009-06-15  Ulrich Drepper  <drepper@redhat.com>
 
+       [BZ #10217]
+       * stdlib/abort.c: Define variable __abort_msg.
+       * stdlib/Versions: Export __abort_msg with GLIBC_PRIVATE version.
+       * include/stdlib.h: Declare __abort_msg.
+       * assert/assert-perr.c: Don't free buffer for message immediately.
+       Store atomically in __abort_msg and free old buffer if necessary.
+       * assert/assert.c: Likewise.
+       * sysdeps/posix/libc_fatal.c: Allocate buffer for message, copy it,
+       store pointer in __abort_msg, and possibly free old string.
+       * sysdeps/unix/sysv/linux/libc_fatal.c: Likewise.
+
        * time/tzfile.c (__tzfile_read): Correct computation of tzspec_len.
 
        [BZ #10211]
index dd54246..f239fab 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1994-1998,2001,2002,2005 Free Software Foundation, Inc.
+/* Copyright (C) 1994-1998,2001,2002,2005,2009 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -17,6 +17,7 @@
    02111-1307 USA.  */
 
 #include <assert.h>
+#include <atomic.h>
 #include <libintl.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -64,9 +65,10 @@ __assert_perror_fail (int errnum,
       (void) __fxprintf (NULL, "%s", buf);
       (void) fflush (stderr);
 
-      /* We have to free the buffer since the appplication might catch the
-        SIGABRT.  */
-      free (buf);
+      /* We have to free the old buffer since the application might
+        catch the SIGABRT signal.  */
+      char *old = atomic_exchange_acq (&__abort_msg, buf);
+      free (old);
     }
   else
     {
index 0ef4ca6..727fb14 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991,1994-1996,1998,2001,2002,2005
+/* Copyright (C) 1991,1994-1996,1998,2001,2002,2005,2009
    Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -18,6 +18,7 @@
    02111-1307 USA.  */
 
 #include <assert.h>
+#include <atomic.h>
 #include <libintl.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -43,6 +44,7 @@ extern const char *__progname;
 # include FATAL_PREPARE_INCLUDE
 #endif
 
+
 #undef __assert_fail
 void
 __assert_fail (const char *assertion, const char *file, unsigned int line,
@@ -64,9 +66,10 @@ __assert_fail (const char *assertion, const char *file, unsigned int line,
       (void) __fxprintf (NULL, "%s", buf);
       (void) fflush (stderr);
 
-      /* We have to free the buffer since the application might catch the
-        SIGABRT.  */
-      free (buf);
+      /* We have to free the old buffer since the application might
+        catch the SIGABRT signal.  */
+      char *old = atomic_exchange_acq (&__abort_msg, buf);
+      free (old);
     }
   else
     {
index 883bc34..d90e6ff 100644 (file)
@@ -221,6 +221,9 @@ extern int __qfcvt_r (long double __value, int __ndigit,
 extern void *__default_morecore (ptrdiff_t) __THROW;
 libc_hidden_proto (__default_morecore)
 
+extern char *__abort_msg;
+libc_hidden_proto (__abort_msg)
+
 __END_DECLS
 
 #undef __Need_M_And_C
index 93c68f6..3e7b892 100644 (file)
@@ -104,5 +104,7 @@ libc {
     # functions which have an additional interface since they are
     # are cancelable.
     __libc_system;
+    # Variable which needs a dynamic symbol table entry.
+    __abort_msg;
   }
 }
index 00788f2..3c188c9 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991,93,95,96,97,98,2001,02 Free Software Foundation, Inc.
+/* Copyright (C) 1991,93,1995-1998,2001,02,2009 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
 # define fflush(s) _IO_flush_all_lockp (0)
 #endif
 
+/* Exported variable to locate abort message in core files etc.  */
+char *__abort_msg __attribute__ ((nocommon));
+libc_hidden_def (__abort_msg)
+
 /* We must avoid to run in circles.  Therefore we remember how far we
    already got.  */
 static int stage;
index c611b84..4f11c0f 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1993,1994,1995,1997,2000,2004,2005
+/* Copyright (C) 1993-1995,1997,2000,2004,2005,2009
        Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -17,6 +17,7 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
+#include <atomic.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <paths.h>
@@ -123,6 +124,20 @@ __libc_message (int do_abort, const char *fmt, ...)
 
       if (TEMP_FAILURE_RETRY (__writev (fd, iov, nlist)) == total)
        written = true;
+
+      char *buf = do_abort ? malloc (total + 1) : NULL;
+      if (buf != NULL)
+       {
+         char *wp = buf;
+         for (int cnt = 0; cnt < nlist; ++cnt)
+           wp = mempcpy (wp, iov[cnt].iov_base, iov[cnt].iov_len);
+         *wp = '\0';
+
+         /* We have to free the old buffer since the application might
+            catch the SIGABRT signal.  */
+         char *old = atomic_exchange_acq (&__abort_msg, buf);
+         free (old);
+       }
     }
 
   va_end (ap);
index c7fac6a..7287f4e 100644 (file)
@@ -1,4 +1,5 @@
-/* Copyright (C) 1993-1995,1997,2000,2002-2005 Free Software Foundation, Inc.
+/* Copyright (C) 1993-1995,1997,2000,2002-2005,2009
+   Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -16,6 +17,7 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
+#include <atomic.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <paths.h>
@@ -131,6 +133,20 @@ __libc_message (int do_abort, const char *fmt, ...)
 
       if (cnt == total)
        written = true;
+
+      char *buf = do_abort ? malloc (total + 1) : NULL;
+      if (buf != NULL)
+       {
+         char *wp = buf;
+         for (int cnt = 0; cnt < nlist; ++cnt)
+           wp = mempcpy (wp, iov[cnt].iov_base, iov[cnt].iov_len);
+         *wp = '\0';
+
+         /* We have to free the old buffer since the application might
+            catch the SIGABRT signal.  */
+         char *old = atomic_exchange_acq (&__abort_msg, buf);
+         free (old);
+       }
     }
 
   va_end (ap);