about summary refs log tree commit diff
path: root/sysdeps/posix/libc_fatal.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/posix/libc_fatal.c')
-rw-r--r--sysdeps/posix/libc_fatal.c37
1 files changed, 30 insertions, 7 deletions
diff --git a/sysdeps/posix/libc_fatal.c b/sysdeps/posix/libc_fatal.c
index 8d416006b5..afa1b816c3 100644
--- a/sysdeps/posix/libc_fatal.c
+++ b/sysdeps/posix/libc_fatal.c
@@ -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.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -27,6 +28,7 @@
 #include <string.h>
 #include <sysdep.h>
 #include <unistd.h>
+#include <sys/mman.h>
 #include <sys/syslog.h>
 #include <sys/uio.h>
 #include <not-cancel.h>
@@ -35,6 +37,25 @@
 #include FATAL_PREPARE_INCLUDE
 #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
 {
   const char *str;
@@ -42,7 +63,6 @@ struct str_list
   struct str_list *next;
 };
 
-
 /* Abort with an error message.  */
 void
 __libc_message (int do_abort, const char *fmt, ...)
@@ -121,8 +141,7 @@ __libc_message (int do_abort, const char *fmt, ...)
 	  list = list->next;
 	}
 
-      if (TEMP_FAILURE_RETRY (__writev (fd, iov, nlist)) == total)
-	written = true;
+      written = WRITEV_FOR_FATAL (fd, iov, nlist, total);
 
       if (do_abort)
 	{
@@ -131,7 +150,7 @@ __libc_message (int do_abort, const char *fmt, ...)
 	  struct abort_msg_s *buf = __mmap (NULL, total,
 					    PROT_READ | PROT_WRITE,
 					    MAP_ANON | MAP_PRIVATE, -1, 0);
-	  if (buf != MAP_FAILED)
+	  if (__glibc_likely (buf != MAP_FAILED))
 	    {
 	      buf->size = total;
 	      char *wp = buf->msg;
@@ -158,8 +177,12 @@ __libc_message (int do_abort, const char *fmt, ...)
   va_end (ap_copy);
 
   if (do_abort)
-    /* Kill the application.  */
-    abort ();
+    {
+      BEFORE_ABORT (do_abort, written, fd);
+
+      /* Kill the application.  */
+      abort ();
+    }
 }