You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
3.3 KiB
117 lines
3.3 KiB
15 years ago
|
/*
|
||
|
This file is part of the KDE libraries
|
||
|
Copyright (c) 1999 Waldo Bastian <bastian@kde.org>
|
||
|
|
||
|
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"
|
||
12 years ago
|
#include "tdelauncher.h"
|
||
15 years ago
|
#include "kcmdlineargs.h"
|
||
|
#include "kcrash.h"
|
||
|
#include "kdebug.h"
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <signal.h>
|
||
14 years ago
|
#include <tqcstring.h>
|
||
15 years ago
|
#include <klocale.h>
|
||
|
|
||
12 years ago
|
#include "tdelauncher_cmds.h"
|
||
15 years ago
|
|
||
|
static void sig_handler(int sig_num)
|
||
|
{
|
||
|
// No recursion
|
||
|
signal( SIGHUP, SIG_IGN);
|
||
|
signal( SIGTERM, SIG_IGN);
|
||
12 years ago
|
fprintf(stderr, "[tdelauncher] Exiting on signal %d\n", sig_num);
|
||
15 years ago
|
KLauncher::destruct(255);
|
||
|
}
|
||
|
|
||
|
static KCmdLineOptions options[] =
|
||
|
{
|
||
|
{ "new-startup", "Internal", 0 },
|
||
|
KCmdLineLastOption
|
||
|
};
|
||
|
|
||
|
extern "C" KDE_EXPORT int kdemain( int argc, char**argv )
|
||
|
{
|
||
13 years ago
|
// Started via tdeinit.
|
||
15 years ago
|
if (fcntl(LAUNCHER_FD, F_GETFD) == -1)
|
||
|
{
|
||
12 years ago
|
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());
|
||
15 years ago
|
return 1;
|
||
|
}
|
||
|
|
||
12 years ago
|
TQCString cname = TDEApplication::launcher();
|
||
15 years ago
|
char *name = cname.data();
|
||
12 years ago
|
TDECmdLineArgs::init(argc, argv, name, "KLauncher", "A service launcher.",
|
||
15 years ago
|
"v1.0");
|
||
|
|
||
|
KLauncher::addCmdLineOptions();
|
||
12 years ago
|
TDECmdLineArgs::addCmdLineOptions( options );
|
||
15 years ago
|
|
||
|
// WABA: Make sure not to enable session management.
|
||
|
putenv(strdup("SESSION_MANAGER="));
|
||
|
|
||
|
// Allow the locale to initialize properly
|
||
13 years ago
|
KLocale::setMainCatalogue("tdelibs");
|
||
15 years ago
|
|
||
12 years ago
|
TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
|
||
15 years ago
|
|
||
|
int maxTry = 3;
|
||
|
while(true)
|
||
|
{
|
||
12 years ago
|
TQCString dcopName = TDEApplication::dcopClient()->registerAs(name, false);
|
||
15 years ago
|
if (dcopName.isEmpty())
|
||
|
{
|
||
12 years ago
|
kdWarning() << "[tdelauncher] DCOP communication problem!" << endl;
|
||
15 years ago
|
return 1;
|
||
|
}
|
||
|
if (dcopName == cname)
|
||
|
break; // Good!
|
||
|
|
||
|
if (--maxTry == 0)
|
||
|
{
|
||
12 years ago
|
kdWarning() << "[tdelauncher] Another instance of tdelauncher is already running!" << endl;
|
||
15 years ago
|
return 1;
|
||
|
}
|
||
|
|
||
|
// Wait a bit...
|
||
12 years ago
|
kdWarning() << "[tdelauncher] Waiting for already running tdelauncher to exit." << endl;
|
||
15 years ago
|
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;
|
||
|
}
|
||
|
|