2 This file is part of the KDE libraries
3 Copyright (c) 1999 Waldo Bastian <bastian@kde.org>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
25 #include "klauncher.h"
26 #include <kcomponentdata.h>
35 #include "klauncher_cmds.h"
36 #include <QtCore/QCoreApplication>
39 static int sigpipe
[ 2 ];
40 static void sig_handler(int sig_num
)
43 KDE_signal( SIGHUP
, SIG_IGN
);
44 KDE_signal( SIGTERM
, SIG_IGN
);
45 fprintf(stderr
, "klauncher: Exiting on signal %d\n", sig_num
);
47 write( sigpipe
[ 1 ], &tmp
, 1 );
51 extern "C" KDE_EXPORT
int kdemain( int argc
, char**argv
)
54 // Started via kdeinit.
55 if (fcntl(LAUNCHER_FD
, F_GETFD
) == -1)
57 fprintf(stderr
, "%s", i18n("klauncher: This program is not supposed to be started manually.\n"
58 "klauncher: It is started automatically by kdeinit4.\n").toLocal8Bit().data());
62 KComponentData
componentData("klauncher");
64 // WABA: Make sure not to enable session management.
65 putenv(strdup("SESSION_MANAGER="));
67 // Allow the locale to initialize properly
68 KLocale::setMainCatalog("kdelibs4");
70 // We need a QCoreApplication to get a DBus event loop
71 QCoreApplication
app(argc
, argv
);
72 app
.setApplicationName( componentData
.componentName() );
77 QString
service(QLatin1String("org.kde.klauncher")); // same as ktoolinvocation.cpp
78 if (!QDBusConnection::sessionBus().isConnected()) {
79 kWarning() << "No DBUS session-bus found. Check if you have started the DBUS server.";
82 QDBusReply
<QDBusConnectionInterface::RegisterServiceReply
> reply
=
83 QDBusConnection::sessionBus().interface()->registerService(service
);
86 kWarning() << "DBUS communication problem!";
89 if (reply
== QDBusConnectionInterface::ServiceRegistered
)
94 kWarning() << "Another instance of klauncher is already running!";
99 kWarning() << "Waiting for already running klauncher to exit.";
105 KLauncher
*launcher
= new KLauncher(LAUNCHER_FD
);
106 QDBusConnection::sessionBus().registerObject("/", launcher
);
110 QSocketNotifier
* signotif
= new QSocketNotifier( sigpipe
[ 0 ], QSocketNotifier::Read
, launcher
);
111 QObject::connect( signotif
, SIGNAL( activated( int )), launcher
, SLOT( destruct()));
112 KCrash::setEmergencySaveFunction(sig_handler
);
113 KDE_signal( SIGHUP
, sig_handler
);
114 KDE_signal( SIGPIPE
, SIG_IGN
);
115 KDE_signal( SIGTERM
, sig_handler
);