Autotest/Unix: request zero-sized core dumps for crashing code
Unix systems have got crash loggers in the past 15-20 years, notably macOS and Linux (abrtd, systemd-coredumpd, etc.). By setting the core dump limit to zero, those tools should be mostly inhibited from running and thus not interfere with the parent process' timeouts. Even for systems without core dump loggers, disabling the writing of a core dump to the filesystem should also help. Change-Id: I12a088d1ae424825abd3fffd171d112d0671effe Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> (cherry picked from commit c849c48d19cc0b086f98688d760fa6e008adc50e) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
789f51eabc
commit
2a14dd4f47
@ -2,6 +2,22 @@
|
||||
// Copyright (C) 2020 Intel Corporation.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#if __has_include(<sys/resource.h>)
|
||||
# include <sys/resource.h>
|
||||
# if defined(RLIMIT_CORE)
|
||||
static bool disableCoreDumps()
|
||||
{
|
||||
// Unix: set our core dump limit to zero to request no dialogs.
|
||||
if (struct rlimit rlim; getrlimit(RLIMIT_CORE, &rlim) == 0) {
|
||||
rlim.rlim_cur = 0;
|
||||
setrlimit(RLIMIT_CORE, &rlim);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
static bool disabledCoreDumps = disableCoreDumps();
|
||||
# endif // RLIMIT_CORE
|
||||
#endif // <sys/resource.h>
|
||||
|
||||
void crashFallback(volatile int *ptr = nullptr)
|
||||
{
|
||||
*ptr = 0;
|
||||
|
@ -8,15 +8,23 @@
|
||||
# include <crtdbg.h>
|
||||
#endif
|
||||
#ifdef Q_OS_UNIX
|
||||
# include <sys/resource.h>
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// Windows: Suppress crash notification dialog.
|
||||
#if defined(Q_OS_WIN) && defined(Q_CC_MSVC)
|
||||
// Windows: Suppress crash notification dialog.
|
||||
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG);
|
||||
#elif defined(RLIMIT_CORE)
|
||||
// Unix: set our core dump limit to zero to request no dialogs.
|
||||
if (struct rlimit rlim; getrlimit(RLIMIT_CORE, &rlim) == 0) {
|
||||
rlim.rlim_cur = 0;
|
||||
setrlimit(RLIMIT_CORE, &rlim);
|
||||
}
|
||||
#endif
|
||||
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
QTcpServer server;
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <qt_windows.h>
|
||||
#else
|
||||
#include <sys/resource.h>
|
||||
#endif
|
||||
|
||||
class tst_Crashes: public QObject
|
||||
@ -22,6 +24,12 @@ void tst_Crashes::crash()
|
||||
#if defined(Q_OS_WIN)
|
||||
//we avoid the error dialogbox to appear on windows
|
||||
SetErrorMode( SEM_NOGPFAULTERRORBOX | SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
|
||||
#elif defined(RLIMIT_CORE)
|
||||
// Unix: set our core dump limit to zero to request no dialogs.
|
||||
if (struct rlimit rlim; getrlimit(RLIMIT_CORE, &rlim) == 0) {
|
||||
rlim.rlim_cur = 0;
|
||||
setrlimit(RLIMIT_CORE, &rlim);
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
We deliberately dereference an invalid but non-zero address;
|
||||
|
Loading…
x
Reference in New Issue
Block a user