• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KInit

klauncher_main.cpp

Go to the documentation of this file.
00001 /*
00002   This file is part of the KDE libraries
00003   Copyright (c) 1999 Waldo Bastian <bastian@kde.org>
00004 
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Library General Public
00007   License version 2 as published by the Free Software Foundation.
00008 
00009   This library is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012   Library General Public License for more details.
00013 
00014   You should have received a copy of the GNU Library General Public License
00015   along with this library; see the file COPYING.LIB.  If not, write to
00016   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017   Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include <config.h>
00021 
00022 #include <unistd.h>
00023 #include <fcntl.h>
00024 
00025 #include "klauncher.h"
00026 #include <kcomponentdata.h>
00027 #include "kcrash.h"
00028 #include "kdebug.h"
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <signal.h>
00032 #include <klocale.h>
00033 
00034 #include "klauncher_cmds.h"
00035 #include <QtCore/QCoreApplication>
00036 
00037 #ifndef Q_WS_WIN
00038 static void sig_handler(int sig_num)
00039 {
00040    // No recursion
00041    signal( SIGHUP, SIG_IGN);
00042    signal( SIGTERM, SIG_IGN);
00043 fprintf(stderr, "klauncher: Exiting on signal %d\n", sig_num);
00044    KLauncher::destruct(255);
00045 }
00046 #endif
00047 
00048 extern "C" KDE_EXPORT int kdemain( int argc, char**argv )
00049 {
00050 #ifndef Q_WS_WIN
00051    // Started via kdeinit.
00052    if (fcntl(LAUNCHER_FD, F_GETFD) == -1)
00053    {
00054       fprintf(stderr, "%s", i18n("klauncher: This program is not supposed to be started manually.\n"
00055                                  "klauncher: It is started automatically by kdeinit4.\n").toLocal8Bit().data());
00056       return 1;
00057    }
00058 #endif
00059    KComponentData componentData("klauncher");
00060 
00061    // WABA: Make sure not to enable session management.
00062    putenv(strdup("SESSION_MANAGER="));
00063 
00064    // Allow the locale to initialize properly
00065    KLocale::setMainCatalog("kdelibs4");
00066 
00067    // We need a QCoreApplication to get a DBus event loop
00068    QCoreApplication app(argc, argv);
00069    app.setApplicationName( componentData.componentName() );
00070 
00071    int maxTry = 3;
00072    while(true)
00073    {
00074       QString service(QLatin1String("org.kde.klauncher")); // same as ktoolinvocation.cpp
00075       if (!QDBusConnection::sessionBus().isConnected()) {
00076          kWarning() << "No DBUS session-bus found. Check if you have started the DBUS server.";
00077          return 1;
00078       }
00079       QDBusReply<QDBusConnectionInterface::RegisterServiceReply> reply =
00080           QDBusConnection::sessionBus().interface()->registerService(service);
00081       if (!reply.isValid())
00082       {
00083          kWarning() << "DBUS communication problem!";
00084          return 1;
00085       }
00086       if (reply == QDBusConnectionInterface::ServiceRegistered)
00087           break;
00088 
00089       if (--maxTry == 0)
00090       {
00091          kWarning() << "Another instance of klauncher is already running!";
00092          return 1;
00093       }
00094 
00095       // Wait a bit...
00096       kWarning() << "Waiting for already running klauncher to exit.";
00097       sleep(1);
00098 
00099       // Try again...
00100    }
00101 
00102    KLauncher *launcher = new KLauncher(LAUNCHER_FD);
00103    QDBusConnection::sessionBus().registerObject("/", launcher);
00104 
00105 #ifndef Q_WS_WIN
00106    KCrash::setEmergencySaveFunction(sig_handler);
00107    signal( SIGHUP, sig_handler);
00108    signal( SIGPIPE, SIG_IGN);
00109    signal( SIGTERM, sig_handler);
00110 #endif
00111 
00112    return app.exec();
00113 }

KInit

Skip menu "KInit"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   WTF
  • KJSEmbed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  •   core
  • Phonon
  •   Backend
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal