[Box Backup-dev] COMMIT r749 - box/chris/merge/bin/bbackupd
boxbackup-dev at fluffy.co.uk
boxbackup-dev at fluffy.co.uk
Wed Aug 9 19:28:38 BST 2006
Author: chris
Date: 2006-08-09 18:28:35 +0000 (Wed, 09 Aug 2006)
New Revision: 749
Modified:
box/chris/merge/bin/bbackupd/BackupDaemon.cpp
Log:
* bin/bbackupd/BackupDaemon.cpp
- Made the code more readable by defining a reference rSocket to
mpCommandSocketInfo->mListeningSocket which is used several times.
- Terminate the listening thread if it fails to bind a command socket.
- Log any unrecognised commands received over the command socket.
Modified: box/chris/merge/bin/bbackupd/BackupDaemon.cpp
===================================================================
--- box/chris/merge/bin/bbackupd/BackupDaemon.cpp 2006-08-09 18:17:36 UTC (rev 748)
+++ box/chris/merge/bin/bbackupd/BackupDaemon.cpp 2006-08-09 18:28:35 UTC (rev 749)
@@ -263,16 +263,36 @@
void BackupDaemon::RunHelperThread(void)
{
mpCommandSocketInfo = new CommandSocketInfo;
- this->mReceivedCommandConn = false;
+ WinNamedPipeStream& rSocket(mpCommandSocketInfo->mListeningSocket);
- // loop until the parent process exits
- while (TRUE)
+ // loop until the parent process exits, or we decide
+ // to kill the thread ourselves
+ while (!IsTerminateWanted())
{
try
{
- mpCommandSocketInfo->mListeningSocket.Accept(
- BOX_NAMED_PIPE_NAME);
+ rSocket.Accept(BOX_NAMED_PIPE_NAME);
+ }
+ catch (BoxException &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
+ {
+ // Errors here do not kill the thread,
+ // only the current connection.
+
// This next section comes from Ben's original function
// Log
::syslog(LOG_INFO, "Connection from command socket");
@@ -289,16 +309,17 @@
conf.GetKeyValueInt("MaxUploadWait"),
mState);
- mpCommandSocketInfo->mListeningSocket.Write(summary, summarySize);
- mpCommandSocketInfo->mListeningSocket.Write("ping\n", 5);
+ rSocket.Write(summary, summarySize);
+ rSocket.Write("ping\n", 5);
- IOStreamGetLine readLine(mpCommandSocketInfo->mListeningSocket);
+ IOStreamGetLine readLine(rSocket);
std::string command;
- while (mpCommandSocketInfo->mListeningSocket.IsConnected() &&
- readLine.GetLine(command) )
+ while (rSocket.IsConnected() &&
+ readLine.GetLine(command) &&
+ !IsTerminateWanted())
{
- TRACE1("Receiving command '%s' over "
+ TRACE1("Received command '%s' over "
"command socket\n", command.c_str());
bool sendOK = false;
@@ -338,12 +359,18 @@
SetTerminateWanted();
sendOK = true;
}
+ else
+ {
+ ::syslog(LOG_ERR, "Received unknown command '%s' from client", command.c_str());
+ sendResponse = true;
+ sendOK = false;
+ }
// Send a response back?
if (sendResponse)
{
const char* response = sendOK ? "ok\n" : "error\n";
- mpCommandSocketInfo->mListeningSocket.Write(
+ rSocket.Write(
response, strlen(response));
}
@@ -355,7 +382,7 @@
this->mReceivedCommandConn = true;
}
- mpCommandSocketInfo->mListeningSocket.Close();
+ rSocket.Close();
}
catch (BoxException &e)
{
More information about the Boxbackup-dev
mailing list