2013-03-20 00:07:15 +00:00
|
|
|
/* Catastrophic failure reports. Generic POSIX.1 version.
|
2019-01-01 00:11:28 +00:00
|
|
|
Copyright (C) 1993-2019 Free Software Foundation, Inc.
|
1997-05-26 23:01:17 +00:00
|
|
|
This file is part of the GNU C Library.
|
1995-02-18 01:27:10 +00:00
|
|
|
|
1997-05-26 23:01:17 +00:00
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 04:58:11 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
1995-02-18 01:27:10 +00:00
|
|
|
|
1997-05-26 23:01:17 +00:00
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2001-07-06 04:58:11 +00:00
|
|
|
Lesser General Public License for more details.
|
1995-02-18 01:27:10 +00:00
|
|
|
|
2001-07-06 04:58:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-09 23:18:22 +00:00
|
|
|
License along with the GNU C Library; if not, see
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
1995-02-18 01:27:10 +00:00
|
|
|
|
2009-06-15 23:17:09 +00:00
|
|
|
#include <atomic.h>
|
2004-11-13 03:09:30 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2011-05-15 04:34:48 +00:00
|
|
|
#include <ldsodefs.h>
|
2004-11-13 03:09:30 +00:00
|
|
|
#include <paths.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdbool.h>
|
1995-02-18 01:27:10 +00:00
|
|
|
#include <stdio.h>
|
2000-04-22 07:19:25 +00:00
|
|
|
#include <stdlib.h>
|
1996-06-23 01:31:00 +00:00
|
|
|
#include <string.h>
|
2004-11-13 03:09:30 +00:00
|
|
|
#include <sysdep.h>
|
|
|
|
#include <unistd.h>
|
2013-03-20 00:07:15 +00:00
|
|
|
#include <sys/mman.h>
|
2004-11-17 09:10:08 +00:00
|
|
|
#include <sys/uio.h>
|
2004-11-13 03:09:30 +00:00
|
|
|
#include <not-cancel.h>
|
1995-02-18 01:27:10 +00:00
|
|
|
|
|
|
|
#ifdef FATAL_PREPARE_INCLUDE
|
|
|
|
#include FATAL_PREPARE_INCLUDE
|
|
|
|
#endif
|
|
|
|
|
2013-03-20 00:07:15 +00:00
|
|
|
#ifndef WRITEV_FOR_FATAL
|
|
|
|
# define WRITEV_FOR_FATAL writev_for_fatal
|
|
|
|
static bool
|
|
|
|
writev_for_fatal (int fd, const struct iovec *iov, size_t niov, size_t total)
|
|
|
|
{
|
|
|
|
return TEMP_FAILURE_RETRY (__writev (fd, iov, niov)) == total;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-11-13 03:09:30 +00:00
|
|
|
struct str_list
|
|
|
|
{
|
|
|
|
const char *str;
|
|
|
|
size_t len;
|
|
|
|
struct str_list *next;
|
|
|
|
};
|
|
|
|
|
1995-02-18 01:27:10 +00:00
|
|
|
/* Abort with an error message. */
|
|
|
|
void
|
2017-07-11 14:44:01 +00:00
|
|
|
__libc_message (enum __libc_message_action action, const char *fmt, ...)
|
1995-02-18 01:27:10 +00:00
|
|
|
{
|
2004-11-13 03:09:30 +00:00
|
|
|
va_list ap;
|
|
|
|
int fd = -1;
|
|
|
|
|
|
|
|
va_start (ap, fmt);
|
1995-02-18 01:27:10 +00:00
|
|
|
|
|
|
|
#ifdef FATAL_PREPARE
|
|
|
|
FATAL_PREPARE;
|
|
|
|
#endif
|
|
|
|
|
2004-11-13 03:09:30 +00:00
|
|
|
if (fd == -1)
|
|
|
|
fd = STDERR_FILENO;
|
|
|
|
|
|
|
|
struct str_list *list = NULL;
|
|
|
|
int nlist = 0;
|
|
|
|
|
|
|
|
const char *cp = fmt;
|
|
|
|
while (*cp != '\0')
|
1995-02-18 01:27:10 +00:00
|
|
|
{
|
2004-11-13 03:09:30 +00:00
|
|
|
/* Find the next "%s" or the end of the string. */
|
2005-12-29 10:38:16 +00:00
|
|
|
const char *next = cp;
|
2004-11-13 03:09:30 +00:00
|
|
|
while (next[0] != '%' || next[1] != 's')
|
1995-02-18 01:27:10 +00:00
|
|
|
{
|
2004-11-13 03:09:30 +00:00
|
|
|
next = __strchrnul (next + 1, '%');
|
|
|
|
|
|
|
|
if (next[0] == '\0')
|
|
|
|
break;
|
1995-02-18 01:27:10 +00:00
|
|
|
}
|
2004-11-13 03:09:30 +00:00
|
|
|
|
|
|
|
/* Determine what to print. */
|
|
|
|
const char *str;
|
|
|
|
size_t len;
|
|
|
|
if (cp[0] == '%' && cp[1] == 's')
|
|
|
|
{
|
|
|
|
str = va_arg (ap, const char *);
|
|
|
|
len = strlen (str);
|
|
|
|
cp += 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
str = cp;
|
|
|
|
len = next - cp;
|
|
|
|
cp = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct str_list *newp = alloca (sizeof (struct str_list));
|
|
|
|
newp->str = str;
|
|
|
|
newp->len = len;
|
|
|
|
newp->next = list;
|
|
|
|
list = newp;
|
|
|
|
++nlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nlist > 0)
|
|
|
|
{
|
|
|
|
struct iovec *iov = alloca (nlist * sizeof (struct iovec));
|
|
|
|
ssize_t total = 0;
|
|
|
|
|
|
|
|
for (int cnt = nlist - 1; cnt >= 0; --cnt)
|
|
|
|
{
|
2005-12-29 10:38:16 +00:00
|
|
|
iov[cnt].iov_base = (char *) list->str;
|
2004-11-13 03:09:30 +00:00
|
|
|
iov[cnt].iov_len = list->len;
|
|
|
|
total += list->len;
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
|
2019-08-19 13:41:29 +00:00
|
|
|
WRITEV_FOR_FATAL (fd, iov, nlist, total);
|
2009-06-15 23:17:09 +00:00
|
|
|
|
2017-07-11 14:44:01 +00:00
|
|
|
if ((action & do_abort))
|
2009-06-15 23:17:09 +00:00
|
|
|
{
|
2011-05-15 04:34:48 +00:00
|
|
|
total = ((total + 1 + GLRO(dl_pagesize) - 1)
|
|
|
|
& ~(GLRO(dl_pagesize) - 1));
|
|
|
|
struct abort_msg_s *buf = __mmap (NULL, total,
|
|
|
|
PROT_READ | PROT_WRITE,
|
|
|
|
MAP_ANON | MAP_PRIVATE, -1, 0);
|
2013-03-20 00:07:15 +00:00
|
|
|
if (__glibc_likely (buf != MAP_FAILED))
|
2011-05-15 04:34:48 +00:00
|
|
|
{
|
|
|
|
buf->size = total;
|
|
|
|
char *wp = buf->msg;
|
|
|
|
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. */
|
|
|
|
struct abort_msg_s *old = atomic_exchange_acq (&__abort_msg,
|
|
|
|
buf);
|
|
|
|
if (old != NULL)
|
|
|
|
__munmap (old, old->size);
|
|
|
|
}
|
2009-06-15 23:17:09 +00:00
|
|
|
}
|
1995-02-18 01:27:10 +00:00
|
|
|
}
|
|
|
|
|
2004-11-13 03:09:30 +00:00
|
|
|
va_end (ap);
|
|
|
|
|
2017-07-11 14:44:01 +00:00
|
|
|
if ((action & do_abort))
|
2019-08-19 13:41:29 +00:00
|
|
|
/* Kill the application. */
|
|
|
|
abort ();
|
2004-11-13 03:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2015-10-19 12:04:33 +00:00
|
|
|
__libc_fatal (const char *message)
|
2004-11-13 03:09:30 +00:00
|
|
|
{
|
2004-11-15 22:00:25 +00:00
|
|
|
/* The loop is added only to keep gcc happy. */
|
|
|
|
while (1)
|
2019-08-19 13:41:29 +00:00
|
|
|
__libc_message (do_abort, "%s", message);
|
1995-02-18 01:27:10 +00:00
|
|
|
}
|
2003-07-22 23:56:53 +00:00
|
|
|
libc_hidden_def (__libc_fatal)
|