Diffstat (limited to 'core/launcher/applauncher.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/launcher/applauncher.cpp | 83 |
1 files changed, 40 insertions, 43 deletions
diff --git a/core/launcher/applauncher.cpp b/core/launcher/applauncher.cpp index 5a5517c..7000346 100644 --- a/core/launcher/applauncher.cpp +++ b/core/launcher/applauncher.cpp | |||
@@ -26,40 +26,37 @@ | |||
26 | #endif | 26 | #endif |
27 | #ifndef QTOPIA_PROGRAM_MONITOR | 27 | #ifndef QTOPIA_PROGRAM_MONITOR |
28 | #define QTOPIA_PROGRAM_MONITOR | 28 | #define QTOPIA_PROGRAM_MONITOR |
29 | #endif | 29 | #endif |
30 | |||
31 | #include "applauncher.h" | ||
32 | #include "documentlist.h" | ||
33 | |||
34 | /* OPIE */ | ||
35 | #include <opie2/odebug.h> | ||
30 | #include <opie2/oglobal.h> | 36 | #include <opie2/oglobal.h> |
37 | #include <qtopia/qcopenvelope_qws.h> | ||
38 | #include <qtopia/qpeapplication.h> | ||
39 | using namespace Opie::Core; | ||
31 | 40 | ||
32 | #ifndef Q_OS_WIN32 | 41 | /* QT */ |
42 | #include <qtimer.h> | ||
43 | #include <qwindowsystem_qws.h> | ||
44 | #include <qmessagebox.h> | ||
45 | #include <qfileinfo.h> | ||
46 | |||
47 | /* STD */ | ||
33 | #include <sys/stat.h> | 48 | #include <sys/stat.h> |
34 | #include <sys/wait.h> | 49 | #include <sys/wait.h> |
35 | #include <sys/file.h> | 50 | #include <sys/file.h> |
36 | #include <unistd.h> | 51 | #include <unistd.h> |
37 | #include <sys/time.h> | 52 | #include <sys/time.h> |
38 | #include <sys/resource.h> | 53 | #include <sys/resource.h> |
39 | #include <errno.h> | 54 | #include <errno.h> |
40 | #else | ||
41 | #include <process.h> | ||
42 | #include <windows.h> | ||
43 | #include <winbase.h> | ||
44 | #endif | ||
45 | |||
46 | #include <signal.h> | 55 | #include <signal.h> |
47 | #include <sys/types.h> | 56 | #include <sys/types.h> |
48 | #include <stdlib.h> | 57 | #include <stdlib.h> |
49 | 58 | ||
50 | #include <qtimer.h> | ||
51 | #include <qwindowsystem_qws.h> | ||
52 | #include <qmessagebox.h> | ||
53 | #include <qfileinfo.h> | ||
54 | |||
55 | #include <qtopia/qcopenvelope_qws.h> | ||
56 | #include <qtopia/qpeapplication.h> | ||
57 | |||
58 | #include "applauncher.h" | ||
59 | #include "documentlist.h" | ||
60 | |||
61 | using namespace Opie::Core; | ||
62 | const int AppLauncher::RAISE_TIMEOUT_MS = 5000; | 59 | const int AppLauncher::RAISE_TIMEOUT_MS = 5000; |
63 | 60 | ||
64 | //--------------------------------------------------------------------------- | 61 | //--------------------------------------------------------------------------- |
65 | 62 | ||
@@ -126,9 +123,9 @@ AppLauncher::~AppLauncher() | |||
126 | /* We use the QCopChannel of the app as an indicator of when it has been launched | 123 | /* We use the QCopChannel of the app as an indicator of when it has been launched |
127 | so that we can disable the busy indicators */ | 124 | so that we can disable the busy indicators */ |
128 | void AppLauncher::newQcopChannel(const QString& channelName) | 125 | void AppLauncher::newQcopChannel(const QString& channelName) |
129 | { | 126 | { |
130 | // qDebug("channel %s added", channelName.data() ); | 127 | // odebug << "channel " << channelName.data() << " added" << oendl; |
131 | QString prefix("QPE/Application/"); | 128 | QString prefix("QPE/Application/"); |
132 | if (channelName.startsWith(prefix)) { | 129 | if (channelName.startsWith(prefix)) { |
133 | { | 130 | { |
134 | QCopEnvelope e("QPE/System", "newChannel(QString)"); | 131 | QCopEnvelope e("QPE/System", "newChannel(QString)"); |
@@ -140,9 +137,9 @@ void AppLauncher::newQcopChannel(const QString& channelName) | |||
140 | QCopEnvelope e("QPE/System", "notBusy(QString)"); | 137 | QCopEnvelope e("QPE/System", "notBusy(QString)"); |
141 | e << appName; | 138 | e << appName; |
142 | } | 139 | } |
143 | } else if (channelName.startsWith("QPE/QuickLauncher-")) { | 140 | } else if (channelName.startsWith("QPE/QuickLauncher-")) { |
144 | qDebug("Registered %s", channelName.latin1()); | 141 | odebug << "Registered " << channelName << "" << oendl; |
145 | int pid = channelName.mid(18).toInt(); | 142 | int pid = channelName.mid(18).toInt(); |
146 | if (pid == qlPid) | 143 | if (pid == qlPid) |
147 | qlReady = TRUE; | 144 | qlReady = TRUE; |
148 | } | 145 | } |
@@ -179,9 +176,9 @@ void AppLauncher::received(const QCString& msg, const QByteArray& data) | |||
179 | stream >> appName; | 176 | stream >> appName; |
180 | 177 | ||
181 | if ( !executeBuiltin( appName, QString::null ) ) { | 178 | if ( !executeBuiltin( appName, QString::null ) ) { |
182 | if ( !waitingHeartbeat.contains( appName ) && appKillerName != appName ) { | 179 | if ( !waitingHeartbeat.contains( appName ) && appKillerName != appName ) { |
183 | //qDebug( "Raising: %s", appName.latin1() ); | 180 | //odebug << "Raising: " << appName << "" << oendl; |
184 | QCString channel = "QPE/Application/"; | 181 | QCString channel = "QPE/Application/"; |
185 | channel += appName.latin1(); | 182 | channel += appName.latin1(); |
186 | 183 | ||
187 | // Need to lock it to avoid race conditions with QPEApplication::processQCopFile | 184 | // Need to lock it to avoid race conditions with QPEApplication::processQCopFile |
@@ -216,9 +213,9 @@ void AppLauncher::received(const QCString& msg, const QByteArray& data) | |||
216 | e << apps; | 213 | e << apps; |
217 | } else if ( msg == "appRaised(QString)" ) { | 214 | } else if ( msg == "appRaised(QString)" ) { |
218 | QString appName; | 215 | QString appName; |
219 | stream >> appName; | 216 | stream >> appName; |
220 | qDebug("Got a heartbeat from %s", appName.latin1()); | 217 | odebug << "Got a heartbeat from " << appName << "" << oendl; |
221 | QMap<QString,int>::Iterator it = waitingHeartbeat.find(appName); | 218 | QMap<QString,int>::Iterator it = waitingHeartbeat.find(appName); |
222 | if ( it != waitingHeartbeat.end() ) { | 219 | if ( it != waitingHeartbeat.end() ) { |
223 | killTimer( *it ); | 220 | killTimer( *it ); |
224 | waitingHeartbeat.remove(it); | 221 | waitingHeartbeat.remove(it); |
@@ -239,14 +236,14 @@ void AppLauncher::signalHandler(int) | |||
239 | #ifndef Q_OS_WIN32 | 236 | #ifndef Q_OS_WIN32 |
240 | int status; | 237 | int status; |
241 | pid_t pid = waitpid(-1, &status, WNOHANG); | 238 | pid_t pid = waitpid(-1, &status, WNOHANG); |
242 | /* if (pid == 0 || &status == 0 ) { | 239 | /* if (pid == 0 || &status == 0 ) { |
243 | qDebug("hmm, could not get return value from signal"); | 240 | odebug << "hmm, could not get return value from signal" << oendl; |
244 | } | 241 | } |
245 | */ | 242 | */ |
246 | QApplication::postEvent(appLauncherPtr, new AppStoppedEvent(pid, status) ); | 243 | QApplication::postEvent(appLauncherPtr, new AppStoppedEvent(pid, status) ); |
247 | #else | 244 | #else |
248 | qDebug("Unhandled signal see by AppLauncher::signalHandler(int)"); | 245 | odebug << "Unhandled signal see by AppLauncher::signalHandler(int)" << oendl; |
249 | #endif | 246 | #endif |
250 | } | 247 | } |
251 | 248 | ||
252 | bool AppLauncher::event(QEvent *e) | 249 | bool AppLauncher::event(QEvent *e) |
@@ -272,9 +269,9 @@ void AppLauncher::timerEvent( QTimerEvent *e ) | |||
272 | appKillerName = it.key(); | 269 | appKillerName = it.key(); |
273 | killTimer( id ); | 270 | killTimer( id ); |
274 | waitingHeartbeat.remove( it ); | 271 | waitingHeartbeat.remove( it ); |
275 | 272 | ||
276 | // qDebug("Checking in on %s", appKillerName.latin1()); | 273 | // odebug << "Checking in on " << appKillerName << "" << oendl; |
277 | 274 | ||
278 | // We store this incase the application responds while we're | 275 | // We store this incase the application responds while we're |
279 | // waiting for user input so we know not to delete ourselves. | 276 | // waiting for user input so we know not to delete ourselves. |
280 | appKillerBox = new QMessageBox(tr("Application Problem"), | 277 | appKillerBox = new QMessageBox(tr("Application Problem"), |
@@ -283,9 +280,9 @@ void AppLauncher::timerEvent( QTimerEvent *e ) | |||
283 | QMessageBox::Warning, QMessageBox::Yes, | 280 | QMessageBox::Warning, QMessageBox::Yes, |
284 | QMessageBox::No | QMessageBox::Default, | 281 | QMessageBox::No | QMessageBox::Default, |
285 | QMessageBox::NoButton); | 282 | QMessageBox::NoButton); |
286 | if (appKillerBox->exec() == QMessageBox::Yes) { | 283 | if (appKillerBox->exec() == QMessageBox::Yes) { |
287 | // qDebug("Killing the app!!! Bwuhahahaha!"); | 284 | // odebug << "Killing the app!!! Bwuhahahaha!" << oendl; |
288 | int pid = pidForName(appKillerName); | 285 | int pid = pidForName(appKillerName); |
289 | if ( pid > 0 ) | 286 | if ( pid > 0 ) |
290 | kill( pid ); | 287 | kill( pid ); |
291 | } | 288 | } |
@@ -314,19 +311,19 @@ void AppLauncher::sigStopped(int sigPid, int sigStatus) | |||
314 | 311 | ||
315 | QMap<int,QString>::Iterator it = runningApps.find( sigPid ); | 312 | QMap<int,QString>::Iterator it = runningApps.find( sigPid ); |
316 | if ( it == runningApps.end() ) { | 313 | if ( it == runningApps.end() ) { |
317 | if ( sigPid == qlPid ) { | 314 | if ( sigPid == qlPid ) { |
318 | qDebug( "quicklauncher stopped" ); | 315 | odebug << "quicklauncher stopped" << oendl; |
319 | qlPid = 0; | 316 | qlPid = 0; |
320 | qlReady = FALSE; | 317 | qlReady = FALSE; |
321 | QFile::remove("/tmp/qcop-msg-quicklauncher" ); | 318 | QFile::remove("/tmp/qcop-msg-quicklauncher" ); |
322 | QTimer::singleShot( 2000, this, SLOT(createQuickLauncher()) ); | 319 | QTimer::singleShot( 2000, this, SLOT(createQuickLauncher()) ); |
323 | } | 320 | } |
324 | /* | 321 | /* |
325 | if ( sigPid == -1 ) | 322 | if ( sigPid == -1 ) |
326 | qDebug("non-qtopia application exited (disregarded)"); | 323 | odebug << "non-qtopia application exited (disregarded)" << oendl; |
327 | else | 324 | else |
328 | qDebug("==== no pid matching %d in list, definite bug", sigPid); | 325 | odebug << "==== no pid matching " << sigPid << " in list, definite bug" << oendl; |
329 | */ | 326 | */ |
330 | return; | 327 | return; |
331 | } | 328 | } |
332 | QString appName = *it; | 329 | QString appName = *it; |
@@ -368,9 +365,9 @@ void AppLauncher::sigStopped(int sigPid, int sigStatus) | |||
368 | } | 365 | } |
369 | /* | 366 | /* |
370 | // debug info | 367 | // debug info |
371 | for (it = runningApps.begin(); it != runningApps.end(); ++it) { | 368 | for (it = runningApps.begin(); it != runningApps.end(); ++it) { |
372 | qDebug("running according to internal list: %s, with pid %d", (*it).data(), it.key() ); | 369 | odebug << "running according to internal list: " << (*it).data() << ", with pid " << it.key() << "" << oendl; |
373 | } | 370 | } |
374 | */ | 371 | */ |
375 | 372 | ||
376 | #ifdef QTOPIA_PROGRAM_MONITOR | 373 | #ifdef QTOPIA_PROGRAM_MONITOR |
@@ -402,9 +399,9 @@ void AppLauncher::sigStopped(int sigPid, int sigStatus) | |||
402 | } else { | 399 | } else { |
403 | QFileInfo fi(QString::fromLatin1("/tmp/qcop-msg-") + appName); | 400 | QFileInfo fi(QString::fromLatin1("/tmp/qcop-msg-") + appName); |
404 | if ( fi.exists() && fi.size() ) { | 401 | if ( fi.exists() && fi.size() ) { |
405 | emit terminated(sigPid, appName); | 402 | emit terminated(sigPid, appName); |
406 | qWarning("Re executing obmitted for %s", appName.latin1() ); | 403 | owarn << "Re executing obmitted for " << appName << "" << oendl; |
407 | // execute( appName, QString::null ); | 404 | // execute( appName, QString::null ); |
408 | return; | 405 | return; |
409 | } | 406 | } |
410 | } | 407 | } |
@@ -416,9 +413,9 @@ void AppLauncher::sigStopped(int sigPid, int sigStatus) | |||
416 | } | 413 | } |
417 | #else | 414 | #else |
418 | void AppLauncher::sigStopped(int sigPid, int sigStatus) | 415 | void AppLauncher::sigStopped(int sigPid, int sigStatus) |
419 | { | 416 | { |
420 | qDebug("Unhandled signal : AppLauncher::sigStopped(int sigPid, int sigStatus)"); | 417 | odebug << "Unhandled signal : AppLauncher::sigStopped(int sigPid, int sigStatus)" << oendl; |
421 | } | 418 | } |
422 | #endif // Q_OS_WIN32 | 419 | #endif // Q_OS_WIN32 |
423 | 420 | ||
424 | bool AppLauncher::isRunning(const QString &app) | 421 | bool AppLauncher::isRunning(const QString &app) |
@@ -427,9 +424,9 @@ bool AppLauncher::isRunning(const QString &app) | |||
427 | if ( *it == app ) { | 424 | if ( *it == app ) { |
428 | #ifdef Q_OS_UNIX | 425 | #ifdef Q_OS_UNIX |
429 | pid_t t = ::__getpgid( it.key() ); | 426 | pid_t t = ::__getpgid( it.key() ); |
430 | if ( t == -1 ) { | 427 | if ( t == -1 ) { |
431 | qDebug("appLauncher bug, %s believed running, but pid %d is not existing", app.data(), it.key() ); | 428 | odebug << "appLauncher bug, " << app.data() << " believed running, but pid " << it.key() << " is not existing" << oendl; |
432 | runningApps.remove( it.key() ); | 429 | runningApps.remove( it.key() ); |
433 | return FALSE; | 430 | return FALSE; |
434 | } | 431 | } |
435 | #endif | 432 | #endif |
@@ -480,9 +477,9 @@ bool AppLauncher::executeBuiltin(const QString &c, const QString &document) | |||
480 | } | 477 | } |
481 | 478 | ||
482 | bool AppLauncher::execute(const QString &c, const QString &docParam, bool noRaise) | 479 | bool AppLauncher::execute(const QString &c, const QString &docParam, bool noRaise) |
483 | { | 480 | { |
484 | qWarning("AppLauncher::execute '%s' '%s'", (const char*) c, (const char*) docParam ); | 481 | owarn << "AppLauncher::execute '" << c << "' '" << docParam << "'" << oendl; |
485 | // Convert the command line in to a list of arguments | 482 | // Convert the command line in to a list of arguments |
486 | QStringList list = QStringList::split(QRegExp(" *"),c); | 483 | QStringList list = QStringList::split(QRegExp(" *"),c); |
487 | QStringList arglist = QStringList::split(QRegExp(" *"),docParam); | 484 | QStringList arglist = QStringList::split(QRegExp(" *"),docParam); |
488 | for ( QStringList::Iterator it = arglist.begin(); it != arglist.end(); ++it ) | 485 | for ( QStringList::Iterator it = arglist.begin(); it != arglist.end(); ++it ) |
@@ -547,9 +544,9 @@ bool AppLauncher::execute(const QString &c, const QString &docParam, bool noRais | |||
547 | if ( qlPid && qlReady && QFile::exists( QPEApplication::qpeDir()+"plugins/application/lib"+args[0] + ".dylib" ) ) { | 544 | if ( qlPid && qlReady && QFile::exists( QPEApplication::qpeDir()+"plugins/application/lib"+args[0] + ".dylib" ) ) { |
548 | #else | 545 | #else |
549 | if ( qlPid && qlReady && QFile::exists( QPEApplication::qpeDir()+"plugins/application/lib"+args[0] + ".so" ) ) { | 546 | if ( qlPid && qlReady && QFile::exists( QPEApplication::qpeDir()+"plugins/application/lib"+args[0] + ".so" ) ) { |
550 | #endif /* Q_OS_MACX */ | 547 | #endif /* Q_OS_MACX */ |
551 | qDebug( "Quick launching: %s", args[0] ); | 548 | odebug << "Quick launching: " << args[0] << "" << oendl; |
552 | if ( getuid() == 0 ) | 549 | if ( getuid() == 0 ) |
553 | setpriority( PRIO_PROCESS, qlPid, 0 ); | 550 | setpriority( PRIO_PROCESS, qlPid, 0 ); |
554 | QCString qlch("QPE/QuickLauncher-"); | 551 | QCString qlch("QPE/QuickLauncher-"); |
555 | qlch += QString::number(qlPid); | 552 | qlch += QString::number(qlPid); |
@@ -583,9 +580,9 @@ bool AppLauncher::execute(const QString &c, const QString &docParam, bool noRais | |||
583 | for (int i=0; i < slist.count(); i++) | 580 | for (int i=0; i < slist.count(); i++) |
584 | proc->addArgument(args[i]); | 581 | proc->addArgument(args[i]); |
585 | connect(proc, SIGNAL(processExited()), this, SLOT(processExited())); | 582 | connect(proc, SIGNAL(processExited()), this, SLOT(processExited())); |
586 | if (!proc->start()){ | 583 | if (!proc->start()){ |
587 | qDebug("Unable to start application %s", args[0]); | 584 | odebug << "Unable to start application " << args[0] << "" << oendl; |
588 | }else{ | 585 | }else{ |
589 | PROCESS_INFORMATION *procInfo = (PROCESS_INFORMATION *)proc->processIdentifier(); | 586 | PROCESS_INFORMATION *procInfo = (PROCESS_INFORMATION *)proc->processIdentifier(); |
590 | if (procInfo){ | 587 | if (procInfo){ |
591 | DWORD pid = procInfo->dwProcessId; | 588 | DWORD pid = procInfo->dwProcessId; |
@@ -593,13 +590,13 @@ bool AppLauncher::execute(const QString &c, const QString &docParam, bool noRais | |||
593 | runningAppsProc.append(proc); | 590 | runningAppsProc.append(proc); |
594 | emit launched(pid, QString(args[0])); | 591 | emit launched(pid, QString(args[0])); |
595 | QCopEnvelope e("QPE/System", "busy()"); | 592 | QCopEnvelope e("QPE/System", "busy()"); |
596 | }else{ | 593 | }else{ |
597 | qDebug("Unable to read process inforation #1 for %s", args[0]); | 594 | odebug << "Unable to read process inforation #1 for " << args[0] << "" << oendl; |
598 | } | 595 | } |
599 | } | 596 | } |
600 | }else{ | 597 | }else{ |
601 | qDebug("Unable to create process for application %s", args[0]); | 598 | odebug << "Unable to create process for application " << args[0] << "" << oendl; |
602 | return FALSE; | 599 | return FALSE; |
603 | } | 600 | } |
604 | #endif | 601 | #endif |
605 | #endif //QT_NO_QWS_MULTIPROCESS | 602 | #endif //QT_NO_QWS_MULTIPROCESS |
@@ -677,18 +674,18 @@ void AppLauncher::createQuickLauncher() | |||
677 | // Used only by Win32 | 674 | // Used only by Win32 |
678 | void AppLauncher::processExited() | 675 | void AppLauncher::processExited() |
679 | { | 676 | { |
680 | #ifdef Q_OS_WIN32 | 677 | #ifdef Q_OS_WIN32 |
681 | qDebug("AppLauncher::processExited()"); | 678 | odebug << "AppLauncher::processExited()" << oendl; |
682 | bool found = FALSE; | 679 | bool found = FALSE; |
683 | QProcess *proc = (QProcess *) sender(); | 680 | QProcess *proc = (QProcess *) sender(); |
684 | if (!proc){ | 681 | if (!proc){ |
685 | qDebug("Interanl error NULL proc"); | 682 | odebug << "Interanl error NULL proc" << oendl; |
686 | return; | 683 | return; |
687 | } | 684 | } |
688 | 685 | ||
689 | QString appName = proc->arguments()[0]; | 686 | QString appName = proc->arguments()[0]; |
690 | qDebug("Removing application %s", appName.latin1()); | 687 | odebug << "Removing application " << appName << "" << oendl; |
691 | runningAppsProc.remove(proc); | 688 | runningAppsProc.remove(proc); |
692 | 689 | ||
693 | QMap<QString,int>::Iterator hbit = waitingHeartbeat.find(appName); | 690 | QMap<QString,int>::Iterator hbit = waitingHeartbeat.find(appName); |
694 | if ( hbit != waitingHeartbeat.end() ) { | 691 | if ( hbit != waitingHeartbeat.end() ) { |
@@ -713,9 +710,9 @@ void AppLauncher::processExited() | |||
713 | if (found){ | 710 | if (found){ |
714 | emit terminated(it.key(), it.data()); | 711 | emit terminated(it.key(), it.data()); |
715 | runningApps.remove(it.key()); | 712 | runningApps.remove(it.key()); |
716 | }else{ | 713 | }else{ |
717 | qDebug("Internal error application %s not listed as running", appName.latin1()); | 714 | odebug << "Internal error application " << appName << " not listed as running" << oendl; |
718 | } | 715 | } |
719 | 716 | ||
720 | #endif | 717 | #endif |
721 | } | 718 | } |