[Box Backup-dev] COMMIT r838 - box/trunk/bin/bbackupd
boxbackup-dev@fluffy.co.uk
boxbackup-dev@fluffy.co.uk
Wed, 30 Aug 2006 20:50:08 +0100
Author: chris
Date: 2006-08-30 20:50:08 +0100 (Wed, 30 Aug 2006)
New Revision: 838
Modified:
box/trunk/bin/bbackupd/BackupDaemon.cpp
Log:
* bin/bbackupd/BackupDaemon.cpp
- 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/trunk/bin/bbackupd/BackupDaemon.cpp
===================================================================
--- box/trunk/bin/bbackupd/BackupDaemon.cpp 2006-08-30 19:42:27 UTC (rev 837)
+++ box/trunk/bin/bbackupd/BackupDaemon.cpp 2006-08-30 19:50:08 UTC (rev 838)
@@ -272,6 +272,21 @@
{
mpCommandSocketInfo->mListeningSocket.Accept(
BOX_NAMED_PIPE_NAME);
+ }
+ 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
+ }
// This next section comes from Ben's original function
// Log
@@ -357,13 +372,18 @@
mpCommandSocketInfo->mListeningSocket.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");
}
}
@@ -423,6 +443,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,
@@ -753,6 +779,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
@@ -884,6 +916,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
@@ -1090,13 +1133,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
{
@@ -1130,6 +1179,11 @@
}
mpCommandSocketInfo->mpConnectedSocket.reset();
}
+ catch(std::exception &e)
+ {
+ ::syslog(LOG_ERR, "Internal error while closing command "
+ "socket: %s", e.what());
+ }
catch(...)
{
// Ignore any errors
@@ -1175,6 +1229,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();
@@ -1284,7 +1344,7 @@
}
catch(...)
{
- ::endmntent(mountPointsFile);
+ ::endmntent(mountPointsFile);
throw;
}
#else // ! HAVE_STRUCT_MNTENT_MNT_DIR
@@ -1784,6 +1844,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();
@@ -1797,6 +1863,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();
@@ -2246,7 +2318,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",
@@ -2401,22 +2473,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;
}