[PATCH] konqueror crash recovery

Alexander Kellett kelletta at eidetica.com
Sat May 25 15:25:24 BST 2002


On Sat, May 25, 2002 at 01:01:58PM +0200, David Faure wrote:
> Hmm, so this is a binary format now?
> In case of filesystem corruption this has bad side effects - reading the crash
> logfile could make the app crash, quite a recursive problem ;-)
> ksycoca, konq_history and other similar files have shown this problem in the past...

okay. thanks for that info, i'd thought maybe that binary
was safer as it could check string lengths and other things
that a text format couldn't.

> What about coming back to a text-based format, but with a more basic
> writeBlock(QCString) approach?

True, binary sucks I just hadn't seen writeBlock :) 
Here's a new version...

> One compilation-time nitpick: please use "class QFile;" and "class QDataStream;" 
> in konq_mainwindow.h, and move the #includes to konq_mainwindow.cpp.

Aaahh, done. 
I always wonder about such stuff, i'll stick this in my CPP_TIPS file ;-)

mvg,
Alex
-------------- next part --------------
? .konq_mainwindow.h.swp
? crashlog.patch
? history/Makefile
? history/Makefile.in
? keditbookmarks/TODO
? keditbookmarks/tests
Index: KonquerorIface.cc
===================================================================
RCS file: /home/kde/kdebase/konqueror/KonquerorIface.cc,v
retrieving revision 1.27
diff -u -p -r1.27 KonquerorIface.cc
--- KonquerorIface.cc	2002/02/22 13:55:34	1.27
+++ KonquerorIface.cc	2002/05/25 14:23:18
@@ -27,6 +27,7 @@
 #include <kapplication.h>
 #include <dcopclient.h>
 #include <kdebug.h>
+#include <qfile.h>
 
 KonquerorIface::KonquerorIface()
  : DCOPObject( "KonquerorIface" )
@@ -171,6 +172,11 @@ void KonquerorIface::updateProfileList()
   QPtrListIterator<KonqMainWindow> it( *mainWindows );
   for (; it.current(); ++it )
     it.current()->viewManager()->profileListDirty( false );
+}
+
+QString KonquerorIface::crashLogFile()
+{
+  return KonqMainWindow::s_crashlog_file->name();
 }
 
 QValueList<DCOPRef> KonquerorIface::getWindows()
Index: KonquerorIface.h
===================================================================
RCS file: /home/kde/kdebase/konqueror/KonquerorIface.h,v
retrieving revision 1.24
diff -u -p -r1.24 KonquerorIface.h
--- KonquerorIface.h	2002/02/22 13:55:34	1.24
+++ KonquerorIface.h	2002/05/25 14:23:18
@@ -37,6 +37,7 @@ public:
   ~KonquerorIface();
 
 k_dcop:
+
   /**
    * Opens a new window for the given @p url (using createSimpleWindow, i.e. a single view)
    */
@@ -130,6 +131,11 @@ k_dcop:
    * Called by kcontrol when the global configuration changes
    */
   ASYNC reparseConfiguration();
+
+  /**
+   * @return the name of the instance's crash log file
+   */
+  QString crashLogFile();
 
   /**
    * @return a list of references to all the windows
Index: konq_main.cc
===================================================================
RCS file: /home/kde/kdebase/konqueror/konq_main.cc,v
retrieving revision 1.112
diff -u -p -r1.112 konq_main.cc
--- konq_main.cc	2002/05/09 06:47:21	1.112
+++ konq_main.cc	2002/05/25 14:23:18
@@ -23,6 +23,7 @@
 #include "konq_mainwindow.h"
 #include "KonquerorIface.h"
 
+#include <ktempfile.h>
 #include <klocale.h>
 #include <kstandarddirs.h>
 #include <kdebug.h>
@@ -59,6 +60,11 @@ int main( int argc, char **argv )
 
   KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
 
+  KTempFile crashlog_file(locateLocal("tmp", "konqueror-crashlog"), ".xml");
+
+  KonqMainWindow::s_crashlog_file = new QFile( crashlog_file.name() );
+  KonqMainWindow::s_crashlog_file->open( IO_WriteOnly );
+
   if ( kapp->isRestored() )
   {
     int n = 1;
@@ -135,6 +141,8 @@ int main( int argc, char **argv )
      if ( w->testWFlags( Qt::WDestructiveClose ) )
           delete w;
   }  
+
+  KonqMainWindow::s_crashlog_file->remove();
 
   return 0;
 }
Index: konq_mainwindow.cc
===================================================================
RCS file: /home/kde/kdebase/konqueror/konq_mainwindow.cc,v
retrieving revision 1.1000
diff -u -p -r1.1000 konq_mainwindow.cc
--- konq_mainwindow.cc	2002/05/21 09:44:04	1.1000
+++ konq_mainwindow.cc	2002/05/25 14:23:21
@@ -51,6 +51,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
+#include <qfile.h>
 #include <qclipboard.h>
 #include <qmetaobject.h>
 #include <qvbox.h>
@@ -93,6 +94,7 @@ template class QPtrList<KToggleAction>;
 QPtrList<KonqMainWindow> *KonqMainWindow::s_lstViews = 0;
 KConfig * KonqMainWindow::s_comboConfig = 0;
 KCompletion * KonqMainWindow::s_pCompletion = 0;
+QFile * KonqMainWindow::s_crashlog_file = 0;
 
 KonqMainWindow::KonqMainWindow( const KURL &initialURL, bool openInitialURL, const char *name )
  : KParts::MainWindow( name, WDestructiveClose | WStyle_ContextHelp )
Index: konq_mainwindow.h
===================================================================
RCS file: /home/kde/kdebase/konqueror/konq_mainwindow.h,v
retrieving revision 1.356
diff -u -p -r1.356 konq_mainwindow.h
--- konq_mainwindow.h	2002/05/07 14:25:17	1.356
+++ konq_mainwindow.h	2002/05/25 14:23:21
@@ -41,6 +41,7 @@
 #include "konq_combo.h"
 #include "konq_frame.h"
 
+class QFile;
 class KAction;
 class KActionCollection;
 class KActionMenu;
@@ -636,6 +637,10 @@ private:
   bool m_urlCompletionStarted;
 
   bool m_bBackRightClick;
+
+public:
+
+  static QFile *s_crashlog_file;
 };
 
 #endif
Index: konq_view.cc
===================================================================
RCS file: /home/kde/kdebase/konqueror/konq_view.cc,v
retrieving revision 1.295
diff -u -p -r1.295 konq_view.cc
--- konq_view.cc	2002/05/07 15:13:59	1.295
+++ konq_view.cc	2002/05/25 14:23:22
@@ -19,6 +19,7 @@
 
 
 #include "konq_view.h"
+#include "kapplication.h"
 #include "KonqViewIface.h"
 #include "konq_frame.h"
 #include "konq_run.h"
@@ -65,6 +66,8 @@ KonqView::KonqView( KonqViewFactory &vie
   m_pPart = 0L;
   m_dcopObject = 0L;
 
+  m_randID = KApplication::random();
+
   m_service = service;
   m_partServiceOffers = partServiceOffers;
   m_appServiceOffers = appServiceOffers;
@@ -91,6 +94,14 @@ KonqView::~KonqView()
 {
   kdDebug(1202) << "KonqView::~KonqView : part = " << m_pPart << endl;
 
+  // AK - stupid code duplication, see below comment
+  if (KonqMainWindow::s_crashlog_file) {
+     QString part_url = (m_pPart)?(m_pPart->url().url()):(QString(""));
+     QCString lines = ( QString("close(%1):%2\n").arg(m_randID,0,16).arg(part_url) ).utf8();
+     KonqMainWindow::s_crashlog_file->writeBlock(lines,lines.length());
+     KonqMainWindow::s_crashlog_file->flush();
+  }
+
   // We did so ourselves for passive views
   if (m_pPart != 0L)
   {
@@ -108,6 +119,17 @@ void KonqView::openURL( const KURL &url,
 {
   kdDebug(1202) << "KonqView::openURL url=" << url.url() << " locationBarURL=" << locationBarURL << endl;
   setServiceTypeInExtension();
+
+  // TODO - AK - could be abstracted to prevent duplication here 
+  //             & in destructor & in the importer
+  if (KonqMainWindow::s_crashlog_file) {
+     QString part_url = (m_pPart)?(m_pPart->url().url()):(QString(""));
+     QCString lines = ( QString("opened(%1):%2\nclosed(%3):%4\n")
+                           .arg(m_randID,0,16).arg(part_url)
+                           .arg(m_randID,0,16).arg(url.url()) ).utf8();
+     KonqMainWindow::s_crashlog_file->writeBlock(lines,lines.length());
+     KonqMainWindow::s_crashlog_file->flush();
+  }
 
   KParts::BrowserExtension *ext = browserExtension();
   KParts::URLArgs args;
Index: konq_view.h
===================================================================
RCS file: /home/kde/kdebase/konqueror/konq_view.h,v
retrieving revision 1.149
diff -u -p -r1.149 konq_view.h
--- konq_view.h	2002/05/07 14:25:17	1.149
+++ konq_view.h	2002/05/25 14:23:22
@@ -387,6 +387,7 @@ protected:
   KonqViewIface * m_dcopObject;
   KonqBrowserInterface *m_browserIface;
   bool m_bBackRightClick;
+  int m_randID;
 };
 
 #endif


More information about the kfm-devel mailing list