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>
|
||
|
|
||
12 years ago
|
#include "tdeapplication.h"
|
||
12 years ago
|
#include "tdelauncher.h"
|
||
12 years ago
|
#include "tdecmdlineargs.h"
|
||
15 years ago
|
#include "kcrash.h"
|
||
|
#include "kdebug.h"
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <signal.h>
|
||
14 years ago
|
#include <tqcstring.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
|
||
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);
|
||
12 years ago
|
TDELauncher::destruct(255);
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
static TDECmdLineOptions options[] =
|
||
15 years ago
|
{
|
||
|
{ "new-startup", "Internal", 0 },
|
||
12 years ago
|
TDECmdLineLastOption
|
||
15 years ago
|
};
|
||
|
|
||
|
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, "TDELauncher", "A service launcher.",
|
||
15 years ago
|
"v1.0");
|
||
|
|
||
12 years ago
|
TDELauncher::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
|
||
12 years ago
|
TDELocale::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...
|
||
|
}
|
||
|
|
||
12 years ago
|
TDELauncher *launcher = new TDELauncher(LAUNCHER_FD, args->isSet("new-startup"));
|
||
15 years ago
|
launcher->dcopClient()->setDefaultObject( name );
|
||
|
launcher->dcopClient()->setDaemonMode( true );
|
||
|
|
||
12 years ago
|
TDECrash::setEmergencySaveFunction(sig_handler);
|
||
15 years ago
|
signal( SIGHUP, sig_handler);
|
||
|
signal( SIGPIPE, SIG_IGN);
|
||
|
signal( SIGTERM, sig_handler);
|
||
|
|
||
|
launcher->exec();
|
||
|
return 0;
|
||
|
}
|
||
|
|