2 * This file is part of the KDE libraries
3 * Copyright (c) 1999-2000 Waldo Bastian <bastian@kde.org>
4 * (c) 1999 Mario Weilguni <mweilguni@sime.com>
5 * (c) 2001 Lubos Lunak <l.lunak@kde.org>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License version 2 as published by the Free Software Foundation.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
30 #include <QtCore/QString>
31 #include <QtCore/QLibrary>
32 #include <QtCore/QFile>
34 #include <QtCore/QDir>
35 #include <QtCore/QProcess>
36 #include <QtCore/QStringList>
39 #include "kstandarddirs.h"
43 /* These are to link libkio even if 'smart' linker is used */
44 #include <kio/authinfo.h>
45 extern "C" KIO::AuthInfo
* _kioslave_init_kio() { return new KIO::AuthInfo(); }
48 int main(int argc
, char **argv
)
52 fprintf(stderr
, "Usage: kioslave <slave-lib> <protocol> <klauncher-socket> <app-socket>\n\nThis program is part of KDE.\n");
55 setlocale(LC_ALL
, "");
56 QString libpath
= QFile::decodeName(argv
[1]);
58 if (libpath
.isEmpty())
60 fprintf(stderr
, "library path is empty.\n");
64 QLibrary
lib(libpath
);
66 qDebug("trying to load '%s'", qPrintable(libpath
));
68 if ( !lib
.load() || !lib
.isLoaded() )
71 libpath
= KStandardDirs::installPath("module") + QFileInfo(libpath
).fileName();
72 lib
.setFileName( libpath
);
73 if(!lib
.load() || !lib
.isLoaded())
75 QByteArray kdedirs
= qgetenv("KDEDIRS");
76 if (!kdedirs
.size()) {
77 qDebug("not able to find '%s' because KDEDIRS environment variable is not set.\n"
78 "Set KDEDIRS to the KDE installation root dir and restart klauncher to fix this problem.",
82 QString paths
= QString::fromLocal8Bit(kdedirs
);
83 QStringList pathlist
= paths
.split(';');
84 Q_FOREACH(const QString
&path
, pathlist
) {
85 QString slave_path
= path
+ QLatin1String("/lib/kde4/") + QFileInfo(libpath
).fileName();
86 qDebug("trying to load '%s'",slave_path
.toAscii().data());
87 lib
.setFileName(slave_path
);
88 if (lib
.load() && lib
.isLoaded() )
93 qWarning("could not open %s: %s", libpath
.data(), qPrintable (lib
.errorString()) );
98 fprintf(stderr
, "could not open %s: %s", qPrintable(libpath
),
99 qPrintable (lib
.errorString()) );
104 void* sym
= lib
.resolve("kdemain");
107 sym
= lib
.resolve("main");
110 fprintf(stderr
, "Could not find main: %s\n", qPrintable(lib
.errorString() ));
116 // enter debugger in case debugging is actived
117 QString
slaveDebugWait( QString::fromLocal8Bit( qgetenv("KDE_SLAVE_DEBUG_WAIT") ) );
118 if (slaveDebugWait
== QLatin1String("all") || slaveDebugWait
== argv
[2])
121 // msvc debugger or windbg supports jit debugging, the latter requires setting up windbg jit with windbg -i
124 // gdb does not support win32 jit debug support, so implement it by ourself
126 GetModuleFileName(NULL
,buf
, 1024);
128 params
<< QString::fromUtf16((const unsigned short*)buf
);
129 params
<< QString::number(GetCurrentProcessId());
130 QProcess::startDetached("gdb",params
);
136 QString
slaveDebugPopup( QString::fromLocal8Bit( qgetenv("KDE_SLAVE_DEBUG_POPUP") ) );
137 if (slaveDebugPopup
== QLatin1String("all") || slaveDebugPopup
== argv
[2]) {
138 // A workaround for OSes where DebugBreak() does not work in administrative mode (actually Vista with msvc 2k5)
139 // - display a native message box so developer can attach the debugger to the KIO slave process and click OK.
141 QString("Please attach the debugger to process #%1 (%2)").arg(getpid()).arg(argv
[0]).toLatin1(),
142 QString("\"%1\" KIO Slave Debugging").arg(argv
[2]).toLatin1(), MB_OK
|MB_ICONINFORMATION
|MB_TASKMODAL
);
148 int (*func
)(int, char *[]) = (int (*)(int, char *[])) sym
;
150 exit( func(argc
-1, argv
+1)); /* Launch! */