[Box Backup-dev] COMMIT r798 - box/chris/merge/bin/bbackupd
boxbackup-dev@fluffy.co.uk
boxbackup-dev@fluffy.co.uk
Sun, 20 Aug 2006 01:29:23 +0100
Author: chris
Date: 2006-08-20 01:29:23 +0100 (Sun, 20 Aug 2006)
New Revision: 798
Modified:
box/chris/merge/bin/bbackupd/BackupDaemon.cpp
Log:
* 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.
Modified: box/chris/merge/bin/bbackupd/BackupDaemon.cpp
===================================================================
--- box/chris/merge/bin/bbackupd/BackupDaemon.cpp 2006-08-19 23:51:23 UTC (rev 797)
+++ box/chris/merge/bin/bbackupd/BackupDaemon.cpp 2006-08-20 00:29:23 UTC (rev 798)
@@ -262,6 +262,7 @@
#ifdef WIN32
void BackupDaemon::RunHelperThread(void)
{
+ this->mReceivedCommandConn = false;
mpCommandSocketInfo = new CommandSocketInfo;
WinNamedPipeStream& rSocket(mpCommandSocketInfo->mListeningSocket);
@@ -273,16 +274,23 @@
{
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");
SetTerminateWanted();
break; // this is fatal to listening thread
@@ -384,13 +392,18 @@
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 @@
{
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 @@
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 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 @@
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 @@
}
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 @@
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 @@
}
catch(...)
{
- ::endmntent(mountPointsFile);
+ ::endmntent(mountPointsFile);
throw;
}
#else // ! HAVE_STRUCT_MNTENT_MNT_DIR
@@ -1811,6 +1864,12 @@
{
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 @@
{
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 @@
::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,22 +2493,29 @@
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;
}