mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-29 11:41:21 +03:00
Consolidate Linux and POSIX libc_fatal code.
This commit is contained in:
16
ChangeLog
16
ChangeLog
@ -1,3 +1,19 @@
|
|||||||
|
2013-03-19 Roland McGrath <roland@hack.frob.com>
|
||||||
|
|
||||||
|
* sysdeps/posix/libc_fatal.c: Include <sys/mman.h>.
|
||||||
|
[!WRITEV_FOR_FATAL] (writev_for_fatal): New function.
|
||||||
|
[!WRITEV_FOR_FATAL] (WRITEV_FOR_FATAL): New macro; call that.
|
||||||
|
[!BEFORE_ABORT] (before_abort): New function.
|
||||||
|
[!BEFORE_ABORT] (BEFORE_ABORT): New macro; call that.
|
||||||
|
* sysdeps/unix/sysv/linux/libc_fatal.c: Trim includes.
|
||||||
|
(writev_for_fatal): New function.
|
||||||
|
(WRITEV_FOR_FATAL): New macro; call that.
|
||||||
|
(backtrace_and_maps): New function.
|
||||||
|
(BEFORE_ABORT): New macro; call that.
|
||||||
|
(struct str_list): Type removed.
|
||||||
|
(__libc_message, __libc_fatal): Functions removed.
|
||||||
|
Include <sysdeps/posix/libc_fatal.c> instead.
|
||||||
|
|
||||||
2013-03-19 Joseph Myers <joseph@codesourcery.com>
|
2013-03-19 Joseph Myers <joseph@codesourcery.com>
|
||||||
|
|
||||||
* math/k_casinhf.c (__kernel_casinhf): Consistently use float
|
* math/k_casinhf.c (__kernel_casinhf): Consistently use float
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
/* Copyright (C) 1993-2013 Free Software Foundation, Inc.
|
/* Catastrophic failure reports. Generic POSIX.1 version.
|
||||||
|
Copyright (C) 1993-2013 Free Software Foundation, Inc.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
The GNU C Library is free software; you can redistribute it and/or
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
@ -27,6 +28,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sysdep.h>
|
#include <sysdep.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
#include <sys/syslog.h>
|
#include <sys/syslog.h>
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
#include <not-cancel.h>
|
#include <not-cancel.h>
|
||||||
@ -35,6 +37,25 @@
|
|||||||
#include FATAL_PREPARE_INCLUDE
|
#include FATAL_PREPARE_INCLUDE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
|
#ifndef BEFORE_ABORT
|
||||||
|
# define BEFORE_ABORT before_abort
|
||||||
|
static void
|
||||||
|
before_abort (int do_abort __attribute__ ((unused)),
|
||||||
|
bool written __attribute__ ((unused)),
|
||||||
|
int fd __attribute__ ((unused)))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
struct str_list
|
struct str_list
|
||||||
{
|
{
|
||||||
const char *str;
|
const char *str;
|
||||||
@ -42,7 +63,6 @@ struct str_list
|
|||||||
struct str_list *next;
|
struct str_list *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* Abort with an error message. */
|
/* Abort with an error message. */
|
||||||
void
|
void
|
||||||
__libc_message (int do_abort, const char *fmt, ...)
|
__libc_message (int do_abort, const char *fmt, ...)
|
||||||
@ -121,8 +141,7 @@ __libc_message (int do_abort, const char *fmt, ...)
|
|||||||
list = list->next;
|
list = list->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TEMP_FAILURE_RETRY (__writev (fd, iov, nlist)) == total)
|
written = WRITEV_FOR_FATAL (fd, iov, nlist, total);
|
||||||
written = true;
|
|
||||||
|
|
||||||
if (do_abort)
|
if (do_abort)
|
||||||
{
|
{
|
||||||
@ -131,7 +150,7 @@ __libc_message (int do_abort, const char *fmt, ...)
|
|||||||
struct abort_msg_s *buf = __mmap (NULL, total,
|
struct abort_msg_s *buf = __mmap (NULL, total,
|
||||||
PROT_READ | PROT_WRITE,
|
PROT_READ | PROT_WRITE,
|
||||||
MAP_ANON | MAP_PRIVATE, -1, 0);
|
MAP_ANON | MAP_PRIVATE, -1, 0);
|
||||||
if (buf != MAP_FAILED)
|
if (__glibc_likely (buf != MAP_FAILED))
|
||||||
{
|
{
|
||||||
buf->size = total;
|
buf->size = total;
|
||||||
char *wp = buf->msg;
|
char *wp = buf->msg;
|
||||||
@ -158,9 +177,13 @@ __libc_message (int do_abort, const char *fmt, ...)
|
|||||||
va_end (ap_copy);
|
va_end (ap_copy);
|
||||||
|
|
||||||
if (do_abort)
|
if (do_abort)
|
||||||
|
{
|
||||||
|
BEFORE_ABORT (do_abort, written, fd);
|
||||||
|
|
||||||
/* Kill the application. */
|
/* Kill the application. */
|
||||||
abort ();
|
abort ();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
/* Copyright (C) 1993-2013 Free Software Foundation, Inc.
|
/* Catastrophic failure reports. Linux version.
|
||||||
|
Copyright (C) 1993-2013 Free Software Foundation, Inc.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
The GNU C Library is free software; you can redistribute it and/or
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
@ -15,159 +16,28 @@
|
|||||||
License along with the GNU C Library; if not, see
|
License along with the GNU C Library; if not, see
|
||||||
<http://www.gnu.org/licenses/>. */
|
<http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#include <atomic.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
|
||||||
#include <ldsodefs.h>
|
|
||||||
#include <paths.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <sysdep.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <sys/syslog.h>
|
|
||||||
#include <execinfo.h>
|
#include <execinfo.h>
|
||||||
|
#include <fcntl.h>
|
||||||
/* Abort with an error message. */
|
|
||||||
#include <not-cancel.h>
|
#include <not-cancel.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <sys/uio.h>
|
||||||
|
|
||||||
#ifdef FATAL_PREPARE_INCLUDE
|
static bool
|
||||||
#include FATAL_PREPARE_INCLUDE
|
writev_for_fatal (int fd, const struct iovec *iov, size_t niov, size_t total)
|
||||||
#endif
|
|
||||||
|
|
||||||
struct str_list
|
|
||||||
{
|
{
|
||||||
const char *str;
|
|
||||||
size_t len;
|
|
||||||
struct str_list *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* Abort with an error message. */
|
|
||||||
void
|
|
||||||
__libc_message (int do_abort, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
va_list ap_copy;
|
|
||||||
int fd = -1;
|
|
||||||
|
|
||||||
va_start (ap, fmt);
|
|
||||||
va_copy (ap_copy, ap);
|
|
||||||
|
|
||||||
#ifdef FATAL_PREPARE
|
|
||||||
FATAL_PREPARE;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Open a descriptor for /dev/tty unless the user explicitly
|
|
||||||
requests errors on standard error. */
|
|
||||||
const char *on_2 = __libc_secure_getenv ("LIBC_FATAL_STDERR_");
|
|
||||||
if (on_2 == NULL || *on_2 == '\0')
|
|
||||||
fd = open_not_cancel_2 (_PATH_TTY, O_RDWR | O_NOCTTY | O_NDELAY);
|
|
||||||
|
|
||||||
if (fd == -1)
|
|
||||||
fd = STDERR_FILENO;
|
|
||||||
|
|
||||||
struct str_list *list = NULL;
|
|
||||||
int nlist = 0;
|
|
||||||
|
|
||||||
const char *cp = fmt;
|
|
||||||
while (*cp != '\0')
|
|
||||||
{
|
|
||||||
/* Find the next "%s" or the end of the string. */
|
|
||||||
const char *next = cp;
|
|
||||||
while (next[0] != '%' || next[1] != 's')
|
|
||||||
{
|
|
||||||
next = __strchrnul (next + 1, '%');
|
|
||||||
|
|
||||||
if (next[0] == '\0')
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool written = false;
|
|
||||||
if (nlist > 0)
|
|
||||||
{
|
|
||||||
struct iovec *iov = alloca (nlist * sizeof (struct iovec));
|
|
||||||
ssize_t total = 0;
|
|
||||||
|
|
||||||
for (int cnt = nlist - 1; cnt >= 0; --cnt)
|
|
||||||
{
|
|
||||||
iov[cnt].iov_base = (void *) list->str;
|
|
||||||
iov[cnt].iov_len = list->len;
|
|
||||||
total += list->len;
|
|
||||||
list = list->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
INTERNAL_SYSCALL_DECL (err);
|
INTERNAL_SYSCALL_DECL (err);
|
||||||
ssize_t cnt;
|
ssize_t cnt;
|
||||||
do
|
do
|
||||||
cnt = INTERNAL_SYSCALL (writev, err, 3, fd, iov, nlist);
|
cnt = INTERNAL_SYSCALL (writev, err, 3, fd, iov, niov);
|
||||||
while (INTERNAL_SYSCALL_ERROR_P (cnt, err)
|
while (INTERNAL_SYSCALL_ERROR_P (cnt, err)
|
||||||
&& INTERNAL_SYSCALL_ERRNO (cnt, err) == EINTR);
|
&& INTERNAL_SYSCALL_ERRNO (cnt, err) == EINTR);
|
||||||
|
return cnt == total;
|
||||||
if (cnt == total)
|
|
||||||
written = true;
|
|
||||||
|
|
||||||
if (do_abort)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
if (__builtin_expect (buf != MAP_FAILED, 1))
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
#define WRITEV_FOR_FATAL writev_for_fatal
|
||||||
|
|
||||||
va_end (ap);
|
static void
|
||||||
|
backtrace_and_maps (int do_abort, bool written, int fd)
|
||||||
/* If we had no success writing the message, use syslog. */
|
|
||||||
if (! written)
|
|
||||||
vsyslog (LOG_ERR, fmt, ap_copy);
|
|
||||||
|
|
||||||
va_end (ap_copy);
|
|
||||||
|
|
||||||
if (do_abort)
|
|
||||||
{
|
{
|
||||||
if (do_abort > 1 && written)
|
if (do_abort > 1 && written)
|
||||||
{
|
{
|
||||||
@ -191,19 +61,7 @@ __libc_message (int do_abort, const char *fmt, ...)
|
|||||||
close_not_cancel_no_status (fd2);
|
close_not_cancel_no_status (fd2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Terminate the process. */
|
|
||||||
abort ();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
#define BEFORE_ABORT backtrace_and_maps
|
||||||
|
|
||||||
|
#include <sysdeps/posix/libc_fatal.c>
|
||||||
void
|
|
||||||
__libc_fatal (message)
|
|
||||||
const char *message;
|
|
||||||
{
|
|
||||||
/* The loop is added only to keep gcc happy. */
|
|
||||||
while (1)
|
|
||||||
__libc_message (1, "%s", message);
|
|
||||||
}
|
|
||||||
libc_hidden_def (__libc_fatal)
|
|
||||||
|
Reference in New Issue
Block a user