summaryrefslogtreecommitdiff
path: root/bin/bbackupd
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2006-08-09 18:28:35 +0000
committerChris Wilson <chris+github@qwirx.com>2006-08-09 18:28:35 +0000
commite64b25d653697eb05ef506d27dc233332e7e36f8 (patch)
treeaf2be72f54b27516a197b3f845aa9fdaf9b2fe74 /bin/bbackupd
parent1c113f8281baadb593f818f4f12b33c50156d735 (diff)
* 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.
Diffstat (limited to 'bin/bbackupd')
-rw-r--r--bin/bbackupd/BackupDaemon.cpp53
1 files changed, 40 insertions, 13 deletions
diff --git a/bin/bbackupd/BackupDaemon.cpp b/bin/bbackupd/BackupDaemon.cpp
index 35e5b7b4..db19a6ff 100644
--- a/bin/bbackupd/BackupDaemon.cpp
+++ b/bin/bbackupd/BackupDaemon.cpp
@@ -263,15 +263,35 @@ void BackupDaemon::DeleteAllLocations()
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
@@ -289,16 +309,17 @@ void BackupDaemon::RunHelperThread(void)
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 @@ void BackupDaemon::RunHelperThread(void)
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 @@ void BackupDaemon::RunHelperThread(void)
this->mReceivedCommandConn = true;
}
- mpCommandSocketInfo->mListeningSocket.Close();
+ rSocket.Close();
}
catch (BoxException &e)
{