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.
1422 lines
44 KiB
1422 lines
44 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.
|
||
|
*/
|
||
|
#ifdef HAVE_CONFIG_H
|
||
|
#include <config.h>
|
||
|
#endif
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <unistd.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <errno.h>
|
||
|
#include <signal.h>
|
||
|
#include <sys/time.h>
|
||
|
|
||
15 years ago
|
#include <tqfile.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdeconfig.h>
|
||
15 years ago
|
#include <kdebug.h>
|
||
|
#include <klibloader.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
|
#include <tdeprotocolmanager.h>
|
||
15 years ago
|
#include <kprotocolinfo.h>
|
||
|
#include <krun.h>
|
||
|
#include <kstandarddirs.h>
|
||
12 years ago
|
#include <tdetempfile.h>
|
||
15 years ago
|
#include <kurl.h>
|
||
|
|
||
|
#if defined Q_WS_X11 && ! defined K_WS_QTONLY
|
||
12 years ago
|
#include <tdestartupinfo.h> // schroder
|
||
15 years ago
|
#endif
|
||
|
|
||
|
|
||
12 years ago
|
#include "tdeio/global.h"
|
||
|
#include "tdeio/connection.h"
|
||
|
#include "tdeio/slaveinterface.h"
|
||
15 years ago
|
|
||
12 years ago
|
#include "tdelauncher.h"
|
||
|
#include "tdelauncher_cmds.h"
|
||
15 years ago
|
|
||
|
//#if defined Q_WS_X11 && ! defined K_WS_QTONLY
|
||
|
#ifdef Q_WS_X11
|
||
|
//#undef K_WS_QTONLY
|
||
|
#include <X11/Xlib.h> // schroder
|
||
|
#endif
|
||
|
|
||
|
// Dispose slaves after being idle for SLAVE_MAX_IDLE seconds
|
||
|
#define SLAVE_MAX_IDLE 30
|
||
|
|
||
12 years ago
|
using namespace TDEIO;
|
||
15 years ago
|
|
||
12 years ago
|
template class TQPtrList<TDELaunchRequest>;
|
||
15 years ago
|
template class TQPtrList<IdleSlave>;
|
||
15 years ago
|
|
||
12 years ago
|
IdleSlave::IdleSlave(TDESocket *socket)
|
||
15 years ago
|
{
|
||
|
mConn.init(socket);
|
||
15 years ago
|
mConn.connect(this, TQT_SLOT(gotInput()));
|
||
15 years ago
|
mConn.send( CMD_SLAVE_STATUS );
|
||
|
mPid = 0;
|
||
|
mBirthDate = time(0);
|
||
|
mOnHold = false;
|
||
|
}
|
||
|
|
||
|
void
|
||
|
IdleSlave::gotInput()
|
||
|
{
|
||
|
int cmd;
|
||
15 years ago
|
TQByteArray data;
|
||
15 years ago
|
if (mConn.read( &cmd, data) == -1)
|
||
|
{
|
||
|
// Communication problem with slave.
|
||
|
kdError(7016) << "SlavePool: No communication with slave." << endl;
|
||
|
delete this;
|
||
|
}
|
||
|
else if (cmd == MSG_SLAVE_ACK)
|
||
|
{
|
||
|
delete this;
|
||
|
}
|
||
|
else if (cmd != MSG_SLAVE_STATUS)
|
||
|
{
|
||
|
kdError(7016) << "SlavePool: Unexpected data from slave." << endl;
|
||
|
delete this;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
15 years ago
|
TQDataStream stream( data, IO_ReadOnly );
|
||
15 years ago
|
pid_t pid;
|
||
15 years ago
|
TQCString protocol;
|
||
|
TQString host;
|
||
14 years ago
|
TQ_INT8 b;
|
||
15 years ago
|
stream >> pid >> protocol >> host >> b;
|
||
|
// Overload with (bool) onHold, (KURL) url.
|
||
|
if (!stream.atEnd())
|
||
|
{
|
||
|
KURL url;
|
||
|
stream >> url;
|
||
|
mOnHold = true;
|
||
|
mUrl = url;
|
||
|
}
|
||
|
|
||
|
mPid = pid;
|
||
|
mConnected = (b != 0);
|
||
|
mProtocol = protocol;
|
||
|
mHost = host;
|
||
|
emit statusUpdate(this);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void
|
||
15 years ago
|
IdleSlave::connect(const TQString &app_socket)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQByteArray data;
|
||
|
TQDataStream stream( data, IO_WriteOnly);
|
||
15 years ago
|
stream << app_socket;
|
||
|
mConn.send( CMD_SLAVE_CONNECT, data );
|
||
|
// Timeout!
|
||
|
}
|
||
|
|
||
|
void
|
||
|
IdleSlave::reparseConfiguration()
|
||
|
{
|
||
|
mConn.send( CMD_REPARSECONFIGURATION );
|
||
|
}
|
||
|
|
||
|
bool
|
||
15 years ago
|
IdleSlave::match(const TQString &protocol, const TQString &host, bool connected)
|
||
15 years ago
|
{
|
||
|
if (mOnHold) return false;
|
||
|
if (protocol != mProtocol) return false;
|
||
|
if (host.isEmpty()) return true;
|
||
|
if (host != mHost) return false;
|
||
|
if (!connected) return true;
|
||
|
if (!mConnected) return false;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool
|
||
|
IdleSlave::onHold(const KURL &url)
|
||
|
{
|
||
|
if (!mOnHold) return false;
|
||
|
return (url == mUrl);
|
||
|
}
|
||
|
|
||
|
int
|
||
|
IdleSlave::age(time_t now)
|
||
|
{
|
||
|
return (int) difftime(now, mBirthDate);
|
||
|
}
|
||
|
|
||
12 years ago
|
TDELauncher::TDELauncher(int _tdeinitSocket, bool new_startup)
|
||
12 years ago
|
// : TDEApplication( false, false ), // No Styles, No GUI
|
||
|
: TDEApplication( false, true ), // TQClipboard tries to construct a QWidget so a GUI is technically needed, even though it is not used
|
||
12 years ago
|
DCOPObject("tdelauncher"),
|
||
13 years ago
|
tdeinitSocket(_tdeinitSocket), mAutoStart( new_startup ),
|
||
15 years ago
|
dontBlockReading(false), newStartup( new_startup )
|
||
|
{
|
||
|
#ifdef Q_WS_X11
|
||
|
mCached_dpy = NULL;
|
||
|
#endif
|
||
15 years ago
|
connect(&mAutoTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(slotAutoStart()));
|
||
15 years ago
|
requestList.setAutoDelete(true);
|
||
|
mSlaveWaitRequest.setAutoDelete(true);
|
||
|
dcopClient()->setNotifications( true );
|
||
15 years ago
|
connect(dcopClient(), TQT_SIGNAL( applicationRegistered( const TQCString &)),
|
||
|
this, TQT_SLOT( slotAppRegistered( const TQCString &)));
|
||
15 years ago
|
dcopClient()->connectDCOPSignal( "DCOPServer", "", "terminateKDE()",
|
||
|
objId(), "terminateKDE()", false );
|
||
|
|
||
12 years ago
|
TQString prefix = locateLocal("socket", "tdelauncher");
|
||
13 years ago
|
KTempFile domainname(prefix, TQString::fromLatin1(".slave-socket"));
|
||
15 years ago
|
if (domainname.status() != 0)
|
||
|
{
|
||
|
// Sever error!
|
||
12 years ago
|
tqDebug("TDELauncher: Fatal error, can't create tempfile!");
|
||
15 years ago
|
::exit(1);
|
||
|
}
|
||
|
mPoolSocketName = domainname.name();
|
||
|
#ifdef __CYGWIN__
|
||
|
domainname.close();
|
||
|
domainname.unlink();
|
||
|
#endif
|
||
12 years ago
|
mPoolSocket = new TDEServerSocket(static_cast<const char*>(TQFile::encodeName(mPoolSocketName)));
|
||
|
connect(mPoolSocket, TQT_SIGNAL(accepted( TDESocket *)),
|
||
|
TQT_SLOT(acceptSlave(TDESocket *)));
|
||
15 years ago
|
|
||
15 years ago
|
connect(&mTimer, TQT_SIGNAL(timeout()), TQT_SLOT(idleTimeout()));
|
||
15 years ago
|
|
||
13 years ago
|
tdeinitNotifier = new TQSocketNotifier(tdeinitSocket, TQSocketNotifier::Read);
|
||
|
connect(tdeinitNotifier, TQT_SIGNAL( activated( int )),
|
||
15 years ago
|
this, TQT_SLOT( slotKDEInitData( int )));
|
||
13 years ago
|
tdeinitNotifier->setEnabled( true );
|
||
15 years ago
|
lastRequest = 0;
|
||
|
bProcessingQueue = false;
|
||
|
|
||
13 years ago
|
mSlaveDebug = getenv("TDE_SLAVE_DEBUG_WAIT");
|
||
15 years ago
|
if (!mSlaveDebug.isEmpty())
|
||
|
{
|
||
13 years ago
|
tqWarning("Klauncher running in slave-debug mode for slaves of protocol '%s'", mSlaveDebug.data());
|
||
15 years ago
|
}
|
||
13 years ago
|
mSlaveValgrind = getenv("TDE_SLAVE_VALGRIND");
|
||
15 years ago
|
if (!mSlaveValgrind.isEmpty())
|
||
|
{
|
||
13 years ago
|
mSlaveValgrindSkin = getenv("TDE_SLAVE_VALGRIND_SKIN");
|
||
13 years ago
|
tqWarning("Klauncher running slaves through valgrind for slaves of protocol '%s'", mSlaveValgrind.data());
|
||
15 years ago
|
}
|
||
12 years ago
|
tdelauncher_header request_header;
|
||
15 years ago
|
request_header.cmd = LAUNCHER_OK;
|
||
|
request_header.arg_length = 0;
|
||
13 years ago
|
write(tdeinitSocket, &request_header, sizeof(request_header));
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
TDELauncher::~TDELauncher()
|
||
15 years ago
|
{
|
||
|
close();
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDELauncher::close()
|
||
15 years ago
|
{
|
||
|
if (!mPoolSocketName.isEmpty())
|
||
|
{
|
||
15 years ago
|
TQCString filename = TQFile::encodeName(mPoolSocketName);
|
||
15 years ago
|
unlink(filename.data());
|
||
|
}
|
||
|
#if defined Q_WS_X11 && ! defined K_WS_QTONLY
|
||
|
//#ifdef Q_WS_X11
|
||
|
if( mCached_dpy != NULL )
|
||
|
XCloseDisplay( mCached_dpy );
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
void
|
||
12 years ago
|
TDELauncher::destruct(int exit_code)
|
||
15 years ago
|
{
|
||
12 years ago
|
if (kapp) ((TDELauncher*)kapp)->close();
|
||
15 years ago
|
// We don't delete kapp here, that's intentional.
|
||
|
::exit(exit_code);
|
||
|
}
|
||
|
|
||
|
bool
|
||
12 years ago
|
TDELauncher::process(const TQCString &fun, const TQByteArray &data,
|
||
15 years ago
|
TQCString &replyType, TQByteArray &replyData)
|
||
15 years ago
|
{
|
||
15 years ago
|
if ((fun == "exec_blind(TQCString,TQValueList<TQCString>)")
|
||
|
|| (fun == "exec_blind(TQCString,TQValueList<TQCString>,TQValueList<TQCString>,TQCString)"))
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDataStream stream(data, IO_ReadOnly);
|
||
15 years ago
|
replyType = "void";
|
||
15 years ago
|
TQCString name;
|
||
|
TQValueList<TQCString> arg_list;
|
||
|
TQCString startup_id = "0";
|
||
|
TQValueList<TQCString> envs;
|
||
15 years ago
|
stream >> name >> arg_list;
|
||
15 years ago
|
if( fun == "exec_blind(TQCString,TQValueList<TQCString>,TQValueList<TQCString>,TQCString)" )
|
||
15 years ago
|
stream >> envs >> startup_id;
|
||
12 years ago
|
kdDebug(7016) << "TDELauncher: Got exec_blind('" << name << "', ...)" << endl;
|
||
15 years ago
|
exec_blind( name, arg_list, envs, startup_id);
|
||
|
return true;
|
||
|
}
|
||
15 years ago
|
if ((fun == "start_service_by_name(TQString,TQStringList)") ||
|
||
|
(fun == "start_service_by_desktop_path(TQString,TQStringList)")||
|
||
|
(fun == "start_service_by_desktop_name(TQString,TQStringList)")||
|
||
13 years ago
|
(fun == "tdeinit_exec(TQString,TQStringList)") ||
|
||
|
(fun == "tdeinit_exec_wait(TQString,TQStringList)") ||
|
||
15 years ago
|
(fun == "start_service_by_name(TQString,TQStringList,TQValueList<TQCString>,TQCString)") ||
|
||
|
(fun == "start_service_by_desktop_path(TQString,TQStringList,TQValueList<TQCString>,TQCString)")||
|
||
|
(fun == "start_service_by_desktop_name(TQString,TQStringList,TQValueList<TQCString>,TQCString)") ||
|
||
|
(fun == "start_service_by_name(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)") ||
|
||
|
(fun == "start_service_by_desktop_path(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)")||
|
||
|
(fun == "start_service_by_desktop_name(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)") ||
|
||
13 years ago
|
(fun == "tdeinit_exec(TQString,TQStringList,TQValueList<TQCString>)") ||
|
||
|
(fun == "tdeinit_exec_wait(TQString,TQStringList,TQValueList<TQCString>)") ||
|
||
|
(fun == "tdeinit_exec(TQString,TQStringList,TQValueList<TQCString>,TQCString)") ||
|
||
|
(fun == "tdeinit_exec_wait(TQString,TQStringList,TQValueList<TQCString>,TQCString)"))
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDataStream stream(data, IO_ReadOnly);
|
||
15 years ago
|
bool bNoWait = false;
|
||
15 years ago
|
TQString serviceName;
|
||
|
TQStringList urls;
|
||
|
TQValueList<TQCString> envs;
|
||
|
TQCString startup_id = "";
|
||
15 years ago
|
DCOPresult.result = -1;
|
||
|
DCOPresult.dcopName = 0;
|
||
15 years ago
|
DCOPresult.error = TQString::null;
|
||
15 years ago
|
DCOPresult.pid = 0;
|
||
|
stream >> serviceName >> urls;
|
||
15 years ago
|
if ((fun == "start_service_by_name(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)") ||
|
||
|
(fun == "start_service_by_desktop_path(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)")||
|
||
|
(fun == "start_service_by_desktop_name(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)"))
|
||
15 years ago
|
stream >> envs >> startup_id >> bNoWait;
|
||
15 years ago
|
else if ((fun == "start_service_by_name(TQString,TQStringList,TQValueList<TQCString>,TQCString)") ||
|
||
|
(fun == "start_service_by_desktop_path(TQString,TQStringList,TQValueList<TQCString>,TQCString)")||
|
||
|
(fun == "start_service_by_desktop_name(TQString,TQStringList,TQValueList<TQCString>,TQCString)"))
|
||
15 years ago
|
stream >> envs >> startup_id;
|
||
13 years ago
|
else if ((fun == "tdeinit_exec(TQString,TQStringList,TQValueList<TQCString>)") ||
|
||
|
(fun == "tdeinit_exec_wait(TQString,TQStringList,TQValueList<TQCString>)"))
|
||
15 years ago
|
stream >> envs;
|
||
13 years ago
|
else if ((fun == "tdeinit_exec(TQString,TQStringList,TQValueList<TQCString>,TQCString)") ||
|
||
|
(fun == "tdeinit_exec_wait(TQString,TQStringList,TQValueList<TQCString>,TQCString)"))
|
||
15 years ago
|
stream >> envs >> startup_id;
|
||
|
bool finished;
|
||
|
if (strncmp(fun, "start_service_by_name(", 22) == 0)
|
||
|
{
|
||
12 years ago
|
kdDebug(7016) << "TDELauncher: Got start_service_by_name('" << serviceName << "', ...)" << endl;
|
||
15 years ago
|
finished = start_service_by_name(serviceName, urls, envs, startup_id, bNoWait);
|
||
|
}
|
||
|
else if (strncmp(fun, "start_service_by_desktop_path(", 30) == 0)
|
||
|
{
|
||
12 years ago
|
kdDebug(7016) << "TDELauncher: Got start_service_by_desktop_path('" << serviceName << "', ...)" << endl;
|
||
15 years ago
|
finished = start_service_by_desktop_path(serviceName, urls, envs, startup_id, bNoWait);
|
||
|
}
|
||
|
else if (strncmp(fun, "start_service_by_desktop_name(", 30) == 0)
|
||
|
{
|
||
12 years ago
|
kdDebug(7016) << "TDELauncher: Got start_service_by_desktop_name('" << serviceName << "', ...)" << endl;
|
||
15 years ago
|
finished = start_service_by_desktop_name(serviceName, urls, envs, startup_id, bNoWait );
|
||
|
}
|
||
13 years ago
|
else if ((fun == "tdeinit_exec(TQString,TQStringList)")
|
||
|
|| (fun == "tdeinit_exec(TQString,TQStringList,TQValueList<TQCString>)")
|
||
|
|| (fun == "tdeinit_exec(TQString,TQStringList,TQValueList<TQCString>,TQCString)"))
|
||
15 years ago
|
{
|
||
12 years ago
|
kdDebug(7016) << "TDELauncher: Got tdeinit_exec('" << serviceName << "', ...)" << endl;
|
||
13 years ago
|
finished = tdeinit_exec(serviceName, urls, envs, startup_id, false);
|
||
15 years ago
|
}
|
||
|
else
|
||
|
{
|
||
12 years ago
|
kdDebug(7016) << "TDELauncher: Got tdeinit_exec_wait('" << serviceName << "', ...)" << endl;
|
||
13 years ago
|
finished = tdeinit_exec(serviceName, urls, envs, startup_id, true);
|
||
15 years ago
|
}
|
||
|
if (!finished)
|
||
|
{
|
||
|
replyType = "serviceResult";
|
||
15 years ago
|
TQDataStream stream2(replyData, IO_WriteOnly);
|
||
15 years ago
|
stream2 << DCOPresult.result << DCOPresult.dcopName << DCOPresult.error << DCOPresult.pid;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
15 years ago
|
else if (fun == "requestSlave(TQString,TQString,TQString)")
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDataStream stream(data, IO_ReadOnly);
|
||
|
TQString protocol;
|
||
|
TQString host;
|
||
|
TQString app_socket;
|
||
15 years ago
|
stream >> protocol >> host >> app_socket;
|
||
15 years ago
|
replyType = "TQString";
|
||
|
TQString error;
|
||
15 years ago
|
pid_t pid = requestSlave(protocol, host, app_socket, error);
|
||
15 years ago
|
TQDataStream stream2(replyData, IO_WriteOnly);
|
||
15 years ago
|
stream2 << pid << error;
|
||
|
return true;
|
||
|
}
|
||
15 years ago
|
else if (fun == "requestHoldSlave(KURL,TQString)")
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDataStream stream(data, IO_ReadOnly);
|
||
15 years ago
|
KURL url;
|
||
15 years ago
|
TQString app_socket;
|
||
15 years ago
|
stream >> url >> app_socket;
|
||
|
replyType = "pid_t";
|
||
|
pid_t pid = requestHoldSlave(url, app_socket);
|
||
15 years ago
|
TQDataStream stream2(replyData, IO_WriteOnly);
|
||
15 years ago
|
stream2 << pid;
|
||
|
return true;
|
||
|
}
|
||
|
else if (fun == "waitForSlave(pid_t)")
|
||
|
{
|
||
15 years ago
|
TQDataStream stream(data, IO_ReadOnly);
|
||
15 years ago
|
pid_t pid;
|
||
|
stream >> pid;
|
||
|
waitForSlave(pid);
|
||
|
replyType = "void";
|
||
|
return true;
|
||
|
|
||
|
}
|
||
15 years ago
|
else if (fun == "setLaunchEnv(TQCString,TQCString)")
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDataStream stream(data, IO_ReadOnly);
|
||
|
TQCString name;
|
||
|
TQCString value;
|
||
15 years ago
|
stream >> name >> value;
|
||
|
setLaunchEnv(name, value);
|
||
|
replyType = "void";
|
||
|
return true;
|
||
|
}
|
||
|
else if (fun == "reparseConfiguration()")
|
||
|
{
|
||
12 years ago
|
TDEGlobal::config()->reparseConfiguration();
|
||
12 years ago
|
kdDebug(7016) << "TDELauncher::process : reparseConfiguration" << endl;
|
||
15 years ago
|
KProtocolManager::reparseConfiguration();
|
||
|
IdleSlave *slave;
|
||
|
for(slave = mSlaveList.first(); slave; slave = mSlaveList.next())
|
||
|
slave->reparseConfiguration();
|
||
|
replyType = "void";
|
||
|
return true;
|
||
|
}
|
||
|
else if (fun == "terminateKDE()")
|
||
|
{
|
||
|
::signal( SIGHUP, SIG_IGN);
|
||
|
::signal( SIGTERM, SIG_IGN);
|
||
12 years ago
|
kdDebug() << "TDELauncher::process ---> terminateKDE" << endl;
|
||
12 years ago
|
tdelauncher_header request_header;
|
||
15 years ago
|
request_header.cmd = LAUNCHER_TERMINATE_KDE;
|
||
|
request_header.arg_length = 0;
|
||
13 years ago
|
write(tdeinitSocket, &request_header, sizeof(request_header));
|
||
15 years ago
|
destruct(0);
|
||
|
}
|
||
|
else if (fun == "autoStart()")
|
||
|
{
|
||
12 years ago
|
kdDebug() << "TDELauncher::process ---> autoStart" << endl;
|
||
15 years ago
|
autoStart(1);
|
||
|
replyType = "void";
|
||
|
return true;
|
||
|
}
|
||
|
else if (fun == "autoStart(int)")
|
||
|
{
|
||
12 years ago
|
kdDebug() << "TDELauncher::process ---> autoStart(int)" << endl;
|
||
15 years ago
|
TQDataStream stream(data, IO_ReadOnly);
|
||
15 years ago
|
int phase;
|
||
|
stream >> phase;
|
||
|
autoStart(phase);
|
||
|
replyType = "void";
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
if (DCOPObject::process(fun, data, replyType, replyData))
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
kdWarning(7016) << "Got unknown DCOP function: " << fun << endl;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
QCStringList
|
||
12 years ago
|
TDELauncher::interfaces()
|
||
15 years ago
|
{
|
||
|
QCStringList ifaces = DCOPObject::interfaces();
|
||
12 years ago
|
ifaces += "TDELauncher";
|
||
15 years ago
|
return ifaces;
|
||
|
}
|
||
|
|
||
|
QCStringList
|
||
12 years ago
|
TDELauncher::functions()
|
||
15 years ago
|
{
|
||
|
QCStringList funcs = DCOPObject::functions();
|
||
15 years ago
|
funcs << "void exec_blind(TQCString,TQValueList<TQCString>)";
|
||
|
funcs << "void exec_blind(TQCString,TQValueList<TQCString>,TQValueList<TQCString>,TQCString)";
|
||
|
funcs << "serviceResult start_service_by_name(TQString,TQStringList)";
|
||
|
funcs << "serviceResult start_service_by_desktop_path(TQString,TQStringList)";
|
||
|
funcs << "serviceResult start_service_by_desktop_name(TQString,TQStringList)";
|
||
13 years ago
|
funcs << "serviceResult tdeinit_exec(TQString,TQStringList)";
|
||
|
funcs << "serviceResult tdeinit_exec_wait(TQString,TQStringList)";
|
||
15 years ago
|
funcs << "serviceResult start_service_by_name(TQString,TQStringList,TQValueList<TQCString>,TQCString)";
|
||
|
funcs << "serviceResult start_service_by_desktop_path(TQString,TQStringList,TQValueList<TQCString>,TQCString)";
|
||
|
funcs << "serviceResult start_service_by_desktop_name(TQString,TQStringList,TQValueList<TQCString>,TQCString)";
|
||
|
funcs << "serviceResult start_service_by_name(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)";
|
||
|
funcs << "serviceResult start_service_by_desktop_path(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)";
|
||
|
funcs << "serviceResult start_service_by_desktop_name(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)";
|
||
13 years ago
|
funcs << "serviceResult tdeinit_exec(TQString,TQStringList,TQValueList<TQCString>)";
|
||
|
funcs << "serviceResult tdeinit_exec_wait(TQString,TQStringList,TQValueList<TQCString>)";
|
||
15 years ago
|
funcs << "TQString requestSlave(TQString,TQString,TQString)";
|
||
|
funcs << "pid_t requestHoldSlave(KURL,TQString)";
|
||
15 years ago
|
funcs << "void waitForSlave(pid_t)";
|
||
15 years ago
|
funcs << "void setLaunchEnv(TQCString,TQCString)";
|
||
15 years ago
|
funcs << "void reparseConfiguration()";
|
||
|
// funcs << "void terminateKDE()";
|
||
|
funcs << "void autoStart()";
|
||
|
funcs << "void autoStart(int)";
|
||
|
return funcs;
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDELauncher::setLaunchEnv(const TQCString &name, const TQCString &_value)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQCString value(_value);
|
||
15 years ago
|
if (value.isNull())
|
||
|
value = "";
|
||
12 years ago
|
tdelauncher_header request_header;
|
||
15 years ago
|
TQByteArray requestData(name.length()+value.length()+2);
|
||
15 years ago
|
memcpy(requestData.data(), name.data(), name.length()+1);
|
||
|
memcpy(requestData.data()+name.length()+1, value.data(), value.length()+1);
|
||
|
request_header.cmd = LAUNCHER_SETENV;
|
||
|
request_header.arg_length = requestData.size();
|
||
13 years ago
|
write(tdeinitSocket, &request_header, sizeof(request_header));
|
||
|
write(tdeinitSocket, requestData.data(), request_header.arg_length);
|
||
15 years ago
|
}
|
||
|
|
||
|
/*
|
||
|
* Read 'len' bytes from 'sock' into buffer.
|
||
|
* returns -1 on failure, 0 on no data.
|
||
|
*/
|
||
|
static int
|
||
|
read_socket(int sock, char *buffer, int len)
|
||
|
{
|
||
|
ssize_t result;
|
||
|
int bytes_left = len;
|
||
|
while ( bytes_left > 0)
|
||
|
{
|
||
|
result = read(sock, buffer, bytes_left);
|
||
|
if (result > 0)
|
||
|
{
|
||
|
buffer += result;
|
||
|
bytes_left -= result;
|
||
|
}
|
||
|
else if (result == 0)
|
||
|
return -1;
|
||
|
else if ((result == -1) && (errno != EINTR))
|
||
|
return -1;
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
|
||
|
void
|
||
12 years ago
|
TDELauncher::slotKDEInitData(int)
|
||
15 years ago
|
{
|
||
12 years ago
|
tdelauncher_header request_header;
|
||
15 years ago
|
TQByteArray requestData;
|
||
15 years ago
|
if( dontBlockReading )
|
||
|
{
|
||
|
// in case we get a request to start an application and data arrive
|
||
13 years ago
|
// to tdeinitSocket at the same time, requestStart() will already
|
||
15 years ago
|
// call slotKDEInitData(), so we must check there's still something
|
||
|
// to read, otherwise this would block
|
||
|
fd_set in;
|
||
|
timeval tm = { 0, 0 };
|
||
|
FD_ZERO ( &in );
|
||
13 years ago
|
FD_SET( tdeinitSocket, &in );
|
||
|
select( tdeinitSocket + 1, &in, 0, 0, &tm );
|
||
|
if( !FD_ISSET( tdeinitSocket, &in ))
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
dontBlockReading = false;
|
||
13 years ago
|
int result = read_socket(tdeinitSocket, (char *) &request_header,
|
||
15 years ago
|
sizeof( request_header));
|
||
|
if (result == -1)
|
||
|
{
|
||
|
kdDebug() << "Exiting on read_socket errno: " << errno << endl;
|
||
|
::signal( SIGHUP, SIG_IGN);
|
||
|
::signal( SIGTERM, SIG_IGN);
|
||
|
destruct(255); // Exit!
|
||
|
}
|
||
|
requestData.resize(request_header.arg_length);
|
||
13 years ago
|
result = read_socket(tdeinitSocket, (char *) requestData.data(),
|
||
15 years ago
|
request_header.arg_length);
|
||
|
|
||
|
if (request_header.cmd == LAUNCHER_DIED)
|
||
|
{
|
||
|
long *request_data;
|
||
|
request_data = (long *) requestData.data();
|
||
|
processDied(request_data[0], request_data[1]);
|
||
|
return;
|
||
|
}
|
||
|
if (lastRequest && (request_header.cmd == LAUNCHER_OK))
|
||
|
{
|
||
|
long *request_data;
|
||
|
request_data = (long *) requestData.data();
|
||
|
lastRequest->pid = (pid_t) (*request_data);
|
||
|
kdDebug(7016) << lastRequest->name << " (pid " << lastRequest->pid <<
|
||
|
") up and running." << endl;
|
||
|
switch(lastRequest->dcop_service_type)
|
||
|
{
|
||
|
case KService::DCOP_None:
|
||
|
{
|
||
12 years ago
|
lastRequest->status = TDELaunchRequest::Running;
|
||
15 years ago
|
break;
|
||
|
}
|
||
|
|
||
|
case KService::DCOP_Unique:
|
||
|
{
|
||
12 years ago
|
lastRequest->status = TDELaunchRequest::Launching;
|
||
15 years ago
|
break;
|
||
|
}
|
||
|
|
||
|
case KService::DCOP_Wait:
|
||
|
{
|
||
12 years ago
|
lastRequest->status = TDELaunchRequest::Launching;
|
||
15 years ago
|
break;
|
||
|
}
|
||
|
|
||
|
case KService::DCOP_Multi:
|
||
|
{
|
||
12 years ago
|
lastRequest->status = TDELaunchRequest::Launching;
|
||
15 years ago
|
break;
|
||
|
}
|
||
|
}
|
||
|
lastRequest = 0;
|
||
|
return;
|
||
|
}
|
||
|
if (lastRequest && (request_header.cmd == LAUNCHER_ERROR))
|
||
|
{
|
||
12 years ago
|
lastRequest->status = TDELaunchRequest::Error;
|
||
15 years ago
|
if (!requestData.isEmpty())
|
||
15 years ago
|
lastRequest->errorMsg = TQString::fromUtf8((char *) requestData.data());
|
||
15 years ago
|
lastRequest = 0;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
kdWarning(7016) << "Unexpected command from KDEInit (" << (unsigned int) request_header.cmd
|
||
|
<< ")" << endl;
|
||
|
}
|
||
|
|
||
|
void
|
||
12 years ago
|
TDELauncher::processDied(pid_t pid, long /* exitStatus */)
|
||
15 years ago
|
{
|
||
12 years ago
|
TDELaunchRequest *request = requestList.first();
|
||
15 years ago
|
for(; request; request = requestList.next())
|
||
|
{
|
||
|
if (request->pid == pid)
|
||
|
{
|
||
|
if (request->dcop_service_type == KService::DCOP_Wait)
|
||
12 years ago
|
request->status = TDELaunchRequest::Done;
|
||
15 years ago
|
else if ((request->dcop_service_type == KService::DCOP_Unique) &&
|
||
|
(dcopClient()->isApplicationRegistered(request->dcop_name)))
|
||
12 years ago
|
request->status = TDELaunchRequest::Running;
|
||
15 years ago
|
else
|
||
12 years ago
|
request->status = TDELaunchRequest::Error;
|
||
15 years ago
|
requestDone(request);
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void
|
||
12 years ago
|
TDELauncher::slotAppRegistered(const TQCString &appId)
|
||
15 years ago
|
{
|
||
|
const char *cAppId = appId.data();
|
||
|
if (!cAppId) return;
|
||
|
|
||
12 years ago
|
TDELaunchRequest *request = requestList.first();
|
||
|
TDELaunchRequest *nextRequest;
|
||
15 years ago
|
for(; request; request = nextRequest)
|
||
|
{
|
||
|
nextRequest = requestList.next();
|
||
12 years ago
|
if (request->status != TDELaunchRequest::Launching)
|
||
15 years ago
|
continue;
|
||
|
|
||
|
// For unique services check the requested service name first
|
||
|
if ((request->dcop_service_type == KService::DCOP_Unique) &&
|
||
|
((appId == request->dcop_name) ||
|
||
|
dcopClient()->isApplicationRegistered(request->dcop_name)))
|
||
|
{
|
||
12 years ago
|
request->status = TDELaunchRequest::Running;
|
||
15 years ago
|
requestDone(request);
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
const char *rAppId = request->dcop_name.data();
|
||
|
if (!rAppId) continue;
|
||
|
|
||
|
int l = strlen(rAppId);
|
||
|
if ((strncmp(rAppId, cAppId, l) == 0) &&
|
||
|
((cAppId[l] == '\0') || (cAppId[l] == '-')))
|
||
|
{
|
||
|
request->dcop_name = appId;
|
||
12 years ago
|
request->status = TDELaunchRequest::Running;
|
||
15 years ago
|
requestDone(request);
|
||
|
continue;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void
|
||
12 years ago
|
TDELauncher::autoStart(int phase)
|
||
15 years ago
|
{
|
||
|
if( mAutoStart.phase() >= phase )
|
||
|
return;
|
||
|
mAutoStart.setPhase(phase);
|
||
|
if( newStartup )
|
||
|
{
|
||
|
if (phase == 0)
|
||
|
mAutoStart.loadAutoStartList();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (phase == 1)
|
||
|
mAutoStart.loadAutoStartList();
|
||
|
}
|
||
|
mAutoTimer.start(0, true);
|
||
|
}
|
||
|
|
||
|
void
|
||
12 years ago
|
TDELauncher::slotAutoStart()
|
||
15 years ago
|
{
|
||
|
KService::Ptr s;
|
||
|
do
|
||
|
{
|
||
15 years ago
|
TQString service = mAutoStart.startService();
|
||
15 years ago
|
if (service.isEmpty())
|
||
|
{
|
||
|
// Done
|
||
|
if( !mAutoStart.phaseDone())
|
||
|
{
|
||
|
mAutoStart.setPhaseDone();
|
||
|
// Emit signal
|
||
|
if( newStartup )
|
||
|
{
|
||
15 years ago
|
TQCString autoStartSignal;
|
||
15 years ago
|
autoStartSignal.sprintf( "autoStart%dDone()", mAutoStart.phase());
|
||
15 years ago
|
emitDCOPSignal(autoStartSignal, TQByteArray());
|
||
15 years ago
|
}
|
||
|
else
|
||
|
{
|
||
15 years ago
|
TQCString autoStartSignal( "autoStartDone()" );
|
||
15 years ago
|
int phase = mAutoStart.phase();
|
||
|
if ( phase > 1 )
|
||
|
autoStartSignal.sprintf( "autoStart%dDone()", phase );
|
||
15 years ago
|
emitDCOPSignal(autoStartSignal, TQByteArray());
|
||
15 years ago
|
}
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
s = new KService(service);
|
||
|
}
|
||
15 years ago
|
while (!start_service(s, TQStringList(), TQValueList<TQCString>(), "0", false, true));
|
||
14 years ago
|
// Loop till we find a service that we can start.
|
||
15 years ago
|
}
|
||
|
|
||
|
void
|
||
12 years ago
|
TDELauncher::requestDone(TDELaunchRequest *request)
|
||
15 years ago
|
{
|
||
12 years ago
|
if ((request->status == TDELaunchRequest::Running) ||
|
||
|
(request->status == TDELaunchRequest::Done))
|
||
15 years ago
|
{
|
||
|
DCOPresult.result = 0;
|
||
|
DCOPresult.dcopName = request->dcop_name;
|
||
15 years ago
|
DCOPresult.error = TQString::null;
|
||
15 years ago
|
DCOPresult.pid = request->pid;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
DCOPresult.result = 1;
|
||
|
DCOPresult.dcopName = "";
|
||
14 years ago
|
DCOPresult.error = i18n("KDEInit could not launch '%1'.").arg(TQString(request->name));
|
||
15 years ago
|
if (!request->errorMsg.isEmpty())
|
||
|
DCOPresult.error += ":\n" + request->errorMsg;
|
||
|
DCOPresult.pid = 0;
|
||
|
|
||
|
#if defined Q_WS_X11 && ! defined K_WS_QTONLY
|
||
|
//#ifdef Q_WS_X11
|
||
|
if (!request->startup_dpy.isEmpty())
|
||
|
{
|
||
|
Display* dpy = NULL;
|
||
|
if( (mCached_dpy != NULL) &&
|
||
|
(request->startup_dpy == XDisplayString( mCached_dpy )))
|
||
|
dpy = mCached_dpy;
|
||
|
if( dpy == NULL )
|
||
|
dpy = XOpenDisplay( request->startup_dpy );
|
||
|
if( dpy )
|
||
|
{
|
||
12 years ago
|
TDEStartupInfoId id;
|
||
15 years ago
|
id.initId( request->startup_id );
|
||
12 years ago
|
TDEStartupInfo::sendFinishX( dpy, id );
|
||
15 years ago
|
if( mCached_dpy != dpy && mCached_dpy != NULL )
|
||
|
XCloseDisplay( mCached_dpy );
|
||
|
mCached_dpy = dpy;
|
||
|
}
|
||
|
}
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
if (request->autoStart)
|
||
|
{
|
||
|
mAutoTimer.start(0, true);
|
||
|
}
|
||
|
|
||
|
if (request->transaction)
|
||
|
{
|
||
15 years ago
|
TQByteArray replyData;
|
||
|
TQCString replyType;
|
||
15 years ago
|
replyType = "serviceResult";
|
||
15 years ago
|
TQDataStream stream2(replyData, IO_WriteOnly);
|
||
15 years ago
|
stream2 << DCOPresult.result << DCOPresult.dcopName << DCOPresult.error << DCOPresult.pid;
|
||
|
dcopClient()->endTransaction( request->transaction,
|
||
|
replyType, replyData);
|
||
|
}
|
||
|
requestList.removeRef( request );
|
||
|
}
|
||
|
|
||
|
void
|
||
12 years ago
|
TDELauncher::requestStart(TDELaunchRequest *request)
|
||
15 years ago
|
{
|
||
|
requestList.append( request );
|
||
13 years ago
|
// Send request to tdeinit.
|
||
12 years ago
|
tdelauncher_header request_header;
|
||
15 years ago
|
TQByteArray requestData;
|
||
15 years ago
|
int length = 0;
|
||
|
length += sizeof(long); // Nr of. Args
|
||
|
length += request->name.length() + 1; // Cmd
|
||
15 years ago
|
for(TQValueList<TQCString>::Iterator it = request->arg_list.begin();
|
||
15 years ago
|
it != request->arg_list.end();
|
||
|
it++)
|
||
|
{
|
||
|
length += (*it).length() + 1; // Args...
|
||
|
}
|
||
|
length += sizeof(long); // Nr of. envs
|
||
15 years ago
|
for(TQValueList<TQCString>::ConstIterator it = request->envs.begin();
|
||
15 years ago
|
it != request->envs.end();
|
||
|
it++)
|
||
|
{
|
||
|
length += (*it).length() + 1; // Envs...
|
||
|
}
|
||
|
length += sizeof( long ); // avoid_loops
|
||
|
#ifdef Q_WS_X11
|
||
|
bool startup_notify = !request->startup_id.isNull() && request->startup_id != "0";
|
||
|
if( startup_notify )
|
||
|
length += request->startup_id.length() + 1;
|
||
|
#endif
|
||
|
if (!request->cwd.isEmpty())
|
||
|
length += request->cwd.length() + 1;
|
||
|
|
||
|
requestData.resize( length );
|
||
|
|
||
|
char *p = requestData.data();
|
||
|
long l = request->arg_list.count()+1;
|
||
|
memcpy(p, &l, sizeof(long));
|
||
|
p += sizeof(long);
|
||
|
strcpy(p, request->name.data());
|
||
|
p += strlen(p) + 1;
|
||
15 years ago
|
for(TQValueList<TQCString>::Iterator it = request->arg_list.begin();
|
||
15 years ago
|
it != request->arg_list.end();
|
||
|
it++)
|
||
|
{
|
||
|
strcpy(p, (*it).data());
|
||
|
p += strlen(p) + 1;
|
||
|
}
|
||
|
l = request->envs.count();
|
||
|
memcpy(p, &l, sizeof(long));
|
||
|
p += sizeof(long);
|
||
15 years ago
|
for(TQValueList<TQCString>::ConstIterator it = request->envs.begin();
|
||
15 years ago
|
it != request->envs.end();
|
||
|
it++)
|
||
|
{
|
||
|
strcpy(p, (*it).data());
|
||
|
p += strlen(p) + 1;
|
||
|
}
|
||
|
l = 0; // avoid_loops, always false here
|
||
|
memcpy(p, &l, sizeof(long));
|
||
|
p += sizeof(long);
|
||
|
#ifdef Q_WS_X11
|
||
|
if( startup_notify )
|
||
|
{
|
||
|
strcpy(p, request->startup_id.data());
|
||
|
p += strlen( p ) + 1;
|
||
|
}
|
||
|
#endif
|
||
|
if (!request->cwd.isEmpty())
|
||
|
{
|
||
|
strcpy(p, request->cwd.data());
|
||
|
p += strlen( p ) + 1;
|
||
|
}
|
||
|
#ifdef Q_WS_X11
|
||
|
request_header.cmd = startup_notify ? LAUNCHER_EXT_EXEC : LAUNCHER_EXEC_NEW;
|
||
|
#else
|
||
|
request_header.cmd = LAUNCHER_EXEC_NEW;
|
||
|
#endif
|
||
|
request_header.arg_length = length;
|
||
13 years ago
|
write(tdeinitSocket, &request_header, sizeof(request_header));
|
||
|
write(tdeinitSocket, requestData.data(), request_header.arg_length);
|
||
15 years ago
|
|
||
|
// Wait for pid to return.
|
||
|
lastRequest = request;
|
||
|
dontBlockReading = false;
|
||
|
do {
|
||
13 years ago
|
slotKDEInitData( tdeinitSocket );
|
||
15 years ago
|
}
|
||
|
while (lastRequest != 0);
|
||
|
dontBlockReading = true;
|
||
|
}
|
||
|
|
||
|
void
|
||
12 years ago
|
TDELauncher::exec_blind( const TQCString &name, const TQValueList<TQCString> &arg_list,
|
||
15 years ago
|
const TQValueList<TQCString> &envs, const TQCString& startup_id )
|
||
15 years ago
|
{
|
||
12 years ago
|
TDELaunchRequest *request = new TDELaunchRequest;
|
||
15 years ago
|
request->autoStart = false;
|
||
|
request->name = name;
|
||
|
request->arg_list = arg_list;
|
||
|
request->dcop_name = 0;
|
||
|
request->dcop_service_type = KService::DCOP_None;
|
||
|
request->pid = 0;
|
||
12 years ago
|
request->status = TDELaunchRequest::Launching;
|
||
15 years ago
|
request->transaction = 0; // No confirmation is send
|
||
|
request->envs = envs;
|
||
|
// Find service, if any - strip path if needed
|
||
13 years ago
|
KService::Ptr service = KService::serviceByDesktopName( name.mid( name.findRev( '/' ) + 1 ));
|
||
15 years ago
|
if (service != NULL)
|
||
|
send_service_startup_info( request, service,
|
||
15 years ago
|
startup_id, TQValueList< TQCString >());
|
||
15 years ago
|
else // no .desktop file, no startup info
|
||
|
cancel_service_startup_info( request, startup_id, envs );
|
||
|
|
||
|
requestStart(request);
|
||
|
// We don't care about this request any longer....
|
||
|
requestDone(request);
|
||
|
}
|
||
|
|
||
|
|
||
|
bool
|
||
12 years ago
|
TDELauncher::start_service_by_name(const TQString &serviceName, const TQStringList &urls,
|
||
15 years ago
|
const TQValueList<TQCString> &envs, const TQCString& startup_id, bool blind)
|
||
15 years ago
|
{
|
||
|
KService::Ptr service = 0;
|
||
|
// Find service
|
||
|
service = KService::serviceByName(serviceName);
|
||
|
if (!service)
|
||
|
{
|
||
|
DCOPresult.result = ENOENT;
|
||
14 years ago
|
DCOPresult.error = i18n("Could not find service '%1'.").arg(serviceName);
|
||
15 years ago
|
cancel_service_startup_info( NULL, startup_id, envs ); // cancel it if any
|
||
|
return false;
|
||
|
}
|
||
|
return start_service(service, urls, envs, startup_id, blind);
|
||
|
}
|
||
|
|
||
|
bool
|
||
12 years ago
|
TDELauncher::start_service_by_desktop_path(const TQString &serviceName, const TQStringList &urls,
|
||
15 years ago
|
const TQValueList<TQCString> &envs, const TQCString& startup_id, bool blind)
|
||
15 years ago
|
{
|
||
|
KService::Ptr service = 0;
|
||
|
// Find service
|
||
|
if (serviceName[0] == '/')
|
||
|
{
|
||
|
// Full path
|
||
|
service = new KService(serviceName);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
service = KService::serviceByDesktopPath(serviceName);
|
||
|
}
|
||
|
if (!service)
|
||
|
{
|
||
|
DCOPresult.result = ENOENT;
|
||
14 years ago
|
DCOPresult.error = i18n("Could not find service '%1'.").arg(serviceName);
|
||
15 years ago
|
cancel_service_startup_info( NULL, startup_id, envs ); // cancel it if any
|
||
|
return false;
|
||
|
}
|
||
|
return start_service(service, urls, envs, startup_id, blind);
|
||
|
}
|
||
|
|
||
|
bool
|
||
12 years ago
|
TDELauncher::start_service_by_desktop_name(const TQString &serviceName, const TQStringList &urls,
|
||
15 years ago
|
const TQValueList<TQCString> &envs, const TQCString& startup_id, bool blind)
|
||
15 years ago
|
{
|
||
|
KService::Ptr service = 0;
|
||
|
// Find service
|
||
|
service = KService::serviceByDesktopName(serviceName);
|
||
|
if (!service)
|
||
|
{
|
||
|
DCOPresult.result = ENOENT;
|
||
14 years ago
|
DCOPresult.error = i18n("Could not find service '%1'.").arg(serviceName);
|
||
15 years ago
|
cancel_service_startup_info( NULL, startup_id, envs ); // cancel it if any
|
||
|
return false;
|
||
|
}
|
||
|
return start_service(service, urls, envs, startup_id, blind);
|
||
|
}
|
||
|
|
||
|
bool
|
||
12 years ago
|
TDELauncher::start_service(KService::Ptr service, const TQStringList &_urls,
|
||
15 years ago
|
const TQValueList<TQCString> &envs, const TQCString& startup_id, bool blind, bool autoStart)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQStringList urls = _urls;
|
||
15 years ago
|
if (!service->isValid())
|
||
|
{
|
||
|
DCOPresult.result = ENOEXEC;
|
||
|
DCOPresult.error = i18n("Service '%1' is malformatted.").arg(service->desktopEntryPath());
|
||
|
cancel_service_startup_info( NULL, startup_id, envs ); // cancel it if any
|
||
|
return false;
|
||
|
}
|
||
12 years ago
|
TDELaunchRequest *request = new TDELaunchRequest;
|
||
15 years ago
|
request->autoStart = autoStart;
|
||
|
|
||
|
if ((urls.count() > 1) && !service->allowMultipleFiles())
|
||
|
{
|
||
|
// We need to launch the application N times. That sucks.
|
||
|
// We ignore the result for application 2 to N.
|
||
|
// For the first file we launch the application in the
|
||
|
// usual way. The reported result is based on this
|
||
|
// application.
|
||
15 years ago
|
TQStringList::ConstIterator it = urls.begin();
|
||
15 years ago
|
for(++it;
|
||
|
it != urls.end();
|
||
|
++it)
|
||
|
{
|
||
15 years ago
|
TQStringList singleUrl;
|
||
15 years ago
|
singleUrl.append(*it);
|
||
15 years ago
|
TQCString startup_id2 = startup_id;
|
||
15 years ago
|
if( !startup_id2.isEmpty() && startup_id2 != "0" )
|
||
|
startup_id2 = "0"; // can't use the same startup_id several times
|
||
|
start_service( service, singleUrl, envs, startup_id2, true);
|
||
|
}
|
||
15 years ago
|
TQString firstURL = *(urls.begin());
|
||
15 years ago
|
urls.clear();
|
||
|
urls.append(firstURL);
|
||
|
}
|
||
|
createArgs(request, service, urls);
|
||
|
|
||
|
// We must have one argument at least!
|
||
|
if (!request->arg_list.count())
|
||
|
{
|
||
|
DCOPresult.result = ENOEXEC;
|
||
|
DCOPresult.error = i18n("Service '%1' is malformatted.").arg(service->desktopEntryPath());
|
||
|
delete request;
|
||
|
cancel_service_startup_info( NULL, startup_id, envs );
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
request->name = request->arg_list.first();
|
||
|
request->arg_list.remove(request->arg_list.begin());
|
||
|
|
||
|
request->dcop_service_type = service->DCOPServiceType();
|
||
|
|
||
|
if ((request->dcop_service_type == KService::DCOP_Unique) ||
|
||
|
(request->dcop_service_type == KService::DCOP_Multi))
|
||
|
{
|
||
15 years ago
|
TQVariant v = service->property("X-DCOP-ServiceName");
|
||
15 years ago
|
if (v.isValid())
|
||
|
request->dcop_name = v.toString().utf8();
|
||
|
if (request->dcop_name.isEmpty())
|
||
|
{
|
||
15 years ago
|
request->dcop_name = TQFile::encodeName(KRun::binaryName(service->exec(), true));
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
request->pid = 0;
|
||
|
request->transaction = 0;
|
||
|
request->envs = envs;
|
||
|
send_service_startup_info( request, service, startup_id, envs );
|
||
|
|
||
|
// Request will be handled later.
|
||
|
if (!blind && !autoStart)
|
||
|
{
|
||
|
request->transaction = dcopClient()->beginTransaction();
|
||
|
}
|
||
|
queueRequest(request);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
void
|
||
12 years ago
|
TDELauncher::send_service_startup_info( TDELaunchRequest *request, KService::Ptr service, const TQCString& startup_id,
|
||
15 years ago
|
const TQValueList<TQCString> &envs )
|
||
15 years ago
|
{
|
||
|
#if defined Q_WS_X11 && ! defined K_WS_QTONLY
|
||
12 years ago
|
//#ifdef Q_WS_X11 // TDEStartup* isn't implemented for Qt/Embedded yet
|
||
15 years ago
|
request->startup_id = "0";
|
||
|
if( startup_id == "0" )
|
||
|
return;
|
||
|
bool silent;
|
||
15 years ago
|
TQCString wmclass;
|
||
|
if( !KRun::checkStartupNotify( TQString::null, service, &silent, &wmclass ))
|
||
15 years ago
|
return;
|
||
12 years ago
|
TDEStartupInfoId id;
|
||
15 years ago
|
id.initId( startup_id );
|
||
|
const char* dpy_str = NULL;
|
||
15 years ago
|
for( TQValueList<TQCString>::ConstIterator it = envs.begin();
|
||
15 years ago
|
it != envs.end();
|
||
|
++it )
|
||
|
if( strncmp( *it, "DISPLAY=", 8 ) == 0 )
|
||
|
dpy_str = static_cast< const char* >( *it ) + 8;
|
||
|
Display* dpy = NULL;
|
||
|
if( dpy_str != NULL && mCached_dpy != NULL
|
||
|
&& qstrcmp( dpy_str, XDisplayString( mCached_dpy )) == 0 )
|
||
|
dpy = mCached_dpy;
|
||
|
if( dpy == NULL )
|
||
|
dpy = XOpenDisplay( dpy_str );
|
||
|
request->startup_id = id.id();
|
||
|
if( dpy == NULL )
|
||
|
{
|
||
|
cancel_service_startup_info( request, startup_id, envs );
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
request->startup_dpy = dpy_str;
|
||
|
|
||
12 years ago
|
TDEStartupInfoData data;
|
||
15 years ago
|
data.setName( service->name());
|
||
|
data.setIcon( service->icon());
|
||
|
data.setDescription( i18n( "Launching %1" ).arg( service->name()));
|
||
|
if( !wmclass.isEmpty())
|
||
|
data.setWMClass( wmclass );
|
||
|
if( silent )
|
||
12 years ago
|
data.setSilent( TDEStartupInfoData::Yes );
|
||
13 years ago
|
// the rest will be sent by tdeinit
|
||
12 years ago
|
TDEStartupInfo::sendStartupX( dpy, id, data );
|
||
15 years ago
|
if( mCached_dpy != dpy && mCached_dpy != NULL )
|
||
|
XCloseDisplay( mCached_dpy );
|
||
|
mCached_dpy = dpy;
|
||
|
return;
|
||
|
#else
|
||
|
return;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
void
|
||
12 years ago
|
TDELauncher::cancel_service_startup_info( TDELaunchRequest* request, const TQCString& startup_id,
|
||
15 years ago
|
const TQValueList<TQCString> &envs )
|
||
15 years ago
|
{
|
||
|
#if defined Q_WS_X11 && ! defined K_WS_QTONLY
|
||
12 years ago
|
//#ifdef Q_WS_X11 // TDEStartup* isn't implemented for Qt/Embedded yet
|
||
15 years ago
|
if( request != NULL )
|
||
|
request->startup_id = "0";
|
||
|
if( !startup_id.isEmpty() && startup_id != "0" )
|
||
|
{
|
||
|
const char* dpy_str = NULL;
|
||
15 years ago
|
for( TQValueList<TQCString>::ConstIterator it = envs.begin();
|
||
15 years ago
|
it != envs.end();
|
||
|
++it )
|
||
|
if( strncmp( *it, "DISPLAY=", 8 ) == 0 )
|
||
|
dpy_str = static_cast< const char* >( *it ) + 8;
|
||
|
Display* dpy = NULL;
|
||
|
if( dpy_str != NULL && mCached_dpy != NULL
|
||
|
&& qstrcmp( dpy_str, XDisplayString( mCached_dpy )) == 0 )
|
||
|
dpy = mCached_dpy;
|
||
|
if( dpy == NULL )
|
||
|
dpy = XOpenDisplay( dpy_str );
|
||
|
if( dpy == NULL )
|
||
|
return;
|
||
12 years ago
|
TDEStartupInfoId id;
|
||
15 years ago
|
id.initId( startup_id );
|
||
12 years ago
|
TDEStartupInfo::sendFinishX( dpy, id );
|
||
15 years ago
|
if( mCached_dpy != dpy && mCached_dpy != NULL )
|
||
|
XCloseDisplay( mCached_dpy );
|
||
|
mCached_dpy = dpy;
|
||
|
}
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
bool
|
||
12 years ago
|
TDELauncher::tdeinit_exec(const TQString &app, const TQStringList &args,
|
||
15 years ago
|
const TQValueList<TQCString> &envs, TQCString startup_id, bool wait)
|
||
15 years ago
|
{
|
||
12 years ago
|
TDELaunchRequest *request = new TDELaunchRequest;
|
||
15 years ago
|
request->autoStart = false;
|
||
|
|
||
15 years ago
|
for(TQStringList::ConstIterator it = args.begin();
|
||
15 years ago
|
it != args.end();
|
||
|
it++)
|
||
|
{
|
||
15 years ago
|
TQString arg = *it;
|
||
15 years ago
|
request->arg_list.append(arg.local8Bit());
|
||
|
}
|
||
|
|
||
|
request->name = app.local8Bit();
|
||
|
|
||
|
if (wait)
|
||
|
request->dcop_service_type = KService::DCOP_Wait;
|
||
|
else
|
||
|
request->dcop_service_type = KService::DCOP_None;
|
||
|
request->dcop_name = 0;
|
||
|
request->pid = 0;
|
||
|
#ifdef Q_WS_X11
|
||
|
request->startup_id = startup_id;
|
||
|
#endif
|
||
|
request->envs = envs;
|
||
12 years ago
|
if( app != "tdebuildsycoca" ) // avoid stupid loop
|
||
15 years ago
|
{
|
||
|
// Find service, if any - strip path if needed
|
||
13 years ago
|
KService::Ptr service = KService::serviceByDesktopName( app.mid( app.findRev( '/' ) + 1 ));
|
||
15 years ago
|
if (service != NULL)
|
||
|
send_service_startup_info( request, service,
|
||
15 years ago
|
startup_id, TQValueList< TQCString >());
|
||
15 years ago
|
else // no .desktop file, no startup info
|
||
|
cancel_service_startup_info( request, startup_id, envs );
|
||
|
}
|
||
|
request->transaction = dcopClient()->beginTransaction();
|
||
|
queueRequest(request);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
void
|
||
12 years ago
|
TDELauncher::queueRequest(TDELaunchRequest *request)
|
||
15 years ago
|
{
|
||
|
requestQueue.append( request );
|
||
|
if (!bProcessingQueue)
|
||
|
{
|
||
|
bProcessingQueue = true;
|
||
15 years ago
|
TQTimer::singleShot(0, this, TQT_SLOT( slotDequeue() ));
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
void
|
||
12 years ago
|
TDELauncher::slotDequeue()
|
||
15 years ago
|
{
|
||
|
do {
|
||
12 years ago
|
TDELaunchRequest *request = requestQueue.take(0);
|
||
15 years ago
|
// process request
|
||
12 years ago
|
request->status = TDELaunchRequest::Launching;
|
||
15 years ago
|
requestStart(request);
|
||
12 years ago
|
if (request->status != TDELaunchRequest::Launching)
|
||
15 years ago
|
{
|
||
|
// Request handled.
|
||
|
requestDone( request );
|
||
|
continue;
|
||
|
}
|
||
|
} while(requestQueue.count());
|
||
|
bProcessingQueue = false;
|
||
|
}
|
||
|
|
||
|
void
|
||
12 years ago
|
TDELauncher::createArgs( TDELaunchRequest *request, const KService::Ptr service ,
|
||
15 years ago
|
const TQStringList &urls)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQStringList params = KRun::processDesktopExec(*service, urls, false);
|
||
15 years ago
|
|
||
15 years ago
|
for(TQStringList::ConstIterator it = params.begin();
|
||
15 years ago
|
it != params.end(); ++it)
|
||
|
{
|
||
|
request->arg_list.append((*it).local8Bit());
|
||
|
}
|
||
15 years ago
|
request->cwd = TQFile::encodeName(service->path());
|
||
15 years ago
|
}
|
||
|
|
||
|
///// IO-Slave functions
|
||
|
|
||
|
pid_t
|
||
12 years ago
|
TDELauncher::requestHoldSlave(const KURL &url, const TQString &app_socket)
|
||
15 years ago
|
{
|
||
|
IdleSlave *slave;
|
||
|
for(slave = mSlaveList.first(); slave; slave = mSlaveList.next())
|
||
|
{
|
||
|
if (slave->onHold(url))
|
||
|
break;
|
||
|
}
|
||
|
if (slave)
|
||
|
{
|
||
|
mSlaveList.removeRef(slave);
|
||
|
slave->connect(app_socket);
|
||
|
return slave->pid();
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
|
||
|
pid_t
|
||
12 years ago
|
TDELauncher::requestSlave(const TQString &protocol,
|
||
15 years ago
|
const TQString &host,
|
||
|
const TQString &app_socket,
|
||
|
TQString &error)
|
||
15 years ago
|
{
|
||
|
IdleSlave *slave;
|
||
|
for(slave = mSlaveList.first(); slave; slave = mSlaveList.next())
|
||
|
{
|
||
|
if (slave->match(protocol, host, true))
|
||
|
break;
|
||
|
}
|
||
|
if (!slave)
|
||
|
{
|
||
|
for(slave = mSlaveList.first(); slave; slave = mSlaveList.next())
|
||
|
{
|
||
|
if (slave->match(protocol, host, false))
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if (!slave)
|
||
|
{
|
||
|
for(slave = mSlaveList.first(); slave; slave = mSlaveList.next())
|
||
|
{
|
||
15 years ago
|
if (slave->match(protocol, TQString::null, false))
|
||
15 years ago
|
break;
|
||
|
}
|
||
|
}
|
||
|
if (slave)
|
||
|
{
|
||
|
mSlaveList.removeRef(slave);
|
||
|
slave->connect(app_socket);
|
||
|
return slave->pid();
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString _name = KProtocolInfo::exec(protocol);
|
||
15 years ago
|
if (_name.isEmpty())
|
||
|
{
|
||
|
error = i18n("Unknown protocol '%1'.\n").arg(protocol);
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
12 years ago
|
TQCString name = _name.latin1(); // ex: "tdeio_ftp"
|
||
15 years ago
|
TQCString arg1 = protocol.latin1();
|
||
|
TQCString arg2 = TQFile::encodeName(mPoolSocketName);
|
||
|
TQCString arg3 = TQFile::encodeName(app_socket);
|
||
|
TQValueList<TQCString> arg_list;
|
||
15 years ago
|
arg_list.append(arg1);
|
||
|
arg_list.append(arg2);
|
||
|
arg_list.append(arg3);
|
||
|
|
||
12 years ago
|
// kdDebug(7016) << "TDELauncher: launching new slave " << _name << " with protocol=" << protocol << endl;
|
||
15 years ago
|
if (mSlaveDebug == arg1)
|
||
|
{
|
||
12 years ago
|
tdelauncher_header request_header;
|
||
15 years ago
|
request_header.cmd = LAUNCHER_DEBUG_WAIT;
|
||
|
request_header.arg_length = 0;
|
||
13 years ago
|
write(tdeinitSocket, &request_header, sizeof(request_header));
|
||
15 years ago
|
}
|
||
|
if (mSlaveValgrind == arg1)
|
||
|
{
|
||
15 years ago
|
arg_list.prepend(TQFile::encodeName(KLibLoader::findLibrary(name)));
|
||
12 years ago
|
arg_list.prepend(TQFile::encodeName(locate("exe", "tdeioslave")));
|
||
15 years ago
|
name = "valgrind";
|
||
|
if (!mSlaveValgrindSkin.isEmpty()) {
|
||
15 years ago
|
arg_list.prepend(TQCString("--tool=") + mSlaveValgrindSkin);
|
||
15 years ago
|
} else
|
||
|
arg_list.prepend("--tool=memcheck");
|
||
|
}
|
||
|
|
||
12 years ago
|
TDELaunchRequest *request = new TDELaunchRequest;
|
||
15 years ago
|
request->autoStart = false;
|
||
|
request->name = name;
|
||
|
request->arg_list = arg_list;
|
||
|
request->dcop_name = 0;
|
||
|
request->dcop_service_type = KService::DCOP_None;
|
||
|
request->pid = 0;
|
||
|
#ifdef Q_WS_X11
|
||
|
request->startup_id = "0";
|
||
|
#endif
|
||
12 years ago
|
request->status = TDELaunchRequest::Launching;
|
||
15 years ago
|
request->transaction = 0; // No confirmation is send
|
||
|
requestStart(request);
|
||
|
pid_t pid = request->pid;
|
||
|
|
||
|
// kdDebug(7016) << "Slave launched, pid = " << pid << endl;
|
||
|
|
||
|
// We don't care about this request any longer....
|
||
|
requestDone(request);
|
||
|
if (!pid)
|
||
|
{
|
||
14 years ago
|
error = i18n("Error loading '%1'.\n").arg(TQString(name));
|
||
15 years ago
|
}
|
||
|
return pid;
|
||
|
}
|
||
|
|
||
|
void
|
||
12 years ago
|
TDELauncher::waitForSlave(pid_t pid)
|
||
15 years ago
|
{
|
||
|
IdleSlave *slave;
|
||
|
for(slave = mSlaveList.first(); slave; slave = mSlaveList.next())
|
||
|
{
|
||
|
if (slave->pid() == pid)
|
||
|
return; // Already here.
|
||
|
}
|
||
|
SlaveWaitRequest *waitRequest = new SlaveWaitRequest;
|
||
|
waitRequest->transaction = dcopClient()->beginTransaction();
|
||
|
waitRequest->pid = pid;
|
||
|
mSlaveWaitRequest.append(waitRequest);
|
||
|
}
|
||
|
|
||
|
void
|
||
12 years ago
|
TDELauncher::acceptSlave(TDESocket *slaveSocket)
|
||
15 years ago
|
{
|
||
|
IdleSlave *slave = new IdleSlave(slaveSocket);
|
||
|
// Send it a SLAVE_STATUS command.
|
||
|
mSlaveList.append(slave);
|
||
15 years ago
|
connect(slave, TQT_SIGNAL(destroyed()), this, TQT_SLOT(slotSlaveGone()));
|
||
|
connect(slave, TQT_SIGNAL(statusUpdate(IdleSlave *)),
|
||
14 years ago
|
this, TQT_SLOT(slotSlaveStatus(IdleSlave *)));
|
||
15 years ago
|
if (!mTimer.isActive())
|
||
|
{
|
||
|
mTimer.start(1000*10);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void
|
||
12 years ago
|
TDELauncher::slotSlaveStatus(IdleSlave *slave)
|
||
15 years ago
|
{
|
||
|
SlaveWaitRequest *waitRequest = mSlaveWaitRequest.first();
|
||
|
while(waitRequest)
|
||
|
{
|
||
|
if (waitRequest->pid == slave->pid())
|
||
|
{
|
||
15 years ago
|
TQByteArray replyData;
|
||
|
TQCString replyType;
|
||
15 years ago
|
replyType = "void";
|
||
|
dcopClient()->endTransaction( waitRequest->transaction, replyType, replyData);
|
||
|
mSlaveWaitRequest.removeRef(waitRequest);
|
||
|
waitRequest = mSlaveWaitRequest.current();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
waitRequest = mSlaveWaitRequest.next();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void
|
||
12 years ago
|
TDELauncher::slotSlaveGone()
|
||
15 years ago
|
{
|
||
|
IdleSlave *slave = (IdleSlave *) sender();
|
||
|
mSlaveList.removeRef(slave);
|
||
|
if ((mSlaveList.count() == 0) && (mTimer.isActive()))
|
||
|
{
|
||
|
mTimer.stop();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void
|
||
12 years ago
|
TDELauncher::idleTimeout()
|
||
15 years ago
|
{
|
||
|
bool keepOneFileSlave=true;
|
||
|
time_t now = time(0);
|
||
|
IdleSlave *slave;
|
||
|
for(slave = mSlaveList.first(); slave; slave = mSlaveList.next())
|
||
|
{
|
||
|
if ((slave->protocol()=="file") && (keepOneFileSlave))
|
||
|
keepOneFileSlave=false;
|
||
|
else if (slave->age(now) > SLAVE_MAX_IDLE)
|
||
|
{
|
||
|
// killing idle slave
|
||
|
delete slave;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
#include "tdelauncher.moc"
|