[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-pim
Subject: Re: [Kde-pim] posix file locking in libkabc
From: Tobias Koenig <tokoe () kde ! org>
Date: 2002-09-05 17:22:39
[Download RAW message or body]
On Thu, Sep 05, 2002 at 06:13:40PM +0200, Tobias Koenig wrote:
> On Thu, Sep 05, 2002 at 12:25:27PM +1000, Don Sanders wrote:
Hi,
> > Could you send a patch to the list before committing, it's easier for
> > me to scan them this way, (even weeks later if I have to read mail in
> > bulk).
> Ok, I'll do.
And here it is.
Additional to the signal handler stuff, I've added the second ::self(bool)
method that was not present (how could it compile without?!?).
Furthermore 3 kdDebug fixes in distributionlisteditor.
Ok to commit?
Ciao,
Tobias
--
In a world without walls and fences who
needs Windows and Gates???
["libkabc.diff" (text/plain)]
? libkabc.diff
? err.txt
? plugins/sql.new
Index: addressbook.cpp
===================================================================
RCS file: /home/kde/kdelibs/kabc/addressbook.cpp,v
retrieving revision 1.41
diff -u -b -p -r1.41 addressbook.cpp
--- addressbook.cpp 2002/09/01 10:32:07 1.41
+++ addressbook.cpp 2002/09/05 17:19:52
@@ -588,4 +588,13 @@ void AddressBook::setStandardResource( R
Resource *AddressBook::standardResource()
{
return d->mStandardResource;
+}
+
+void AddressBook::cleanUp()
+{
+ for ( uint i = 0; i < d->mResources.count(); ++i ) {
+ Resource *resource = d->mResources.at( i );
+ if ( !resource->readOnly() )
+ resource->cleanUp();
+ }
}
Index: addressbook.h
===================================================================
RCS file: /home/kde/kdelibs/kabc/addressbook.h,v
retrieving revision 1.27
diff -u -b -p -r1.27 addressbook.h
--- addressbook.h 2002/09/01 10:32:07 1.27
+++ addressbook.h 2002/09/05 17:19:52
@@ -277,6 +277,11 @@ class AddressBook : public QObject
*/
void error( const QString& );
+ /**
+ Query all resources to clean up their lock files
+ */
+ void cleanUp();
+
signals:
/**
Emitted, when the address book has changed on disk.
Index: distributionlisteditor.cpp
===================================================================
RCS file: /home/kde/kdelibs/kabc/distributionlisteditor.cpp,v
retrieving revision 1.19
diff -u -b -p -r1.19 distributionlisteditor.cpp
--- distributionlisteditor.cpp 2002/08/05 22:48:19 1.19
+++ distributionlisteditor.cpp 2002/09/05 17:19:53
@@ -117,7 +117,7 @@ DistributionListEditor::DistributionList
QWidget( parent ),
mAddressBook( addressBook )
{
- kdDebug() << "DistributionListEditor()" << endl;
+ kdDebug(5700) << "DistributionListEditor()" << endl;
QBoxLayout *topLayout = new QVBoxLayout( this );
topLayout->setMargin( KDialog::marginHint() );
@@ -174,7 +174,7 @@ DistributionListEditor::DistributionList
DistributionListEditor::~DistributionListEditor()
{
- kdDebug() << "~DistributionListEditor()" << endl;
+ kdDebug(5700) << "~DistributionListEditor()" << endl;
mManager->save();
delete mManager;
@@ -220,13 +220,13 @@ void DistributionListEditor::addEntry()
dynamic_cast<AddresseeItem *>( mAddresseeView->selectedItem() );
if( !addresseeItem ) {
- kdDebug() << "DLE::addEntry(): No addressee selected." << endl;
+ kdDebug(5700) << "DLE::addEntry(): No addressee selected." << endl;
return;
}
DistributionList *list = mManager->list( mNameCombo->currentText() );
if ( !list ) {
- kdDebug() << "DLE::addEntry(): No dist list '" << mNameCombo->currentText() << "'" << endl;
+ kdDebug(5700) << "DLE::addEntry(): No dist list '" << mNameCombo->currentText() << "'" << endl;
return;
}
Index: resource.cpp
===================================================================
RCS file: /home/kde/kdelibs/kabc/resource.cpp,v
retrieving revision 1.14
diff -u -b -p -r1.14 resource.cpp
--- resource.cpp 2002/07/21 17:57:15 1.14
+++ resource.cpp 2002/09/05 17:19:53
@@ -74,6 +74,11 @@ void Resource::removeAddressee( const Ad
// do nothing
}
+void Resource::cleanUp()
+{
+ // do nothing
+}
+
void Resource::setReadOnly( bool value )
{
mReadOnly = value;
Index: resource.h
===================================================================
RCS file: /home/kde/kdelibs/kabc/resource.h,v
retrieving revision 1.15
diff -u -b -p -r1.15 resource.h
--- resource.h 2002/07/21 17:57:15 1.15
+++ resource.h 2002/09/05 17:19:53
@@ -105,6 +105,12 @@ public:
virtual void removeAddressee( const Addressee& addr );
/**
+ * This method is called by an error handler if the application
+ * crashed
+ */
+ virtual void cleanUp();
+
+ /**
* Mark the resource to read-only.
*/
virtual void setReadOnly( bool value );
Index: resourcefile.cpp
===================================================================
RCS file: /home/kde/kdelibs/kabc/resourcefile.cpp,v
retrieving revision 1.18
diff -u -b -p -r1.18 resourcefile.cpp
--- resourcefile.cpp 2002/08/05 21:25:39 1.18
+++ resourcefile.cpp 2002/09/05 17:19:54
@@ -214,4 +214,9 @@ void ResourceFile::removeAddressee( cons
QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) );
}
+void ResourceFile::cleanUp()
+{
+ unlock( mFileName );
+}
+
#include "resourcefile.moc"
Index: resourcefile.h
===================================================================
RCS file: /home/kde/kdelibs/kabc/resourcefile.h,v
retrieving revision 1.13
diff -u -b -p -r1.13 resourcefile.h
--- resourcefile.h 2002/08/05 21:25:39 1.13
+++ resourcefile.h 2002/09/05 17:19:54
@@ -118,6 +118,12 @@ public:
*/
void removeAddressee( const Addressee& addr );
+ /**
+ * This method is called by an error handler if the application
+ * crashed
+ */
+ virtual void cleanUp();
+
protected slots:
void fileChanged();
Index: stdaddressbook.cpp
===================================================================
RCS file: /home/kde/kdelibs/kabc/stdaddressbook.cpp,v
retrieving revision 1.29
diff -u -b -p -r1.29 stdaddressbook.cpp
--- stdaddressbook.cpp 2002/08/08 13:02:44 1.29
+++ stdaddressbook.cpp 2002/09/05 17:19:56
@@ -19,10 +19,13 @@
*/
#include <kapplication.h>
+#include <kcrash.h>
#include <kdebug.h>
#include <kstandarddirs.h>
#include <ksimpleconfig.h>
+#include <signal.h>
+
#include "stdaddressbook.h"
#include "resourcefactory.h"
@@ -31,6 +34,40 @@
using namespace KABC;
+extern "C" {
+
+static void setSignalHandler( void (*handler)(int) );
+
+// Crash recovery signal handler
+static void signalHandler( int sigId )
+{
+ setSignalHandler( SIG_DFL );
+ fprintf( stderr, "*** libkabc got signal %d (Exiting)\n", sigId );
+ // try to cleanup all lock files
+ StdAddressBook::self()->cleanUp();
+ ::exit(-1);
+}
+
+// Crash recovery signal handler
+static void crashHandler( int sigId )
+{
+ setSignalHandler( SIG_DFL );
+ fprintf( stderr, "*** libkabc got signal %d (Crashing)\n", sigId );
+ // try to cleanup all lock files
+ StdAddressBook::self()->cleanUp();
+ // Return to DrKonqi.
+}
+
+static void setSignalHandler( void (*handler)(int) )
+{
+ signal( SIGKILL, handler );
+ signal( SIGTERM, handler );
+ signal( SIGHUP, handler );
+ KCrash::setEmergencySaveFunction( crashHandler );
+}
+
+}
+
AddressBook *StdAddressBook::mSelf = 0;
QString StdAddressBook::fileName()
@@ -47,13 +84,22 @@ AddressBook *StdAddressBook::self()
{
kdDebug(5700) << "StdAddressBook::self()" << endl;
- if ( !mSelf ) {
+ if ( !mSelf )
mSelf = new StdAddressBook;
- }
return mSelf;
}
+AddressBook *StdAddressBook::self( bool onlyFastResources )
+{
+ kdDebug(5700) << "StdAddressBook::self()" << endl;
+
+ if ( !mSelf )
+ mSelf = new StdAddressBook( onlyFastResources );
+
+ return mSelf;
+}
+
bool StdAddressBook::save()
{
kdDebug(5700) << "StdAddressBook::save()" << endl;
@@ -129,6 +175,8 @@ void StdAddressBook::init( bool onlyFast
}
load();
+
+ setSignalHandler( signalHandler );
}
void StdAddressBook::close()
Index: plugins/dir/resourcedir.cpp
===================================================================
RCS file: /home/kde/kdelibs/kabc/plugins/dir/resourcedir.cpp,v
retrieving revision 1.3
diff -u -b -p -r1.3 resourcedir.cpp
--- plugins/dir/resourcedir.cpp 2002/08/11 17:25:51 1.3
+++ plugins/dir/resourcedir.cpp 2002/09/05 17:19:57
@@ -256,4 +256,9 @@ void ResourceDir::removeAddressee( const
QFile::remove( mPath + "/" + addr.uid() );
}
+void ResourceDir::cleanUp()
+{
+ unlock( mPath );
+}
+
#include "resourcedir.moc"
Index: plugins/dir/resourcedir.h
===================================================================
RCS file: /home/kde/kdelibs/kabc/plugins/dir/resourcedir.h,v
retrieving revision 1.2
diff -u -b -p -r1.2 resourcedir.h
--- plugins/dir/resourcedir.h 2002/08/05 21:25:39 1.2
+++ plugins/dir/resourcedir.h 2002/09/05 17:19:57
@@ -55,6 +55,12 @@ public:
*/
void removeAddressee( const Addressee& addr );
+ /**
+ * This method is called by an error handler if the application
+ * crashed
+ */
+ virtual void cleanUp();
+
protected slots:
void pathChanged();
_______________________________________________
kde-pim mailing list
kde-pim@mail.kde.org
http://mail.kde.org/mailman/listinfo/kde-pim
kde-pim home page at http://pim.kde.org/
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic