summaryrefslogtreecommitdiff
path: root/library
authorerik <erik>2007-01-24 19:46:19 (UTC)
committer erik <erik>2007-01-24 19:46:19 (UTC)
commita017bf21dd89159052f2f7a3fbc043a24956c08c (patch) (unidiff)
tree008be2b62ee5487dc55b8a7c7f043c94268f8362 /library
parenta4a7bd22feb060a80e20c81cded43cc24f5cd423 (diff)
downloadopie-a017bf21dd89159052f2f7a3fbc043a24956c08c.zip
opie-a017bf21dd89159052f2f7a3fbc043a24956c08c.tar.gz
opie-a017bf21dd89159052f2f7a3fbc043a24956c08c.tar.bz2
Every file in this commit has a memory leak of some kind or another. I think
all of them are minor and should not effect properly running code. But if I were you I would give libstocks and the stockticker plugin in Today a wide berth. That library is atrocious.
Diffstat (limited to 'library') (more/less context) (ignore whitespace changes)
-rw-r--r--library/global.cpp30
1 files changed, 17 insertions, 13 deletions
diff --git a/library/global.cpp b/library/global.cpp
index 7bdd0b1..1895006 100644
--- a/library/global.cpp
+++ b/library/global.cpp
@@ -510,172 +510,176 @@ bool Global::terminateBuiltin( const QString& n )
510/*! 510/*!
511 \internal 511 \internal
512*/ 512*/
513void Global::terminate( const AppLnk* app ) 513void Global::terminate( const AppLnk* app )
514{ 514{
515 //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this 515 //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this
516 516
517#ifndef QT_NO_COP 517#ifndef QT_NO_COP
518 QCString channel = "QPE/Application/" + app->exec().utf8(); 518 QCString channel = "QPE/Application/" + app->exec().utf8();
519 if ( QCopChannel::isRegistered(channel) ) { 519 if ( QCopChannel::isRegistered(channel) ) {
520 QCopEnvelope e(channel, "quit()"); 520 QCopEnvelope e(channel, "quit()");
521 } 521 }
522#endif 522#endif
523} 523}
524 524
525/*! 525/*!
526 Low-level function to run command \a c. 526 Low-level function to run command \a c.
527 527
528 \warning Do not use this function. Use execute instead. 528 \warning Do not use this function. Use execute instead.
529 529
530 \sa execute() 530 \sa execute()
531*/ 531*/
532void Global::invoke(const QString &c) 532void Global::invoke(const QString &c)
533{ 533{
534 // Convert the command line in to a list of arguments 534 // Convert the command line in to a list of arguments
535 QStringList list = QStringList::split(QRegExp(" *"),c); 535 QStringList list = QStringList::split(QRegExp(" *"),c);
536 536
537#if !defined(QT_NO_COP) 537#if !defined(QT_NO_COP)
538 QString ap=list[0]; 538 QString ap=list[0];
539 // see if the application is already running 539 // see if the application is already running
540 // XXX should lock file /tmp/qcop-msg-ap 540 // XXX should lock file /tmp/qcop-msg-ap
541 if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) { 541 if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) {
542 // If the channel is already register, the app is already running, so show it. 542 // If the channel is already register, the app is already running, so show it.
543 { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } 543 {
544 544 QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" );
545 //QCopEnvelope e("QPE/System", "notBusy(QString)" ); 545 }
546 //e << ap; 546
547 return; 547 //QCopEnvelope e("QPE/System", "notBusy(QString)" );
548 //e << ap;
549 return;
548 } 550 }
549 // XXX should unlock file /tmp/qcop-msg-ap 551 // XXX should unlock file /tmp/qcop-msg-ap
550 //see if it is being started 552 //see if it is being started
551 if ( StartingAppList::isStarting( ap ) ) { 553 if ( StartingAppList::isStarting( ap ) ) {
552 // FIXME take it out for now, since it leads to a much to short showing of wait if 554 // FIXME take it out for now, since it leads to a much to short showing of wait if
553 // some entry is clicked. 555 // some entry is clicked.
554 // Real cause is that ::execute is called twice for document tab. But it would need some larger changes 556 // Real cause is that ::execute is called twice for document tab. But it would need some larger changes
555 // to fix that, and with future syncs with qtopia 1.6 it will change anyway big time since somebody there 557 // to fix that, and with future syncs with qtopia 1.6 it will change anyway big time since somebody there
556 // had the idea that an apploader belongs to the launcher ... 558 // had the idea that an apploader belongs to the launcher ...
557 //QCopEnvelope e("QPE/System", "notBusy(QString)" ); 559 //QCopEnvelope e("QPE/System", "notBusy(QString)" );
558 //e << ap; 560 //e << ap;
559 return; 561 return;
560 } 562 }
561 563
562#endif 564#endif
563 565
564#ifdef QT_NO_QWS_MULTIPROCESS 566#ifdef QT_NO_QWS_MULTIPROCESS
565 QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 ); 567 QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 );
566#else 568#else
567 569
568 QStrList slist; 570 QStrList slist;
569 unsigned int j; 571 unsigned int j;
570 for ( j = 0; j < list.count(); j++ ) 572 for ( j = 0; j < list.count(); j++ )
571 slist.append( list[j].utf8() ); 573 slist.append( list[j].utf8() );
572 574
573 const char **args = new const char *[slist.count() + 1]; 575 const char **args = new const char *[slist.count() + 1];
574 for ( j = 0; j < slist.count(); j++ ) 576 for ( j = 0; j < slist.count(); j++ )
575 args[j] = slist.at(j); 577 args[j] = slist.at(j);
578
576 args[j] = NULL; 579 args[j] = NULL;
577 580
578#if !defined(QT_NO_COP) 581#if !defined(QT_NO_COP)
579 // an attempt to show a wait... 582 // an attempt to show a wait...
580 // more logic should be used, but this will be fine for the moment... 583 // more logic should be used, but this will be fine for the moment...
581 QCopEnvelope ( "QPE/System", "busy()" ); 584 QCopEnvelope ( "QPE/System", "busy()" );
582#endif 585#endif
583 586
584#ifdef HAVE_QUICKEXEC 587#ifdef HAVE_QUICKEXEC
585#ifdef Q_OS_MACX 588#ifdef Q_OS_MACX
586 QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".dylib"; 589 QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".dylib";
587#else 590#else
588 QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so"; 591 QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so";
589#endif 592#endif
590 qDebug("libfile = %s", libexe.latin1() ); 593 qDebug("libfile = %s", libexe.latin1() );
591 if ( QFile::exists( libexe ) ) { 594 if ( QFile::exists( libexe ) ) {
592 qDebug("calling quickexec %s", libexe.latin1() ); 595 qDebug("calling quickexec %s", libexe.latin1() );
593 quickexecv( libexe.utf8().data(), (const char **)args ); 596 quickexecv( libexe.utf8().data(), (const char **)args );
594 } else 597 } else
595#endif 598#endif
596 { 599 {
597 bool success = false; 600 bool success = false;
598 int pfd [2]; 601 int pfd [2];
599 if ( ::pipe ( pfd ) < 0 ) 602 if ( ::pipe ( pfd ) < 0 )
600 pfd [0] = pfd [1] = -1; 603 pfd [0] = pfd [1] = -1;
601 604
602 pid_t pid = ::fork ( ); 605 pid_t pid = ::fork ( );
603 606
604 if ( pid == 0 ) { // child 607 if ( pid == 0 ) { // child
605 for ( int fd = 3; fd < 100; fd++ ) { 608 for ( int fd = 3; fd < 100; fd++ ) {
606 if ( fd != pfd [1] ) 609 if ( fd != pfd [1] )
607 ::close ( fd ); 610 ::close ( fd );
608 } 611 }
609 ::setpgid ( ::getpid ( ), ::getppid ( )); 612 ::setpgid ( ::getpid ( ), ::getppid ( ));
610 613
611 // Closing of fd[1] indicates that the execvp succeeded! 614 // Closing of fd[1] indicates that the execvp succeeded!
612 if ( pfd [1] >= 0 ) 615 if ( pfd [1] >= 0 )
613 ::fcntl ( pfd [1], F_SETFD, FD_CLOEXEC ); 616 ::fcntl ( pfd [1], F_SETFD, FD_CLOEXEC );
614 617
615 // Try bindir first, so that foo/bar works too 618 // Try bindir first, so that foo/bar works too
616 ::execv ( qpeDir ( ) + "/bin/" + args [0], (char * const *) args ); 619 ::execv ( qpeDir ( ) + "/bin/" + args [0], (char * const *) args );
617 ::execvp ( args [0], (char * const *) args ); 620 ::execvp ( args [0], (char * const *) args );
618 621
619 char resultByte = 1; 622 char resultByte = 1;
620 if ( pfd [1] >= 0 ) 623 if ( pfd [1] >= 0 )
621 ::write ( pfd [1], &resultByte, 1 ); 624 ::write ( pfd [1], &resultByte, 1 );
622 ::_exit ( -1 ); 625 ::_exit ( -1 );
623 } 626 }
624 else if ( pid > 0 ) { 627 else if ( pid > 0 ) {
625 success = true; 628 success = true;
626 629
627 if ( pfd [1] >= 0 ) 630 if ( pfd [1] >= 0 )
628 ::close ( pfd [1] ); 631 ::close ( pfd [1] );
629 if ( pfd [0] >= 0 ) { 632 if ( pfd [0] >= 0 ) {
630 while ( true ) { 633 while ( true ) {
631 char resultByte; 634 char resultByte;
632 int n = ::read ( pfd [0], &resultByte, 1 ); 635 int n = ::read ( pfd [0], &resultByte, 1 );
633 if ( n == 1 ) { 636 if ( n == 1 ) {
634 success = false; 637 success = false;
635 break; 638 break;
636 } 639 }
637 if (( n == -1 ) && (( errno == ECHILD ) || ( errno == EINTR ))) 640 if (( n == -1 ) && (( errno == ECHILD ) || ( errno == EINTR )))
638 continue; 641 continue;
639 642
640 break; // success 643 break; // success
641 } 644 }
642 ::close ( pfd [0] ); 645 ::close ( pfd [0] );
643 } 646 }
644 } 647 }
645 if ( success ) 648 if ( success )
646 StartingAppList::add( list[0] ); 649 StartingAppList::add( list[0] );
647 else 650 else
648 QMessageBox::warning( 0, "Error", "Could not start the application " + c, "Ok", 0, 0, 0, 1 ); 651 QMessageBox::warning( 0, "Error", "Could not start the application " + c, "Ok", 0, 0, 0, 1 );
649 } 652 }
653 delete [] args;
650#endif //QT_NO_QWS_MULTIPROCESS 654#endif //QT_NO_QWS_MULTIPROCESS
651} 655}
652 656
653 657
654/*! 658/*!
655 Executes the application identfied by \a c, passing \a 659 Executes the application identfied by \a c, passing \a
656 document if it isn't null. 660 document if it isn't null.
657 661
658 Note that a better approach might be to send a QCop message to the 662 Note that a better approach might be to send a QCop message to the
659 application's QPE/Application/\e{appname} channel. 663 application's QPE/Application/\e{appname} channel.
660*/ 664*/
661void Global::execute( const QString &c, const QString& document ) 665void Global::execute( const QString &c, const QString& document )
662{ 666{
663 // ask the server to do the work 667 // ask the server to do the work
664#if !defined(QT_NO_COP) 668#if !defined(QT_NO_COP)
665 if ( document.isNull() ) { 669 if ( document.isNull() ) {
666 QCopEnvelope e( "QPE/System", "execute(QString)" ); 670 QCopEnvelope e( "QPE/System", "execute(QString)" );
667 e << c; 671 e << c;
668 } else { 672 } else {
669 QCopEnvelope e( "QPE/System", "execute(QString,QString)" ); 673 QCopEnvelope e( "QPE/System", "execute(QString,QString)" );
670 e << c << document; 674 e << c << document;
671 } 675 }
672#endif 676#endif
673 return; 677 return;
674} 678}
675 679
676/*! 680/*!
677 Returns the string \a s with the characters '\', '"', and '$' quoted 681 Returns the string \a s with the characters '\', '"', and '$' quoted
678 by a preceeding '\'. 682 by a preceeding '\'.
679 683
680 \sa stringQuote() 684 \sa stringQuote()
681*/ 685*/