Ticket #31332: workaround-kdeinit4-crash.patch
File workaround-kdeinit4-crash.patch, 4.6 KB (added by ak.ml@…, 13 years ago) |
---|
-
kinit/kinit.cpp
old new 543 543 const QString bundlepath = s_instance->dirs()->findExe(QFile::decodeName(execpath)); 544 544 #endif 545 545 546 // Don't run this inside the child process, it crashes on OS/X 10.6 547 const QString helperpath = s_instance->dirs()->findExe(QString::fromLatin1("kdeinit4_helper")); 548 #ifdef Q_WS_MAC 549 const QString argvexe = s_instance->dirs()->findExe(QString::fromLatin1(_name)); 550 #endif 551 546 552 d.errorMsg = 0; 547 553 d.fork = fork(); 548 554 switch(d.fork) { … … 607 613 { 608 614 int r; 609 615 QByteArray procTitle; 610 d.argv = (char **) malloc(sizeof(char *) * (argc+ 1));616 d.argv = (char **) malloc(sizeof(char *) * (argc+2)); 611 617 d.argv[0] = (char *) _name; 612 618 #ifdef Q_WS_MAC 613 QString argvexe = s_instance->dirs()->findExe(QString::fromLatin1(d.argv[0]));614 619 if (!argvexe.isEmpty()) { 615 620 QByteArray cstr = argvexe.toLocal8Bit(); 616 kDebug(7016) << "kdeinit4: launch() setting argv: " << cstr.data();617 621 d.argv[0] = strdup(cstr.data()); 618 622 } 619 623 #endif … … 699 703 exit(255); 700 704 } 701 705 702 void * sym = l.resolve( "kdeinitmain"); 703 if (!sym ) 704 { 705 sym = l.resolve( "kdemain" ); 706 if ( !sym ) 707 { 708 QString ltdlError = l.errorString(); 709 fprintf(stderr, "Could not find kdemain: %s\n", qPrintable(ltdlError) ); 710 QString errorMsg = i18n("Could not find 'kdemain' in '%1'.\n%2", 711 libpath, ltdlError); 712 exitWithErrorMsg(errorMsg); 713 } 714 } 715 716 d.result = 0; // Success 706 d.result = 2; // Try execing 717 707 write(d.fd[1], &d.result, 1); 718 close(d.fd[1]);719 708 720 d.func = (int (*)(int, char *[])) sym; 709 // We set the close on exec flag. 710 // Closing of d.fd[1] indicates that the execvp succeeded! 711 fcntl(d.fd[1], F_SETFD, FD_CLOEXEC); 712 721 713 if (d.debug_wait) 722 714 { 723 715 fprintf(stderr, "kdeinit4: Suspending process\n" … … 731 723 setup_tty( tty ); 732 724 } 733 725 734 exit( d.func(argc, d.argv)); /* Launch! */ 726 QByteArray helperexe = QFile::encodeName(helperpath); 727 QByteArray libpathbytes = QFile::encodeName(libpath); 728 d.argv[argc] = libpathbytes.data(); 729 d.argv[argc+1] = 0; 730 731 if (!helperexe.isEmpty()) 732 execvp(helperexe, d.argv); 735 733 734 d.result = 1; // Error 735 write(d.fd[1], &d.result, 1); 736 close(d.fd[1]); 737 exit(255); 736 738 break; 737 739 } 738 740 default: -
kinit/CMakeLists.txt
old new 58 58 59 59 install(TARGETS kdeinit4 ${INSTALL_TARGETS_DEFAULT_ARGS} ) 60 60 61 ########### kdeinit4_helper ############### 62 63 set(kdeinit4_helper_SRCS helper.cpp) 64 65 kde4_add_executable(kdeinit4_helper NOGUI ${kdeinit4_helper_SRCS}) 66 67 target_link_libraries(kdeinit4_helper ${QT_QTCORE_LIBRARY}) 68 69 install(TARGETS kdeinit4_helper DESTINATION ${LIBEXEC_INSTALL_DIR} ) 70 61 71 ########### kwrapper4 ############### 62 72 if (WIN32) 63 73 set(kwrapper_SRCS kwrapper_win.cpp ) -
new file kdelibs-4.7.1/kinit/helper.cpp
- + 1 #include <stdio.h> 2 #include <stdlib.h> 3 4 #include <QFile> 5 #include <QLibrary> 6 7 typedef int (*handler) (int, char *[]); 8 9 int main(int argc, char *argv[]) 10 { 11 if (argc < 2) 12 { 13 fprintf(stderr, "Too few arguments\n"); 14 exit(1); 15 } 16 17 QString libpath = QFile::decodeName(argv[argc-1]); 18 QLibrary l(libpath); 19 20 if (!libpath.isEmpty() && (!l.load() || !l.isLoaded())) 21 { 22 QString ltdlError = l.errorString(); 23 fprintf(stderr, "Could not open library %s: %s\n", qPrintable(libpath), qPrintable(ltdlError) ); 24 exit(1); 25 } 26 27 void * sym = l.resolve( "kdeinitmain"); 28 if (!sym) 29 { 30 sym = l.resolve( "kdemain" ); 31 if ( !sym ) 32 { 33 QString ltdlError = l.errorString(); 34 fprintf(stderr, "Could not find kdemain: %s\n", qPrintable(ltdlError) ); 35 exit(1); 36 } 37 } 38 39 handler func = (int (*)(int, char *[])) sym; 40 exit( func(argc - 1, argv)); /* Launch! */ 41 } 42