mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-30 04:13:06 +02:00
Merge branch 'wip/smcv/prctl-undumpable' into 'main'
testutils: Use prctl PR_SET_DUMPABLE to silence core dumps on Linux See merge request GNOME/glib!3510
This commit is contained in:
commit
9d203a9e39
@ -3359,6 +3359,7 @@ g_test_trap_assert_stdout_unmatched
|
|||||||
g_test_trap_assert_stderr
|
g_test_trap_assert_stderr
|
||||||
g_test_trap_assert_stderr_unmatched
|
g_test_trap_assert_stderr_unmatched
|
||||||
g_test_trap_fork
|
g_test_trap_fork
|
||||||
|
g_test_disable_crash_reporting
|
||||||
|
|
||||||
g_test_rand_bit
|
g_test_rand_bit
|
||||||
g_test_rand_int
|
g_test_rand_int
|
||||||
|
@ -34,6 +34,9 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#ifdef HAVE_SYS_PRCTL_H
|
||||||
|
#include <sys/prctl.h>
|
||||||
|
#endif
|
||||||
#ifdef HAVE_SYS_RESOURCE_H
|
#ifdef HAVE_SYS_RESOURCE_H
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#endif
|
#endif
|
||||||
@ -1302,6 +1305,33 @@ g_test_log (GTestLogType lbit,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* g_test_disable_crash_reporting:
|
||||||
|
*
|
||||||
|
* Attempt to disable system crash reporting infrastructure.
|
||||||
|
*
|
||||||
|
* This function should be called before exercising code paths that are
|
||||||
|
* expected or intended to crash, to avoid wasting resources in system-wide
|
||||||
|
* crash collection infrastructure such as systemd-coredump or abrt.
|
||||||
|
*
|
||||||
|
* Since: 2.78
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
g_test_disable_crash_reporting (void)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_SYS_RESOURCE_H
|
||||||
|
struct rlimit limit = { 0, 0 };
|
||||||
|
|
||||||
|
(void) setrlimit (RLIMIT_CORE, &limit);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(HAVE_PRCTL) && defined(PR_SET_DUMPABLE)
|
||||||
|
/* On Linux, RLIMIT_CORE = 0 is ignored if core dumps are
|
||||||
|
* configured to be written to a pipe, but PR_SET_DUMPABLE is not. */
|
||||||
|
(void) prctl (PR_SET_DUMPABLE, 0, 0, 0, 0);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/* We intentionally parse the command line without GOptionContext
|
/* We intentionally parse the command line without GOptionContext
|
||||||
* because otherwise you would never be able to test it.
|
* because otherwise you would never be able to test it.
|
||||||
*/
|
*/
|
||||||
@ -1376,12 +1406,8 @@ parse_args (gint *argc_p,
|
|||||||
* tests spawn a *lot* of them. Avoid spamming system crash
|
* tests spawn a *lot* of them. Avoid spamming system crash
|
||||||
* collection programs such as systemd-coredump and abrt.
|
* collection programs such as systemd-coredump and abrt.
|
||||||
*/
|
*/
|
||||||
#ifdef HAVE_SYS_RESOURCE_H
|
g_test_disable_crash_reporting ();
|
||||||
{
|
|
||||||
struct rlimit limit = { 0, 0 };
|
|
||||||
(void) setrlimit (RLIMIT_CORE, &limit);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
argv[i] = NULL;
|
argv[i] = NULL;
|
||||||
|
|
||||||
/* Force non-TAP output when spawning a subprocess, since people often
|
/* Force non-TAP output when spawning a subprocess, since people often
|
||||||
@ -3980,12 +4006,7 @@ g_test_trap_fork (guint64 usec_timeout,
|
|||||||
* tests spawn a *lot* of them. Avoid spamming system crash
|
* tests spawn a *lot* of them. Avoid spamming system crash
|
||||||
* collection programs such as systemd-coredump and abrt.
|
* collection programs such as systemd-coredump and abrt.
|
||||||
*/
|
*/
|
||||||
#ifdef HAVE_SYS_RESOURCE_H
|
g_test_disable_crash_reporting ();
|
||||||
{
|
|
||||||
struct rlimit limit = { 0, 0 };
|
|
||||||
(void) setrlimit (RLIMIT_CORE, &limit);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -407,6 +407,8 @@ GLIB_AVAILABLE_IN_2_38
|
|||||||
gboolean g_test_failed (void);
|
gboolean g_test_failed (void);
|
||||||
GLIB_AVAILABLE_IN_2_38
|
GLIB_AVAILABLE_IN_2_38
|
||||||
void g_test_set_nonfatal_assertions (void);
|
void g_test_set_nonfatal_assertions (void);
|
||||||
|
GLIB_AVAILABLE_IN_2_78
|
||||||
|
void g_test_disable_crash_reporting (void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* g_test_add:
|
* g_test_add:
|
||||||
|
@ -19,20 +19,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#ifdef HAVE_SYS_RESOURCE_H
|
|
||||||
#include <sys/resource.h>
|
|
||||||
#endif
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc,
|
main (int argc,
|
||||||
char **argv)
|
char **argv)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_SYS_RESOURCE_H
|
|
||||||
/* We expect this test to abort, so try to avoid that creating a coredump */
|
/* We expect this test to abort, so try to avoid that creating a coredump */
|
||||||
struct rlimit limit = { 0, 0 };
|
g_test_disable_crash_reporting ();
|
||||||
(void) setrlimit (RLIMIT_CORE, &limit);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
g_assert (42 < 0);
|
g_assert (42 < 0);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -23,9 +23,6 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#ifdef HAVE_SYS_RESOURCE_H
|
|
||||||
#include <sys/resource.h>
|
|
||||||
#endif
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
static gboolean malloc_eom = FALSE;
|
static gboolean malloc_eom = FALSE;
|
||||||
@ -59,11 +56,8 @@ int
|
|||||||
main (int argc,
|
main (int argc,
|
||||||
char *argv[])
|
char *argv[])
|
||||||
{
|
{
|
||||||
#ifdef HAVE_SYS_RESOURCE_H
|
|
||||||
/* We expect this test to abort, so try to avoid that creating a coredump */
|
/* We expect this test to abort, so try to avoid that creating a coredump */
|
||||||
struct rlimit limit = { 0, 0 };
|
g_test_disable_crash_reporting ();
|
||||||
(void) setrlimit (RLIMIT_CORE, &limit);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
g_setenv ("LC_ALL", "C", TRUE);
|
g_setenv ("LC_ALL", "C", TRUE);
|
||||||
|
|
||||||
|
@ -381,6 +381,7 @@ headers = [
|
|||||||
'sys/mnttab.h',
|
'sys/mnttab.h',
|
||||||
'sys/mount.h',
|
'sys/mount.h',
|
||||||
'sys/param.h',
|
'sys/param.h',
|
||||||
|
'sys/prctl.h',
|
||||||
'sys/resource.h',
|
'sys/resource.h',
|
||||||
'sys/select.h',
|
'sys/select.h',
|
||||||
'sys/statfs.h',
|
'sys/statfs.h',
|
||||||
@ -695,6 +696,11 @@ if glib_conf.has('HAVE_SYS_STATFS_H') or glib_conf.has('HAVE_SYS_MOUNT_H')
|
|||||||
else
|
else
|
||||||
have_func_statfs = false
|
have_func_statfs = false
|
||||||
endif
|
endif
|
||||||
|
if glib_conf.has('HAVE_SYS_PRCTL_H')
|
||||||
|
functions += ['prctl']
|
||||||
|
else
|
||||||
|
have_func_prctl = false
|
||||||
|
endif
|
||||||
|
|
||||||
if host_system == 'windows'
|
if host_system == 'windows'
|
||||||
iphlpapi_dep = cc.find_library('iphlpapi')
|
iphlpapi_dep = cc.find_library('iphlpapi')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user