Index: kdelibs-4.7.1/kinit/kinit.cpp =================================================================== --- kdelibs-4.7.1.orig/kinit/kinit.cpp 2011-05-20 22:24:54.000000000 +0200 +++ kdelibs-4.7.1/kinit/kinit.cpp 2011-09-25 01:29:50.000000000 +0200 @@ -543,6 +543,12 @@ const QString bundlepath = s_instance->dirs()->findExe(QFile::decodeName(execpath)); #endif + // Don't run this inside the child process, it crashes on OS/X 10.6 + const QString helperpath = s_instance->dirs()->findExe(QString::fromLatin1("kdeinit4_helper")); +#ifdef Q_WS_MAC + const QString argvexe = s_instance->dirs()->findExe(QString::fromLatin1(_name)); +#endif + d.errorMsg = 0; d.fork = fork(); switch(d.fork) { @@ -607,13 +613,11 @@ { int r; QByteArray procTitle; - d.argv = (char **) malloc(sizeof(char *) * (argc+1)); + d.argv = (char **) malloc(sizeof(char *) * (argc+2)); d.argv[0] = (char *) _name; #ifdef Q_WS_MAC - QString argvexe = s_instance->dirs()->findExe(QString::fromLatin1(d.argv[0])); if (!argvexe.isEmpty()) { QByteArray cstr = argvexe.toLocal8Bit(); - kDebug(7016) << "kdeinit4: launch() setting argv: " << cstr.data(); d.argv[0] = strdup(cstr.data()); } #endif @@ -699,25 +703,13 @@ exit(255); } - void * sym = l.resolve( "kdeinitmain"); - if (!sym ) - { - sym = l.resolve( "kdemain" ); - if ( !sym ) - { - QString ltdlError = l.errorString(); - fprintf(stderr, "Could not find kdemain: %s\n", qPrintable(ltdlError) ); - QString errorMsg = i18n("Could not find 'kdemain' in '%1'.\n%2", - libpath, ltdlError); - exitWithErrorMsg(errorMsg); - } - } - - d.result = 0; // Success + d.result = 2; // Try execing write(d.fd[1], &d.result, 1); - close(d.fd[1]); - d.func = (int (*)(int, char *[])) sym; + // We set the close on exec flag. + // Closing of d.fd[1] indicates that the execvp succeeded! + fcntl(d.fd[1], F_SETFD, FD_CLOEXEC); + if (d.debug_wait) { fprintf(stderr, "kdeinit4: Suspending process\n" @@ -731,8 +723,18 @@ setup_tty( tty ); } - exit( d.func(argc, d.argv)); /* Launch! */ + QByteArray helperexe = QFile::encodeName(helperpath); + QByteArray libpathbytes = QFile::encodeName(libpath); + d.argv[argc] = libpathbytes.data(); + d.argv[argc+1] = 0; + + if (!helperexe.isEmpty()) + execvp(helperexe, d.argv); + d.result = 1; // Error + write(d.fd[1], &d.result, 1); + close(d.fd[1]); + exit(255); break; } default: Index: kdelibs-4.7.1/kinit/CMakeLists.txt =================================================================== --- kdelibs-4.7.1.orig/kinit/CMakeLists.txt 2011-05-20 22:24:54.000000000 +0200 +++ kdelibs-4.7.1/kinit/CMakeLists.txt 2011-09-21 01:41:37.000000000 +0200 @@ -58,6 +58,16 @@ install(TARGETS kdeinit4 ${INSTALL_TARGETS_DEFAULT_ARGS} ) +########### kdeinit4_helper ############### + +set(kdeinit4_helper_SRCS helper.cpp) + +kde4_add_executable(kdeinit4_helper NOGUI ${kdeinit4_helper_SRCS}) + +target_link_libraries(kdeinit4_helper ${QT_QTCORE_LIBRARY}) + +install(TARGETS kdeinit4_helper DESTINATION ${LIBEXEC_INSTALL_DIR} ) + ########### kwrapper4 ############### if (WIN32) set(kwrapper_SRCS kwrapper_win.cpp ) Index: kdelibs-4.7.1/kinit/helper.cpp =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ kdelibs-4.7.1/kinit/helper.cpp 2011-09-21 01:41:37.000000000 +0200 @@ -0,0 +1,42 @@ +#include +#include + +#include +#include + +typedef int (*handler) (int, char *[]); + +int main(int argc, char *argv[]) +{ + if (argc < 2) + { + fprintf(stderr, "Too few arguments\n"); + exit(1); + } + + QString libpath = QFile::decodeName(argv[argc-1]); + QLibrary l(libpath); + + if (!libpath.isEmpty() && (!l.load() || !l.isLoaded())) + { + QString ltdlError = l.errorString(); + fprintf(stderr, "Could not open library %s: %s\n", qPrintable(libpath), qPrintable(ltdlError) ); + exit(1); + } + + void * sym = l.resolve( "kdeinitmain"); + if (!sym) + { + sym = l.resolve( "kdemain" ); + if ( !sym ) + { + QString ltdlError = l.errorString(); + fprintf(stderr, "Could not find kdemain: %s\n", qPrintable(ltdlError) ); + exit(1); + } + } + + handler func = (int (*)(int, char *[])) sym; + exit( func(argc - 1, argv)); /* Launch! */ +} +