diff options
Diffstat (limited to 'tests/auto/network/socket/qtcpserver/crashingServer/main.cpp')
-rw-r--r-- | tests/auto/network/socket/qtcpserver/crashingServer/main.cpp | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/tests/auto/network/socket/qtcpserver/crashingServer/main.cpp b/tests/auto/network/socket/qtcpserver/crashingServer/main.cpp index 7cb65cd1a3..1c41552eb5 100644 --- a/tests/auto/network/socket/qtcpserver/crashingServer/main.cpp +++ b/tests/auto/network/socket/qtcpserver/crashingServer/main.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtCore> @@ -32,18 +7,45 @@ #if defined(Q_OS_WIN) && defined(Q_CC_MSVC) # 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); + if (argc < 1) { + fprintf(stderr, "Need a port number\n"); + return 1; + } + int port = QByteArrayView(argv[1]).toInt(); QTcpServer server; - if (!server.listen(QHostAddress::LocalHost, 49199)) { - qDebug("Failed to listen: %s", server.errorString().toLatin1().constData()); + if (!server.listen(QHostAddress::LocalHost, port)) { + fprintf(stderr, "Failed to listen: %s\n", server.errorString().toLatin1().constData()); + if (server.serverError() == QTcpSocket::AddressInUseError) { + // let's see if we can find the process that would be holding this + // still open +#ifdef Q_OS_LINUX + static const char *ss_args[] = { + "ss", "-nap", "sport", "=", argv[1], nullptr + }; + dup2(STDERR_FILENO, STDOUT_FILENO); + execvp(ss_args[0], const_cast<char **>(ss_args)); +#endif + } return 1; } |