From kde-core-devel Thu Feb 24 02:52:08 2005 From: George Staikos Date: Thu, 24 Feb 2005 02:52:08 +0000 To: kde-core-devel Subject: [PATCH] fix process spinning out of control Message-Id: <200502232152.08201.staikos () kde ! org> X-MARC-Message: https://marc.info/?l=kde-core-devel&m=110921354325275 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--Boundary-00=_YFUHCaTBQVv6VO6" --Boundary-00=_YFUHCaTBQVv6VO6 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline When nspluginviewer is running and the konqueror window crashes or is killed with signal 9, the viewer process doesn't exit and thinks it's still embedded, resulting in an infinite loop of X errors. It uses quite a bit of CPU, and looks like this: X Error: BadDrawable (invalid Pixmap or Window parameter) 9 Major opcode: 144 Minor opcode: 3 Resource id: 0x3c00023 X Error: BadWindow (invalid Window parameter) 3 Major opcode: 3 Minor opcode: 0 Resource id: 0x3c00023 X Error: BadDrawable (invalid Pixmap or Window parameter) 9 Major opcode: 144 Minor opcode: 3 Resource id: 0x3c00023 X Error: BadWindow (invalid Window parameter) 3 Major opcode: 3 Minor opcode: 0 Resource id: 0x3c00023 X Error: BadDrawable (invalid Pixmap or Window parameter) 9 Major opcode: 144 Minor opcode: 3 Resource id: 0x3c00023 [etc] This patch changes the viewer to keep track of the dcop clients that are connected to it and kills their plugins when they go away. If all clients go away, it exits. I think this is a major fix and important for 3.4. Any objections (other than removing the debug output)? (There was a bug reported against this, and while the real problem is that Konqueror crashes, this should be fixed...) -- George Staikos KDE Developer http://www.kde.org/ Staikos Computing Services Inc. http://www.staikos.net/ --Boundary-00=_YFUHCaTBQVv6VO6 Content-Type: text/x-diff; charset="us-ascii"; name="nsplugins-nospin.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="nsplugins-nospin.patch" Index: nsplugin.cpp =================================================================== RCS file: /home/kde/kdebase/nsplugins/viewer/nsplugin.cpp,v retrieving revision 1.119 diff -u -3 -p -r1.119 nsplugin.cpp --- nsplugin.cpp 21 Feb 2005 12:04:14 -0000 1.119 +++ nsplugin.cpp 24 Feb 2005 02:43:17 -0000 @@ -1192,6 +1192,10 @@ NSPluginViewer::NSPluginViewer( QCString : DCOPObject(dcopId), QObject( parent, name ) { _classes.setAutoDelete( true ); + connect(KApplication::dcopClient(), + SIGNAL(applicationRemoved(const QCString&)), + this, + SLOT(appUnregistered(const QCString&))); } @@ -1201,6 +1205,28 @@ NSPluginViewer::~NSPluginViewer() } +void NSPluginViewer::appUnregistered(const QCString& id) { + kdDebug() << "APP [" << id << "] unregistered" << endl; + if (id.isEmpty()) { + return; + } + + QDictIterator it(_classes); + NSPluginClass *c; + while ( (c = it.current()) ) { + QString key = it.currentKey(); + ++it; + if (c->app() == id) { + _classes.remove(key); + } + } + + if (_classes.isEmpty()) { + shutdown(); + } +} + + void NSPluginViewer::shutdown() { kdDebug(1431) << "NSPluginViewer::shutdown" << endl; @@ -1222,6 +1248,13 @@ DCOPRef NSPluginViewer::newClass( QStrin if ( !cls ) { // create new class cls = new NSPluginClass( plugin, this ); + QCString id = ""; + DCOPClient *dc = callingDcopClient(); + if (dc) { + id = dc->senderId(); + } + kdDebug() << "Setting caller id to [" << id << "]" << endl; + cls->setApp(id); if ( cls->error() ) { kdError(1431) << "Can't create plugin class" << endl; delete cls; Index: nsplugin.h =================================================================== RCS file: /home/kde/kdebase/nsplugins/viewer/nsplugin.h,v retrieving revision 1.43 diff -u -3 -p -r1.43 nsplugin.h --- nsplugin.h 21 Feb 2005 10:13:12 -0000 1.43 +++ nsplugin.h 24 Feb 2005 02:43:18 -0000 @@ -69,8 +69,8 @@ public: NSPluginStreamBase( class NSPluginInstance *instance ); ~NSPluginStreamBase(); - KURL url() { return _url; }; - int pos() { return _pos; }; + KURL url() { return _url; } + int pos() { return _pos; } void stop(); signals: @@ -79,10 +79,10 @@ signals: protected: void finish( bool err ); bool pump(); - bool error() { return _error; }; + bool error() { return _error; } void queue( const QByteArray &data ); bool create( const QString& url, const QString& mimeType, void *notify, bool forceNotify = false ); - int tries() { return _tries; }; + int tries() { return _tries; } void inform( ); class NSPluginInstance *_instance; @@ -167,7 +167,7 @@ public: // DCOP functions void shutdown(); - int winId() { return XtWindow(_toplevel); }; + int winId() { return XtWindow(_form); } int setWindow(int remove=0); void resizePlugin(int w, int h); void javascriptResult(int id, QString result); @@ -275,7 +275,10 @@ public: QStringList argn, QStringList argv, QString appId, QString callbackId ); void destroyInstance( NSPluginInstance* inst ); - bool error() { return _error; }; + bool error() { return _error; } + + void setApp(const QCString& app) { _app = app; } + const QCString& app() const { return _app; } protected slots: void timer(); @@ -299,6 +302,8 @@ private: QPtrList _instances; QPtrList _trash; + + QCString _app; }; @@ -312,6 +317,9 @@ public: void shutdown(); DCOPRef newClass( QString plugin ); +private slots: + void appUnregistered(const QCString& id); + private: QDict _classes; }; Index: viewer.cpp =================================================================== RCS file: /home/kde/kdebase/nsplugins/viewer/viewer.cpp,v retrieving revision 1.32 diff -u -3 -p -r1.32 viewer.cpp --- viewer.cpp 18 Nov 2004 22:03:00 -0000 1.32 +++ viewer.cpp 24 Feb 2005 02:43:18 -0000 @@ -271,6 +271,8 @@ int main(int argc, char** argv) else g_dcopId = dcop->registerAs("nspluginviewer"); + dcop->setNotifications(true); + // create dcop interface kdDebug(1430) << "7 - new NSPluginViewer" << endl; NSPluginViewer *viewer = new NSPluginViewer( "viewer", 0 ); --Boundary-00=_YFUHCaTBQVv6VO6--