KService

kbuildsycoca_main.cpp
1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 1999 David Faure <faure@kde.org>
4 SPDX-FileCopyrightText: 2002-2003 Waldo Bastian <bastian@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-only
7*/
8
9#include <kbuildsycoca_p.h>
10
11#include <kservice_version.h>
12
13#include <KAboutData>
14#include <KLocalizedString>
15
16#include <QCommandLineOption>
17#include <QCommandLineParser>
18#include <QCoreApplication>
19#include <QDateTime>
20#include <QDebug>
21#include <QDir>
22#include <QFile>
23#include <QFileInfo>
24#include <QStandardPaths>
25
26#include <qplatformdefs.h> // for unlink
27#ifdef Q_OS_WIN
28#include <qt_windows.h>
29#endif
30
31static void crashHandler(int)
32{
33 // If we crash while reading sycoca, we delete the database
34 // in an attempt to recover.
35 if (KBuildSycoca::sycocaPath()) {
36 unlink(KBuildSycoca::sycocaPath());
37 }
38}
39
40#if defined(Q_OS_WIN)
41// glue function for calling the unix signal handler from the windows unhandled exception filter
42// Inspired from KCrash, but heavily simplified
43LONG WINAPI win32UnhandledExceptionFilter(_EXCEPTION_POINTERS *)
44{
45 crashHandler(0);
46 return EXCEPTION_EXECUTE_HANDLER; // allow windows to do the default action (terminate)
47}
48#endif
49
50void setCrashHandler()
51{
52#if defined(Q_OS_WIN)
53 SetUnhandledExceptionFilter(win32UnhandledExceptionFilter);
54#elif !defined(Q_OS_ANDROID)
55 sigset_t mask;
56 sigemptyset(&mask);
57
58#ifdef SIGSEGV
59 signal(SIGSEGV, crashHandler);
60 sigaddset(&mask, SIGSEGV);
61#endif
62#ifdef SIGBUS
63 signal(SIGBUS, crashHandler);
64 sigaddset(&mask, SIGBUS);
65#endif
66#ifdef SIGFPE
67 signal(SIGFPE, crashHandler);
68 sigaddset(&mask, SIGFPE);
69#endif
70#ifdef SIGILL
71 signal(SIGILL, crashHandler);
72 sigaddset(&mask, SIGILL);
73#endif
74#ifdef SIGABRT
75 signal(SIGABRT, crashHandler);
76 sigaddset(&mask, SIGABRT);
77#endif
78
79 sigprocmask(SIG_UNBLOCK, &mask, nullptr);
80#endif
81}
82
83int main(int argc, char **argv)
84{
85 QCoreApplication app(argc, argv);
86
88
89 KAboutData about(QStringLiteral(KBUILDSYCOCA_EXENAME),
90 i18nc("application name", "KBuildSycoca"),
91 QStringLiteral(KSERVICE_VERSION_STRING),
92 i18nc("application description", "Rebuilds the system configuration cache."),
94 i18nc("@info:credit", "Copyright 1999-2014 KDE Developers"));
95 about.addAuthor(i18nc("@info:credit", "David Faure"), i18nc("@info:credit", "Author"), QStringLiteral("faure@kde.org"));
96 about.addAuthor(i18nc("@info:credit", "Waldo Bastian"), i18nc("@info:credit", "Author"), QStringLiteral("bastian@kde.org"));
98
99 QCommandLineParser parser;
100 about.setupCommandLine(&parser);
101 parser.addOption(
102 QCommandLineOption(QStringLiteral("noincremental"), i18nc("@info:shell command-line option", "Disable incremental update, re-read everything")));
103 parser.addOption(QCommandLineOption(QStringLiteral("menutest"), i18nc("@info:shell command-line option", "Perform menu generation test run only")));
104 parser.addOption(
105 QCommandLineOption(QStringLiteral("track"), i18nc("@info:shell command-line option", "Track menu id for debug purposes"), QStringLiteral("menu-id")));
106 parser.addOption(
107 QCommandLineOption(QStringLiteral("testmode"), i18nc("@info:shell command-line option", "Switch QStandardPaths to test mode, for unit tests only")));
108 parser.process(app);
109 about.processCommandLine(&parser);
110
111 const bool bMenuTest = parser.isSet(QStringLiteral("menutest"));
112
113 if (parser.isSet(QStringLiteral("testmode"))) {
115 }
116
118
119 fprintf(stderr, "%s running...\n", KBUILDSYCOCA_EXENAME);
120
121 const bool incremental = !parser.isSet(QStringLiteral("noincremental"));
122
123 KBuildSycoca sycoca; // Build data base
124 if (parser.isSet(QStringLiteral("track"))) {
125 sycoca.setTrackId(parser.value(QStringLiteral("track")));
126 }
127 sycoca.setMenuTest(bMenuTest);
128 if (!sycoca.recreate(incremental)) {
129 return -1;
130 }
131
132 return 0;
133}
static void setApplicationData(const KAboutData &aboutData)
static void setApplicationDomain(const QByteArray &domain)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
KCRASH_EXPORT void setCrashHandler(HandlerType handler=defaultCrashHandler)
KCRASH_EXPORT HandlerType crashHandler()
bool addOption(const QCommandLineOption &option)
bool isSet(const QCommandLineOption &option) const const
void process(const QCoreApplication &app)
QString value(const QCommandLineOption &option) const const
void setTestModeEnabled(bool testMode)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:16:40 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.