From 9ffa4cabbcac60555f0656640e603f4830a7cb98 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 27 Feb 2014 23:35:50 +0000 Subject: Fix crash in BackupStoreContext with no HousekeepingInterface pointer. Rename mrDaemon to mpHousekeeping and make it a pointer, so that it can officially be NULL, and don't crash if it is, and we fail to get a lock on the account. --- lib/backupstore/BackupProtocol.h | 2 +- lib/backupstore/BackupStoreContext.cpp | 8 ++++---- lib/backupstore/BackupStoreContext.h | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) (limited to 'lib/backupstore') diff --git a/lib/backupstore/BackupProtocol.h b/lib/backupstore/BackupProtocol.h index d2fe8b7f..8736b44f 100644 --- a/lib/backupstore/BackupProtocol.h +++ b/lib/backupstore/BackupProtocol.h @@ -35,7 +35,7 @@ public: // This is rather ugly: the BackupProtocolLocal constructor must not // touch the Context, because it's not initialised yet! : BackupProtocolLocal(mContext), - mContext(AccountNumber, *(HousekeepingInterface *)NULL, + mContext(AccountNumber, (HousekeepingInterface *)NULL, ConnectionDetails) { mContext.SetClientHasAccount(AccountRootDir, DiscSetNumber); diff --git a/lib/backupstore/BackupStoreContext.cpp b/lib/backupstore/BackupStoreContext.cpp index 155abd7f..771bc960 100644 --- a/lib/backupstore/BackupStoreContext.cpp +++ b/lib/backupstore/BackupStoreContext.cpp @@ -54,10 +54,10 @@ // // -------------------------------------------------------------------------- BackupStoreContext::BackupStoreContext(int32_t ClientID, - HousekeepingInterface &rDaemon, const std::string& rConnectionDetails) + HousekeepingInterface* pHousekeeping, const std::string& rConnectionDetails) : mConnectionDetails(rConnectionDetails), mClientID(ClientID), - mrDaemon(rDaemon), + mpHousekeeping(pHousekeeping), mProtocolPhase(Phase_START), mClientHasAccount(false), mStoreDiscSet(-1), @@ -160,13 +160,13 @@ bool BackupStoreContext::AttemptToGetWriteLock() // Request the lock bool gotLock = mWriteLock.TryAndGetLock(writeLockFile.c_str(), 0600 /* restrictive file permissions */); - if(!gotLock) + if(!gotLock && mpHousekeeping) { // The housekeeping process might have the thing open -- ask it to stop char msg[256]; int msgLen = sprintf(msg, "r%x\n", mClientID); // Send message - mrDaemon.SendMessageToHousekeepingProcess(msg, msgLen); + mpHousekeeping->SendMessageToHousekeepingProcess(msg, msgLen); // Then try again a few times int tries = MAX_WAIT_FOR_HOUSEKEEPING_TO_RELEASE_ACCOUNT; diff --git a/lib/backupstore/BackupStoreContext.h b/lib/backupstore/BackupStoreContext.h index 9dde2075..e0162636 100644 --- a/lib/backupstore/BackupStoreContext.h +++ b/lib/backupstore/BackupStoreContext.h @@ -45,7 +45,8 @@ class HousekeepingInterface class BackupStoreContext { public: - BackupStoreContext(int32_t ClientID, HousekeepingInterface &rDaemon, + BackupStoreContext(int32_t ClientID, + HousekeepingInterface* mpHousekeeping, const std::string& rConnectionDetails); ~BackupStoreContext(); private: @@ -173,7 +174,7 @@ private: std::string mConnectionDetails; int32_t mClientID; - HousekeepingInterface &mrDaemon; + HousekeepingInterface *mpHousekeeping; int mProtocolPhase; bool mClientHasAccount; std::string mAccountRootDir; // has final directory separator -- cgit v1.2.3