KInit
kioslave.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <config.h>
00023
00024 #include <stdlib.h>
00025 #include <stdio.h>
00026 #include <errno.h>
00027
00028 #include <QtCore/QString>
00029 #include <QtCore/QLibrary>
00030 #include <QtCore/QFile>
00031 #ifdef Q_WS_WIN
00032 #include <QtCore/QDir>
00033 #include <QtCore/QProcess>
00034 #include <QtCore/QStringList>
00035 #include <windows.h>
00036 #include "kstandarddirs.h"
00037 #endif
00038
00039 #ifndef Q_WS_WIN
00040
00041 #include <kio/authinfo.h>
00042 extern "C" KIO::AuthInfo* _kioslave_init_kio() { return new KIO::AuthInfo(); }
00043 #endif
00044
00045 int main(int argc, char **argv)
00046 {
00047 if (argc < 5)
00048 {
00049 fprintf(stderr, "Usage: kioslave <slave-lib> <protocol> <klauncher-socket> <app-socket>\n\nThis program is part of KDE.\n");
00050 exit(1);
00051 }
00052 QString libpath = QFile::decodeName(argv[1]);
00053
00054 if (libpath.isEmpty())
00055 {
00056 fprintf(stderr, "library path is empty.\n");
00057 exit(1);
00058 }
00059
00060 QLibrary lib(libpath);
00061 #ifdef Q_WS_WIN
00062 qDebug("trying to load '%s'", qPrintable(libpath));
00063 #endif
00064 if ( !lib.load() || !lib.isLoaded() )
00065 {
00066 #ifdef Q_WS_WIN
00067 libpath = KStandardDirs::installPath("module") + QFileInfo(libpath).fileName();
00068 lib.setFileName( libpath );
00069 if(!lib.load() || !lib.isLoaded())
00070 {
00071 QByteArray kdedirs = qgetenv("KDEDIRS");
00072 if (!kdedirs.size()) {
00073 qDebug("not able to find '%s' because KDEDIRS environment variable is not set.\n"
00074 "Set KDEDIRS to the KDE installation root dir and restart klauncher to fix this problem.",
00075 qPrintable(libpath));
00076 exit(1);
00077 }
00078 QString paths = QString::fromLocal8Bit(kdedirs);
00079 QStringList pathlist = paths.split(';');
00080 Q_FOREACH(QString path, pathlist) {
00081 QString slave_path = path + QLatin1String("/lib/kde4/") + libpath;
00082 qDebug("trying to load '%s'",slave_path.toAscii().data());
00083 lib.setFileName(slave_path);
00084 if (lib.load() && lib.isLoaded() )
00085 break;
00086 }
00087 if (!lib.isLoaded())
00088 {
00089 fprintf(stderr, "could not open %s: %s", libpath.data(),
00090 qPrintable (lib.errorString()) );
00091 exit(1);
00092 }
00093 }
00094 #else
00095 fprintf(stderr, "could not open %s: %s", qPrintable(libpath),
00096 qPrintable (lib.errorString()) );
00097 exit(1);
00098 #endif
00099 }
00100
00101 void* sym = lib.resolve("kdemain");
00102 if (!sym )
00103 {
00104 sym = lib.resolve("main");
00105 if (!sym )
00106 {
00107 fprintf(stderr, "Could not find main: %s\n", qPrintable(lib.errorString() ));
00108 exit(1);
00109 }
00110 }
00111
00112 #ifdef Q_WS_WIN
00113
00114 QString mSlaveDebug = getenv("KDE_SLAVE_DEBUG_WAIT");
00115
00116 if (mSlaveDebug == argv[2])
00117 #ifdef Q_CC_GNU
00118 {
00119
00120 QByteArray buf(1024,0);
00121 GetModuleFileName(NULL,buf.data(),buf.size());
00122 QStringList params;
00123 params << buf;
00124 params << QString::number(GetCurrentProcessId());
00125 QProcess::startDetached("gdb",params);
00126 Sleep(1000);
00127 }
00128 #else
00129
00130 DebugBreak();
00131 #endif
00132 #endif
00133
00134 int (*func)(int, char *[]) = (int (*)(int, char *[])) sym;
00135
00136 exit( func(argc-1, argv+1));
00137 }