diff --git a/glib/Makefile.am b/glib/Makefile.am index 3707cb4a1..0744a6c52 100644 --- a/glib/Makefile.am +++ b/glib/Makefile.am @@ -152,6 +152,7 @@ libglib_2_0_la_SOURCES = \ gmarkup.c \ gmem.c \ gmessages.c \ + gmessages-private.h \ gmirroringtable.h \ gnode.c \ goption.c \ diff --git a/glib/gmessages-private.h b/glib/gmessages-private.h new file mode 100644 index 000000000..1a592b95f --- /dev/null +++ b/glib/gmessages-private.h @@ -0,0 +1,35 @@ +/* gmain.h - the GLib Main loop + * Copyright (C) 1998-2000 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __G_MESSAGES_PRIVATE_H__ +#define __G_MESSAGES_PRIVATE_H__ + +#include + +G_BEGIN_DECLS + +G_GNUC_INTERNAL void +_g_log_set_exit_on_fatal (void); + +G_GNUC_INTERNAL void +_g_log_abort (void) G_GNUC_NORETURN; + +G_END_DECLS + +#endif /* __G_MESSAGES_PRIVATE_H__ */ diff --git a/glib/gmessages.c b/glib/gmessages.c index 6160bf5d8..daab0c446 100644 --- a/glib/gmessages.c +++ b/glib/gmessages.c @@ -59,7 +59,7 @@ #include #include -#include "gmessages.h" +#include "gmessages-private.h" #include "glib-init.h" #include "gbacktrace.h" @@ -238,12 +238,23 @@ static GLogDomain *g_log_domains = NULL; static GPrintFunc glib_print_func = NULL; static GPrintFunc glib_printerr_func = NULL; static GPrivate g_log_depth; +static gboolean exit_on_fatal; static GLogFunc default_log_func = g_log_default_handler; static gpointer default_log_data = NULL; static GTestLogFatalFunc fatal_log_func = NULL; static gpointer fatal_log_data; /* --- functions --- */ + +void +_g_log_abort (void) +{ + if (exit_on_fatal) + _exit (1); + else + abort (); +} + #ifdef G_OS_WIN32 # include static gboolean win32_keep_fatal_message = FALSE; @@ -955,7 +966,11 @@ g_logv (const gchar *log_domain, && !fatal_log_func (log_domain, test_level, msg, fatal_log_data); } - if ((test_level & G_LOG_FLAG_FATAL) && !masquerade_fatal) + if ((test_level & G_LOG_FLAG_FATAL) && exit_on_fatal) + { + _g_log_abort (); + } + else if ((test_level & G_LOG_FLAG_FATAL) && !masquerade_fatal) { #ifdef G_OS_WIN32 if (win32_keep_fatal_message) @@ -1060,7 +1075,7 @@ g_assert_warning (const char *log_domain, line, pretty_function, expression); - abort (); + _g_log_abort (); } /** @@ -1552,3 +1567,9 @@ g_printf_string_upper_bound (const gchar *format, gchar c; return _g_vsnprintf (&c, 1, format, args) + 1; } + +void +_g_log_set_exit_on_fatal (void) +{ + exit_on_fatal = TRUE; +} diff --git a/glib/gtestutils.c b/glib/gtestutils.c index 6e34f65bf..b5cb321d3 100644 --- a/glib/gtestutils.c +++ b/glib/gtestutils.c @@ -21,6 +21,7 @@ #include "config.h" #include "gtestutils.h" +#include "gmessages-private.h" #include "gfileutils.h" #include @@ -36,6 +37,9 @@ #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_SYS_RESOURCE_H +#include +#endif #ifdef G_OS_WIN32 #include #include @@ -54,6 +58,7 @@ #include "gslice.h" #include "gspawn.h" #include "glib-private.h" +#include "gmessages-private.h" /** @@ -759,6 +764,17 @@ parse_args (gint *argc_p, else if (strcmp ("--GTestSubprocess", argv[i]) == 0) { test_in_subprocess = TRUE; + /* We typically expect these child processes to crash, and some + * tests spawn a *lot* of them. Avoid spamming system crash + * collection programs such as systemd-coredump and abrt. + */ +#ifdef HAVE_SYS_RESOURCE_H + { + struct rlimit limit = { 0, 0 }; + (void) setrlimit (RLIMIT_CORE, &limit); + } +#endif + _g_log_set_exit_on_fatal (); argv[i] = NULL; } else if (strcmp ("-p", argv[i]) == 0 || strncmp ("-p=", argv[i], 3) == 0) @@ -2027,7 +2043,7 @@ g_assertion_message (const char *domain, g_test_log (G_TEST_LOG_ERROR, s, NULL, 0, NULL); g_free (s); - abort(); + _g_log_abort (); } void