diff options
author | Timothy Pearson <[email protected]> | 2013-01-27 01:04:16 -0600 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2013-01-27 01:04:16 -0600 |
commit | 5159cd2beb2e87806a5b54e9991b7895285c9d3e (patch) | |
tree | 9b70e8be47a390f8f4d56ead812ab0c9dad88709 /kinit/tdelauncher_main.cpp | |
parent | c17cb900dcf52b8bd6dc300d4f103392900ec2b4 (diff) | |
download | tdelibs-5159cd2beb2e87806a5b54e9991b7895285c9d3e.tar.gz tdelibs-5159cd2beb2e87806a5b54e9991b7895285c9d3e.zip |
Rename a number of libraries and executables to avoid conflicts with KDE4
Diffstat (limited to 'kinit/tdelauncher_main.cpp')
-rw-r--r-- | kinit/tdelauncher_main.cpp | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/kinit/tdelauncher_main.cpp b/kinit/tdelauncher_main.cpp new file mode 100644 index 000000000..54ab94d54 --- /dev/null +++ b/kinit/tdelauncher_main.cpp @@ -0,0 +1,116 @@ +/* + This file is part of the KDE libraries + Copyright (c) 1999 Waldo Bastian <[email protected]> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#include <unistd.h> +#include <fcntl.h> + +#include "kapplication.h" +#include "tdelauncher.h" +#include "kcmdlineargs.h" +#include "kcrash.h" +#include "kdebug.h" +#include <stdio.h> +#include <stdlib.h> +#include <signal.h> +#include <tqcstring.h> +#include <klocale.h> + +#include "tdelauncher_cmds.h" + +static void sig_handler(int sig_num) +{ + // No recursion + signal( SIGHUP, SIG_IGN); + signal( SIGTERM, SIG_IGN); + fprintf(stderr, "[tdelauncher] Exiting on signal %d\n", sig_num); + KLauncher::destruct(255); +} + +static KCmdLineOptions options[] = +{ + { "new-startup", "Internal", 0 }, + KCmdLineLastOption +}; + +extern "C" KDE_EXPORT int kdemain( int argc, char**argv ) +{ + // Started via tdeinit. + if (fcntl(LAUNCHER_FD, F_GETFD) == -1) + { + fprintf(stderr, "%s", i18n("[tdelauncher] This program is not supposed to be started manually.\n" + "[tdelauncher] It is started automatically by tdeinit.\n").local8Bit().data()); + return 1; + } + + TQCString cname = TDEApplication::launcher(); + char *name = cname.data(); + TDECmdLineArgs::init(argc, argv, name, "KLauncher", "A service launcher.", + "v1.0"); + + KLauncher::addCmdLineOptions(); + TDECmdLineArgs::addCmdLineOptions( options ); + + // WABA: Make sure not to enable session management. + putenv(strdup("SESSION_MANAGER=")); + + // Allow the locale to initialize properly + KLocale::setMainCatalogue("tdelibs"); + + TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); + + int maxTry = 3; + while(true) + { + TQCString dcopName = TDEApplication::dcopClient()->registerAs(name, false); + if (dcopName.isEmpty()) + { + kdWarning() << "[tdelauncher] DCOP communication problem!" << endl; + return 1; + } + if (dcopName == cname) + break; // Good! + + if (--maxTry == 0) + { + kdWarning() << "[tdelauncher] Another instance of tdelauncher is already running!" << endl; + return 1; + } + + // Wait a bit... + kdWarning() << "[tdelauncher] Waiting for already running tdelauncher to exit." << endl; + sleep(1); + + // Try again... + } + + KLauncher *launcher = new KLauncher(LAUNCHER_FD, args->isSet("new-startup")); + launcher->dcopClient()->setDefaultObject( name ); + launcher->dcopClient()->setDaemonMode( true ); + + KCrash::setEmergencySaveFunction(sig_handler); + signal( SIGHUP, sig_handler); + signal( SIGPIPE, SIG_IGN); + signal( SIGTERM, sig_handler); + + launcher->exec(); + return 0; +} + |