1/*****************************************************************
2 * drkonqi - The KDE Crash Handler
3 *
4 * Copyright (C) 2000-2003 Hans Petter Bieker <bieker@kde.org>
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *****************************************************************/
27
28#include <cstdlib>
29#include <unistd.h>
30
31#include <KApplication>
32#include <KCmdLineArgs>
33#include <KAboutData>
34#include <KLocalizedString>
35#include <kdefakes.h>
36
37#include "drkonqi.h"
38#include "drkonqidialog.h"
39
40static const char version[] = "2.1.5";
41static const char description[] = I18N_NOOP("The KDE Crash Handler gives the user feedback "
42 "if a program has crashed.");
43
44int main(int argc, char* argv[])
45{
46#ifndef Q_OS_WIN //krazy:exclude=cpp
47// Drop privs.
48 setgid(getgid());
49 if (setuid(getuid()) < 0 && geteuid() != getuid()) {
50 exit(255);
51 }
52#endif
53
54 // Prevent KApplication from setting the crash handler. We will set it later...
55 setenv("KDE_DEBUG", "true", 1);
56 // Session management is not needed, do not even connect in order to survive longer than ksmserver.
57 unsetenv("SESSION_MANAGER");
58
59 KAboutData aboutData("drkonqi", 0, ki18n("The KDE Crash Handler"),
60 version, ki18n(description),
61 KAboutData::License_GPL,
62 ki18n("(C) 2000-2009, The DrKonqi Authors"));
63 aboutData.addAuthor(ki18nc("@info:credit","Hans Petter Bieker"), KLocalizedString(),
64 "bieker@kde.org");
65 aboutData.addAuthor(ki18nc("@info:credit","Dario Andres Rodriguez"), KLocalizedString(),
66 "andresbajotierra@gmail.com");
67 aboutData.addAuthor(ki18nc("@info:credit","George Kiagiadakis"), KLocalizedString(),
68 "gkiagia@users.sourceforge.net");
69 aboutData.addAuthor(ki18nc("@info:credit","A. L. Spehr"), KLocalizedString(),
70 "spehr@kde.org");
71 aboutData.setProgramIconName("tools-report-bug");
72
73 KCmdLineArgs::init(argc, argv, &aboutData);
74
75 KCmdLineOptions options;
76 options.add("signal <number>", ki18nc("@info:shell","The signal number that was caught"));
77 options.add("appname <name>", ki18nc("@info:shell","Name of the program"));
78 options.add("apppath <path>", ki18nc("@info:shell","Path to the executable"));
79 options.add("appversion <version>", ki18nc("@info:shell","The version of the program"));
80 options.add("bugaddress <address>", ki18nc("@info:shell","The bug address to use"));
81 options.add("programname <name>", ki18nc("@info:shell","Translated name of the program"));
82 options.add("pid <pid>", ki18nc("@info:shell","The PID of the program"));
83 options.add("startupid <id>", ki18nc("@info:shell","Startup ID of the program"));
84 options.add("kdeinit", ki18nc("@info:shell","The program was started by kdeinit"));
85 options.add("safer", ki18nc("@info:shell","Disable arbitrary disk access"));
86 options.add("restarted", ki18nc("@info:shell","The program has already been restarted"));
87 options.add("keeprunning", ki18nc("@info:shell","Keep the program running and generate "
88 "the backtrace at startup"));
89 options.add("thread <threadid>", ki18nc("@info:shell","The thread id of the failing thread"));
90 KCmdLineArgs::addCmdLineOptions(options);
91
92 KComponentData inst(KCmdLineArgs::aboutData());
93 QApplication *qa =
94 KCmdLineArgs::parsedArgs()->isSet("safer") ?
95 new QApplication(KCmdLineArgs::qtArgc(), KCmdLineArgs::qtArgv()) :
96 new KApplication;
97 qa->setApplicationName(inst.componentName());
98
99 if (!DrKonqi::init()) {
100 delete qa;
101 return 1;
102 }
103
104 qa->setQuitOnLastWindowClosed(false);
105 KGlobal::setAllowQuit(true);
106
107 DrKonqiDialog *w = new DrKonqiDialog();
108 w->show();
109 int ret = qa->exec();
110
111 DrKonqi::cleanup();
112 delete qa;
113 return ret;
114}
115