• Skip to content
  • Skip to link menu
KDE 4.3 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 #include <kde_file.h>
00034 
00035 #include "klauncher_cmds.h"
00036 #include <QtCore/QCoreApplication>
00037 
00038 #ifndef Q_WS_WIN
00039 static int sigpipe[ 2 ];
00040 static void sig_handler(int sig_num)
00041 {
00042    // No recursion
00043    KDE_signal( SIGHUP, SIG_IGN);
00044    KDE_signal( SIGTERM, SIG_IGN);
00045    fprintf(stderr, "klauncher: Exiting on signal %d\n", sig_num);
00046    char tmp = 'x';
00047    write( sigpipe[ 1 ], &tmp, 1 );
00048 }
00049 #endif
00050 
00051 extern "C" KDE_EXPORT int kdemain( int argc, char**argv )
00052 {
00053 #ifndef Q_WS_WIN
00054    // Started via kdeinit.
00055    int launcherFd;
00056    if (argc != 2 || memcmp(argv[1], "--fd=", 5) || !(launcherFd = atoi(argv[1] + 5)))
00057    {
00058       fprintf(stderr, "%s", i18n("klauncher: This program is not supposed to be started manually.\n"
00059                                  "klauncher: It is started automatically by kdeinit4.\n").toLocal8Bit().data());
00060       return 1;
00061    }
00062 #endif
00063 
00064    KComponentData componentData("klauncher", "kdelibs4");
00065    KGlobal::locale();
00066 
00067    // WABA: Make sure not to enable session management.
00068    putenv(strdup("SESSION_MANAGER="));
00069 
00070    // We need a QCoreApplication to get a DBus event loop
00071    QCoreApplication app(argc, argv);
00072    app.setApplicationName( componentData.componentName() );
00073 
00074    int maxTry = 3;
00075    while(true)
00076    {
00077       QString service(QLatin1String("org.kde.klauncher")); // same as ktoolinvocation.cpp
00078       if (!QDBusConnection::sessionBus().isConnected()) {
00079          kWarning() << "No DBUS session-bus found. Check if you have started the DBUS server.";
00080          return 1;
00081       }
00082       QDBusReply<QDBusConnectionInterface::RegisterServiceReply> reply =
00083           QDBusConnection::sessionBus().interface()->registerService(service);
00084       if (!reply.isValid())
00085       {
00086          kWarning() << "DBUS communication problem!";
00087          return 1;
00088       }
00089       if (reply == QDBusConnectionInterface::ServiceRegistered)
00090           break;
00091 
00092       if (--maxTry == 0)
00093       {
00094          kWarning() << "Another instance of klauncher is already running!";
00095          return 1;
00096       }
00097 
00098       // Wait a bit...
00099       kWarning() << "Waiting for already running klauncher to exit.";
00100       sleep(1);
00101 
00102       // Try again...
00103    }
00104 
00105 #ifndef Q_WS_WIN
00106    KLauncher *launcher = new KLauncher(launcherFd);
00107 #else
00108    KLauncher *launcher = new KLauncher();
00109 #endif
00110    QDBusConnection::sessionBus().registerObject(QString::fromLatin1("/"), launcher);
00111 
00112 #ifndef Q_WS_WIN
00113    if (pipe(sigpipe) != 0) {
00114        perror("klauncher: pipe failed.");
00115        return 1;
00116    }
00117    QSocketNotifier* signotif = new QSocketNotifier( sigpipe[ 0 ], QSocketNotifier::Read, launcher );
00118    QObject::connect( signotif, SIGNAL( activated( int )), launcher, SLOT( destruct()));
00119    KCrash::setEmergencySaveFunction(sig_handler);
00120    KDE_signal( SIGHUP, sig_handler);
00121    KDE_signal( SIGPIPE, SIG_IGN);
00122    KDE_signal( SIGTERM, sig_handler);
00123 #endif
00124 
00125    return app.exec();
00126 }

KInit

Skip menu "KInit"
  • Main Page
  • 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
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
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