Changeset View
Changeset View
Standalone View
Standalone View
tools/main.cpp
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * Copyright (C) 2010-2018 Daniel Nicoletti <dantti12@gmail.com> | 2 | * Copyright (C) 2010-2018 Daniel Nicoletti <dantti12@gmail.com> | ||
3 | * (C) 2011 Modestas Vainius <modax@debian.org> | 3 | * (C) 2011 Modestas Vainius <modax@debian.org> | ||
4 | * (C) 2018 Harald Sitter <sitter@kde.org> | ||||
4 | * | 5 | * | ||
5 | * This library is free software; you can redistribute it and/or | 6 | * This library is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of the GNU Library General Public | 7 | * modify it under the terms of the GNU Library General Public | ||
7 | * License as published by the Free Software Foundation; either | 8 | * License as published by the Free Software Foundation; either | ||
8 | * version 2 of the License, or (at your option) any later version. | 9 | * version 2 of the License, or (at your option) any later version. | ||
9 | * | 10 | * | ||
10 | * This library is distributed in the hope that it will be useful, | 11 | * This library is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | * Library General Public License for more details. | 14 | * Library General Public License for more details. | ||
14 | * | 15 | * | ||
15 | * You should have received a copy of the GNU Library General Public License | 16 | * You should have received a copy of the GNU Library General Public License | ||
16 | * along with this library; see the file COPYING.LIB. If not, write to | 17 | * along with this library; see the file COPYING.LIB. If not, write to | ||
17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | * Boston, MA 02110-1301, USA. | 19 | * Boston, MA 02110-1301, USA. | ||
19 | */ | 20 | */ | ||
20 | 21 | | |||
21 | #include <QtCore/QCommandLineParser> | 22 | #include <QApplication> | ||
22 | #include <QtCore/QDebug> | 23 | #include <QCommandLineParser> | ||
23 | #include <QtCore/QRegExp> | 24 | #include <QDebug> | ||
24 | #include <QtWidgets/QApplication> | 25 | #include <QRegExp> | ||
26 | #include <QSocketNotifier> | ||||
25 | 27 | | |||
26 | #include <KAboutData> | 28 | #include <KAboutData> | ||
27 | #include <KLocalizedString> | 29 | #include <KLocalizedString> | ||
28 | 30 | | |||
29 | #include <iostream> | 31 | #include <iostream> | ||
30 | 32 | | |||
33 | #include <signal.h> | ||||
34 | #include <sys/socket.h> | ||||
35 | #include <sys/types.h> | ||||
36 | #include <unistd.h> | ||||
37 | | ||||
31 | #include <DebconfGui.h> | 38 | #include <DebconfGui.h> | ||
32 | 39 | | |||
33 | using namespace DebconfKde; | 40 | using namespace DebconfKde; | ||
34 | 41 | | |||
42 | // Handle SIGQUIT. Clients (e.g. packagekit) may use QUIT which would otherwise | ||||
43 | // result in a core dump. | ||||
44 | // Qt methods aren't signal-safe, so we'll defer the handling via a socket | ||||
45 | // notification. | ||||
46 | static void setupQuitHandler() { | ||||
47 | static int quitFD[2]; | ||||
48 | if (socketpair(AF_UNIX, SOCK_STREAM, 0, quitFD)) { | ||||
49 | qErrnoWarning("Failed to create socket"); | ||||
50 | } | ||||
51 | auto notifier = new QSocketNotifier(quitFD[1], QSocketNotifier::Read, qApp); | ||||
52 | QObject::connect(notifier, &QSocketNotifier::activated, [notifier]() { | ||||
53 | notifier->setEnabled(false); | ||||
54 | char c; | ||||
55 | read(quitFD[1], &c, sizeof(c)); | ||||
56 | qApp->quit(); | ||||
57 | }); | ||||
58 | | ||||
59 | struct sigaction sa; | ||||
60 | sa.sa_handler = [](int) -> void { | ||||
61 | char c = 1; | ||||
62 | write(quitFD[0], &c, sizeof(c)); | ||||
63 | }; | ||||
64 | sigemptyset(&sa.sa_mask); | ||||
65 | sigaddset(&sa.sa_mask, SIGQUIT); | ||||
66 | sa.sa_flags = 0; | ||||
67 | sa.sa_flags |= SA_RESTART; | ||||
68 | | ||||
69 | if (sigaction(SIGQUIT, &sa, 0) != 0) { | ||||
70 | qErrnoWarning("Failed to set quit handler"); | ||||
71 | } | ||||
72 | } | ||||
73 | | ||||
35 | int main(int argc, char **argv) | 74 | int main(int argc, char **argv) | ||
36 | { | 75 | { | ||
37 | QApplication app(argc, argv); | 76 | QApplication app(argc, argv); | ||
77 | setupQuitHandler(); | ||||
38 | 78 | | |||
39 | KLocalizedString::setApplicationDomain("libdebconf-kde"); | 79 | KLocalizedString::setApplicationDomain("libdebconf-kde"); | ||
40 | 80 | | |||
41 | KAboutData aboutData(QStringLiteral("debconf-kde-helper"), | 81 | KAboutData aboutData(QStringLiteral("debconf-kde-helper"), | ||
42 | i18nc("@title", "Debconf KDE"), | 82 | i18nc("@title", "Debconf KDE"), | ||
43 | QStringLiteral(PROJECT_VERSION), | 83 | QStringLiteral(PROJECT_VERSION), | ||
44 | i18nc("@info", "Debconf frontend for KDE"), | 84 | i18nc("@info", "Debconf frontend for KDE"), | ||
45 | KAboutLicense::LicenseKey::LGPL); | 85 | KAboutLicense::LicenseKey::LGPL); | ||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |