• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KInit

  • kinit
klauncher_main.cpp
Go to the documentation of this file.
1/*
2 This file is part of the KDE libraries
3 Copyright (c) 1999 Waldo Bastian <bastian@kde.org>
4
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.
8
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.
13
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.
18*/
19
20#include <config.h>
21
22#include <unistd.h>
23#include <fcntl.h>
24
25#include "klauncher.h"
26#include <kcomponentdata.h>
27#include "kcrash.h"
28#include "kdebug.h"
29#include <stdio.h>
30#include <stdlib.h>
31#include <signal.h>
32#include <klocale.h>
33#include <kde_file.h>
34
35#include "klauncher_cmds.h"
36#include <QtCore/QCoreApplication>
37
38#ifndef USE_KPROCESS_FOR_KIOSLAVES
39static int sigpipe[ 2 ];
40static void sig_handler(int sig_num)
41{
42 // No recursion
43 KDE_signal( SIGHUP, SIG_IGN);
44 KDE_signal( SIGTERM, SIG_IGN);
45 fprintf(stderr, "klauncher: Exiting on signal %d\n", sig_num);
46 char tmp = 'x';
47 write( sigpipe[ 1 ], &tmp, 1 );
48}
49#endif
50
51#if defined(Q_OS_DARWIN) || defined (Q_OS_MAC)
52#include <kkernel_mac.h>
53#endif
54
55extern "C" KDE_EXPORT int kdemain( int argc, char**argv )
56{
57#ifndef Q_WS_WIN
58 // Started via kdeinit.
59 int launcherFd;
60 if (argc != 2 || memcmp(argv[1], "--fd=", 5) || !(launcherFd = atoi(argv[1] + 5)))
61 {
62 fprintf(stderr, "%s", i18n("klauncher: This program is not supposed to be started manually.\n"
63 "klauncher: It is started automatically by kdeinit4.\n").toLocal8Bit().data());
64 return 1;
65 }
66#endif
67
68#if defined(Q_OS_DARWIN) || defined (Q_OS_MAC)
69 mac_initialize_dbus();
70#endif
71
72 KComponentData componentData("klauncher", "kdelibs4");
73 KGlobal::locale();
74
75 // WABA: Make sure not to enable session management.
76 putenv(strdup("SESSION_MANAGER="));
77
78 // Disable the GLib event loop (bug 328571)
79 const bool wasQtNoGlibSet = !qgetenv("QT_NO_GLIB").isEmpty();
80 if (!wasQtNoGlibSet) {
81 qputenv("QT_NO_GLIB", "1");
82 }
83
84 // We need a QCoreApplication to get a DBus event loop
85 QCoreApplication app(argc, argv);
86 app.setApplicationName( componentData.componentName() );
87
88 // Now get rid of QT_NO_GLIB again so launched processes don't inherit it
89 if (!wasQtNoGlibSet) {
90 qputenv("QT_NO_GLIB", "");
91 }
92
93 int maxTry = 3;
94 while(true)
95 {
96 QString service(QLatin1String("org.kde.klauncher")); // same as ktoolinvocation.cpp
97 if (!QDBusConnection::sessionBus().isConnected()) {
98 kWarning() << "No DBUS session-bus found. Check if you have started the DBUS server.";
99 return 1;
100 }
101 QDBusReply<QDBusConnectionInterface::RegisterServiceReply> reply =
102 QDBusConnection::sessionBus().interface()->registerService(service);
103 if (!reply.isValid())
104 {
105 kWarning() << "DBUS communication problem!";
106 return 1;
107 }
108 if (reply == QDBusConnectionInterface::ServiceRegistered)
109 break;
110
111 if (--maxTry == 0)
112 {
113 kWarning() << "Another instance of klauncher is already running!";
114 return 1;
115 }
116
117 // Wait a bit...
118 kWarning() << "Waiting for already running klauncher to exit.";
119 sleep(1);
120
121 // Try again...
122 }
123
124#ifndef USE_KPROCESS_FOR_KIOSLAVES
125 KLauncher *launcher = new KLauncher(launcherFd);
126#else
127 KLauncher *launcher = new KLauncher();
128#endif
129 QDBusConnection::sessionBus().registerObject(QString::fromLatin1("/"), launcher);
130
131#ifndef USE_KPROCESS_FOR_KIOSLAVES
132 if (pipe(sigpipe) != 0) {
133 perror("klauncher: pipe failed.");
134 return 1;
135 }
136 QSocketNotifier* signotif = new QSocketNotifier( sigpipe[ 0 ], QSocketNotifier::Read, launcher );
137 QObject::connect( signotif, SIGNAL(activated(int)), launcher, SLOT(destruct()));
138 KCrash::setEmergencySaveFunction(sig_handler);
139 KDE_signal( SIGHUP, sig_handler);
140 KDE_signal( SIGPIPE, SIG_IGN);
141 KDE_signal( SIGTERM, sig_handler);
142#endif
143
144 return app.exec();
145}
KComponentData
KComponentData::componentName
QString componentName() const
KLauncher
Definition: klauncher.h:124
kWarning
#define kWarning
kcomponentdata.h
perror
QDebug perror(QDebug s, KDebugTag)
kdebug.h
launcher
int launcher[2]
Definition: kinit.cpp:130
argv
char ** argv
Definition: kinit.cpp:141
mac_initialize_dbus
void mac_initialize_dbus()
kkernel_mac.h
klauncher.h
klauncher_cmds.h
kdemain
int kdemain(int argc, char **argv)
Definition: klauncher_main.cpp:55
klocale.h
i18n
QString i18n(const char *text)
KGlobal::locale
KLocale * locale()
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KInit

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

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal