1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-30 22:43:12 +03:00

Preserve message printed before abort.

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
This commit is contained in:
Ulrich Drepper
2009-06-15 16:17:09 -07:00
parent 6355c99740
commit 48dcd0ba84
8 changed files with 67 additions and 11 deletions

View 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);