diff options
author | Chris Wilson <chris+github@qwirx.com> | 2006-08-20 00:29:23 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2006-08-20 00:29:23 +0000 |
commit | 506bd0c34fb1e35e019b799bfd5bcf788f9e9571 (patch) | |
tree | d6ca8aa4fe7344893df7243d0050036391fc4b39 /bin/bbackupd/BackupDaemon.cpp | |
parent | 4be4f2e1dbcf548253cdab502636bc16b7b4c0b0 (diff) |
* bin/bbackupd/BackupDaemon.cpp
- Restored initialisation of this->mReceivedCommandConn to false in handler
thread.
- Changed handling of all catch(...) blocks, which don't have an obvious
outer exception handler, to catch std::exception first and report it
with e.what(), as suggested by Martin.
- Fixed some catch blocks to match coding standards.
Diffstat (limited to 'bin/bbackupd/BackupDaemon.cpp')
-rw-r--r-- | bin/bbackupd/BackupDaemon.cpp | 108 |
1 files changed, 90 insertions, 18 deletions
diff --git a/bin/bbackupd/BackupDaemon.cpp b/bin/bbackupd/BackupDaemon.cpp index db19a6ff..90c72a20 100644 --- a/bin/bbackupd/BackupDaemon.cpp +++ b/bin/bbackupd/BackupDaemon.cpp @@ -262,6 +262,7 @@ void BackupDaemon::DeleteAllLocations() #ifdef WIN32 void BackupDaemon::RunHelperThread(void) { + this->mReceivedCommandConn = false; mpCommandSocketInfo = new CommandSocketInfo; WinNamedPipeStream& rSocket(mpCommandSocketInfo->mListeningSocket); @@ -273,14 +274,21 @@ void BackupDaemon::RunHelperThread(void) { rSocket.Accept(BOX_NAMED_PIPE_NAME); } - catch (BoxException &e) + catch(BoxException &e) { ::syslog(LOG_ERR, "Failed to open command socket: %s", e.what()); SetTerminateWanted(); break; // this is fatal to listening thread } - catch (...) + catch(std::exception &e) + { + ::syslog(LOG_ERR, "Failed to open command socket: " + "%s", e.what()); + SetTerminateWanted(); + break; // this is fatal to listening thread + } + catch(...) { ::syslog(LOG_ERR, "Failed to open command socket: " "unknown error"); @@ -384,12 +392,17 @@ void BackupDaemon::RunHelperThread(void) rSocket.Close(); } - catch (BoxException &e) + catch(BoxException &e) { ::syslog(LOG_ERR, "Communication error with " "control client: %s", e.what()); } - catch (...) + catch(std::exception &e) + { + ::syslog(LOG_ERR, "Internal error in command socket " + "thread: %s", e.what()); + } + catch(...) { ::syslog(LOG_ERR, "Communication error with control client"); } @@ -450,6 +463,12 @@ void BackupDaemon::Run() { delete mpCommandSocketInfo; } + catch(std::exception &e) + { + ::syslog(LOG_ERR, "Internal error while " + "closing command socket after " + "another exception: %s", e.what()); + } catch(...) { ::syslog(LOG_WARNING, @@ -780,6 +799,12 @@ void BackupDaemon::Run2() errorCode = e.GetType(); errorSubCode = e.GetSubType(); } + catch(std::exception &e) + { + ::syslog(LOG_ERR, "Internal error during " + "backup run: %s", e.what()); + errorOccurred = true; + } catch(...) { // TODO: better handling of exceptions here... need to be very careful @@ -911,6 +936,17 @@ int BackupDaemon::UseScriptToSeeIfSyncAllowed() int status = 0; ::waitpid(pid, &status, 0); } + catch(std::exception &e) + { + ::syslog(LOG_ERR, "Internal error running SyncAllowScript: " + "%s", e.what()); + // Clean up + if(pid != 0) + { + int status = 0; + ::waitpid(pid, &status, 0); + } + } catch(...) { // Ignore any exceptions @@ -1117,13 +1153,19 @@ void BackupDaemon::WaitOnCommandSocket(box_time_t RequiredDelay, bool &DoSyncFla CloseCommandConnection(); } } + catch(std::exception &e) + { + ::syslog(LOG_ERR, "Internal error in command socket thread: " + "%s", e.what()); + throw; // thread will die + } catch(...) { // If an error occurs, and there is a connection active, just close that // connection and continue. Otherwise, let the error propagate. if(mpCommandSocketInfo->mpConnectedSocket.get() == 0) { - throw; + throw; // thread will die } else { @@ -1157,6 +1199,11 @@ void BackupDaemon::CloseCommandConnection() } mpCommandSocketInfo->mpConnectedSocket.reset(); } + catch(std::exception &e) + { + ::syslog(LOG_ERR, "Internal error while closing command " + "socket: %s", e.what()); + } catch(...) { // Ignore any errors @@ -1202,6 +1249,12 @@ void BackupDaemon::SendSyncStartOrFinish(bool SendStart) strlen(message)); #endif } + catch(std::exception &e) + { + ::syslog(LOG_ERR, "Internal error while sending to " + "command socket client: %s", e.what()); + CloseCommandConnection(); + } catch(...) { CloseCommandConnection(); @@ -1311,7 +1364,7 @@ void BackupDaemon::SetupLocations(BackupClientContext &rClientContext, const Con } catch(...) { - ::endmntent(mountPointsFile); + ::endmntent(mountPointsFile); throw; } #else // ! HAVE_STRUCT_MNTENT_MNT_DIR @@ -1811,6 +1864,12 @@ void BackupDaemon::SetState(int State) { mpCommandSocketInfo->mListeningSocket.Write(newState, newStateSize); } + catch(std::exception &e) + { + ::syslog(LOG_ERR, "Internal error while writing state " + "to command socket: %s", e.what()); + CloseCommandConnection(); + } catch(...) { CloseCommandConnection(); @@ -1824,6 +1883,12 @@ void BackupDaemon::SetState(int State) { mpCommandSocketInfo->mpConnectedSocket->Write(newState, newStateSize); } + catch(std::exception &e) + { + ::syslog(LOG_ERR, "Internal error while writing state " + "to command socket: %s", e.what()); + CloseCommandConnection(); + } catch(...) { CloseCommandConnection(); @@ -2273,7 +2338,7 @@ bool BackupDaemon::SerializeStoreObjectInfo(int64_t aClientStoreMarker, box_time ::syslog(LOG_INFO, "Saved store object info file '%s'", StoreObjectInfoFile.c_str()); } - catch (...) + catch(...) { ::syslog(LOG_WARNING, "Requested store object info file '%s' " "not accessible or could not be created", @@ -2428,21 +2493,28 @@ bool BackupDaemon::DeserializeStoreObjectInfo(int64_t & aClientStoreMarker, box_ iVersion); return true; + } + catch(std::exception &e) + { + ::syslog(LOG_ERR, "Internal error reading store object " + "info file: %s", e.what()); } - catch (...) + catch(...) { - DeleteAllLocations(); + ::syslog(LOG_ERR, "Internal error reading store object " + "info file: unknown error"); + } - aClientStoreMarker = - BackupClientContext::ClientStoreMarker_NotKnown; - theLastSyncTime = 0; - theNextSyncTime = 0; + DeleteAllLocations(); - ::syslog(LOG_WARNING, "Requested store object info file '%s' " - "does not exist, not accessible, or inconsistent. " - "Will re-cache from store.", - StoreObjectInfoFile.c_str()); - } + aClientStoreMarker = BackupClientContext::ClientStoreMarker_NotKnown; + theLastSyncTime = 0; + theNextSyncTime = 0; + + ::syslog(LOG_WARNING, "Requested store object info file '%s' " + "does not exist, not accessible, or inconsistent. " + "Will re-cache from store.", + StoreObjectInfoFile.c_str()); return false; } |