[Box Backup-commit] COMMIT r1024 - box/chris/general/bin/bbackupd
boxbackup-dev@fluffy.co.uk
boxbackup-dev@fluffy.co.uk
Sat, 14 Oct 2006 15:28:58 +0100
Author: chris
Date: 2006-10-14 15:28:58 +0100 (Sat, 14 Oct 2006)
New Revision: 1024
Modified:
box/chris/general/bin/bbackupd/BackupDaemon.cpp
Log:
* Import error handling improvements from merge branch
Modified: box/chris/general/bin/bbackupd/BackupDaemon.cpp
===================================================================
--- box/chris/general/bin/bbackupd/BackupDaemon.cpp 2006-10-14 14:10:51 UTC (rev 1023)
+++ box/chris/general/bin/bbackupd/BackupDaemon.cpp 2006-10-14 14:28:58 UTC (rev 1024)
@@ -289,7 +289,8 @@
mpCommandSocketInfo = new CommandSocketInfo;
WinNamedPipeStream& rSocket(mpCommandSocketInfo->mListeningSocket);
- // loop until the parent process exits
+ // loop until the parent process exits, or we decide
+ // to kill the thread ourselves
while (!IsTerminateWanted())
{
try
@@ -301,15 +302,30 @@
::syslog(LOG_ERR, "Failed to open command socket: %s",
e.what());
SetTerminateWanted();
- break; // this is fatal
+ break; // this is fatal to listening thread
}
catch (...)
{
::syslog(LOG_ERR, "Failed to open command socket: "
"unknown error");
SetTerminateWanted();
- break; // this is fatal
+ break; // this is fatal to listening thread
}
+ }
+ 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
+ }
try
{
@@ -463,13 +479,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");
}
}
@@ -532,6 +553,12 @@
{
delete mpCommandSocketInfo;
}
+ catch(std::exception &e)
+ {
+ ::syslog(LOG_WARNING, "Internal error while "
+ "closing command socket after "
+ "another exception: %s", e.what());
+ }
catch(...)
{
::syslog(LOG_WARNING,
@@ -862,6 +889,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
@@ -1002,23 +1035,26 @@
}
}
- // Wait and then cleanup child process
- int status = 0;
- ::waitpid(pid, &status, 0);
}
+ catch(std::exception &e)
+ {
+ ::syslog(LOG_ERR, "Internal error running SyncAllowScript: "
+ "%s", e.what());
+ }
catch(...)
{
// Ignore any exceptions
// Log that something bad happened
::syslog(LOG_ERR, "Error running SyncAllowScript '%s'", conf.GetKeyValue("SyncAllowScript").c_str());
- // Clean up though
- if(pid != 0)
- {
- int status = 0;
- ::waitpid(pid, &status, 0);
- }
}
+ // Wait and then cleanup child process, if any
+ if (pid != 0)
+ {
+ int status = 0;
+ ::waitpid(pid, &status, 0);
+ }
+
return waitInSeconds;
}
@@ -1215,13 +1251,29 @@
CloseCommandConnection();
}
}
+ catch(std::exception &e)
+ {
+ ::syslog(LOG_ERR, "Internal error in command socket thread: "
+ "%s", e.what());
+ // 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; // thread will die
+ }
+ else
+ {
+ // Close socket and ignore error
+ CloseCommandConnection();
+ }
+ }
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
{
@@ -1255,6 +1307,11 @@
}
mpCommandSocketInfo->mpConnectedSocket.reset();
}
+ catch(std::exception &e)
+ {
+ ::syslog(LOG_ERR, "Internal error while closing command "
+ "socket: %s", e.what());
+ }
catch(...)
{
// Ignore any errors
@@ -1299,6 +1356,12 @@
message.c_str(), message.size());
#endif
}
+ catch(std::exception &e)
+ {
+ ::syslog(LOG_ERR, "Internal error while sending to "
+ "command socket client: %s", e.what());
+ CloseCommandConnection();
+ }
catch(...)
{
CloseCommandConnection();
@@ -1408,7 +1471,7 @@
}
catch(...)
{
- ::endmntent(mountPointsFile);
+ ::endmntent(mountPointsFile);
throw;
}
#else // ! HAVE_STRUCT_MNTENT_MNT_DIR
@@ -1908,7 +1971,7 @@
return;
}
- if (mpCommandSocketInfo->mpConnectedSocket.get() == 0)
+ if(mpCommandSocketInfo->mpConnectedSocket.get() == 0)
{
return;
}
@@ -2367,10 +2430,16 @@
::syslog(LOG_INFO, "Saved store object info file '%s'",
StoreObjectInfoFile.c_str());
}
- catch (...)
+ catch(std::exception &e)
{
- ::syslog(LOG_WARNING, "Requested store object info file '%s' "
- "not accessible or could not be created",
+ ::syslog(LOG_ERR, "Internal error writing store object "
+ "info file (%s): %s",
+ StoreObjectInfoFile.c_str(), e.what());
+ }
+ catch(...)
+ {
+ ::syslog(LOG_ERR, "Internal error writing store object "
+ "info file (%s): unknown error",
StoreObjectInfoFile.c_str());
}
@@ -2522,22 +2591,31 @@
iVersion);
return true;
+ }
+ catch(std::exception &e)
+ {
+ ::syslog(LOG_ERR, "Internal error reading store object "
+ "info file (%s): %s",
+ StoreObjectInfoFile.c_str(), e.what());
}
- catch (...)
+ catch(...)
{
- DeleteAllLocations();
-
- 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.",
+ ::syslog(LOG_ERR, "Internal error reading store object "
+ "info file (%s): unknown error",
StoreObjectInfoFile.c_str());
}
+ DeleteAllLocations();
+
+ 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;
}