summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2014-12-28 22:03:29 +0000
committerChris Wilson <chris+github@qwirx.com>2014-12-28 22:03:29 +0000
commit7b7456c31276011f012ae7d9f02437ae31071c8c (patch)
tree80721df166d1d6c5e6798908f7f30e9c5134ec3b /bin
parent1c1872a295a8f624feda363b9edb366da97798c6 (diff)
Improve debugging of named pipe operations and bbackupctl pipe interaction.
Diffstat (limited to 'bin')
-rw-r--r--bin/bbackupctl/bbackupctl.cpp40
-rw-r--r--bin/bbackupd/BackupDaemon.h19
2 files changed, 42 insertions, 17 deletions
diff --git a/bin/bbackupctl/bbackupctl.cpp b/bin/bbackupctl/bbackupctl.cpp
index b00e90ba..b07f65a4 100644
--- a/bin/bbackupctl/bbackupctl.cpp
+++ b/bin/bbackupctl/bbackupctl.cpp
@@ -220,6 +220,9 @@ int main(int argc, const char *argv[])
return 1;
}
+ BOX_TRACE("Current state: " <<
+ BackupDaemon::GetStateName(currentState));
+
Command command = Default;
std::string commandName(argv[0]);
@@ -237,21 +240,8 @@ int main(int argc, const char *argv[])
}
else if (commandName == "status")
{
- std::string stateName;
-
- #define STATE(x) case BackupDaemon::State_ ## x: stateName = #x; break;
- switch (currentState)
- {
- STATE(Initialising);
- STATE(Idle);
- STATE(Connected);
- STATE(Error);
- STATE(StorageLimitExceeded);
- default:
- stateName = "unknown";
- break;
- }
- BOX_NOTICE("state " << currentState << " " << stateName);
+ BOX_NOTICE("state " <<
+ BackupDaemon::GetStateName(currentState));
command = NoCommand;
}
@@ -277,8 +267,7 @@ int main(int argc, const char *argv[])
// send a sync command
commandName = "force-sync";
std::string cmd = commandName + "\n";
- connection.Write(cmd.c_str(), cmd.size(),
- PROTOCOL_DEFAULT_TIMEOUT);
+ connection.Write(cmd, PROTOCOL_DEFAULT_TIMEOUT);
connection.WriteAllBuffered();
if (currentState != 0)
@@ -317,6 +306,23 @@ int main(int argc, const char *argv[])
while(command != NoCommand && !finished && !getLine.IsEOF() &&
getLine.GetLine(line, false, PROTOCOL_DEFAULT_TIMEOUT))
{
+ BOX_TRACE("Received line: " << line);
+
+ if(line.substr(0, 6) == "state ")
+ {
+ std::string state_str = line.substr(6);
+ int state_num;
+ if(sscanf(state_str.c_str(), "%d", &state_num) == 1)
+ {
+ BOX_INFO("Daemon state changed to: " <<
+ BackupDaemon::GetStateName(state_num));
+ }
+ else
+ {
+ BOX_WARNING("Failed to parse line: " << line);
+ }
+ }
+
switch (command)
{
case WaitForSyncStart:
diff --git a/bin/bbackupd/BackupDaemon.h b/bin/bbackupd/BackupDaemon.h
index a6cb8d46..ba46dec2 100644
--- a/bin/bbackupd/BackupDaemon.h
+++ b/bin/bbackupd/BackupDaemon.h
@@ -109,6 +109,25 @@ public:
};
int GetState() {return mState;}
+ static std::string GetStateName(int state)
+ {
+ std::string stateName;
+
+ #define STATE(x) case BackupDaemon::State_ ## x: stateName = #x; break;
+ switch (state)
+ {
+ STATE(Initialising);
+ STATE(Idle);
+ STATE(Connected);
+ STATE(Error);
+ STATE(StorageLimitExceeded);
+ default:
+ stateName = "unknown";
+ }
+ #undef STATE
+
+ return stateName;
+ }
// Allow other classes to call this too
void NotifySysadmin(SysadminNotifier::EventCode Event);