summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2010-01-24 13:46:23 +0000
committerChris Wilson <chris+github@qwirx.com>2010-01-24 13:46:23 +0000
commit9cbf4791fc4cbf3e0cfe375b285ea998fae2536d (patch)
treee7f01cd030bd6cf182db749ab5fcdafdbcdd79d2
parenta983f7ce6368d2052d14e4b26fdcd388e42f19a5 (diff)
Revert the quotes part of [2588] as it breaks the unit tests.
Make LocalProcessStream constructor take a std::string& for C++ style.
-rw-r--r--bin/bbackupd/BackupDaemon.cpp31
-rw-r--r--lib/server/LocalProcessStream.cpp11
-rw-r--r--lib/server/LocalProcessStream.h3
3 files changed, 23 insertions, 22 deletions
diff --git a/bin/bbackupd/BackupDaemon.cpp b/bin/bbackupd/BackupDaemon.cpp
index 0e51c3e2..5134d234 100644
--- a/bin/bbackupd/BackupDaemon.cpp
+++ b/bin/bbackupd/BackupDaemon.cpp
@@ -1017,15 +1017,15 @@ int BackupDaemon::UseScriptToSeeIfSyncAllowed()
// If there's no result, try again in five minutes
int waitInSeconds = (60*5);
+ std::string script(conf.GetKeyValue("SyncAllowScript") +
+ " \"" + GetConfigFileName() + "\"");
+
// Run it?
pid_t pid = 0;
try
{
- std::string script("\"" + conf.GetKeyValue("SyncAllowScript") +
- "\" \"" + GetConfigFileName() + "\"");
-
- std::auto_ptr<IOStream> pscript(LocalProcessStream(
- script.c_str(), pid));
+ std::auto_ptr<IOStream> pscript(LocalProcessStream(script,
+ pid));
// Read in the result
IOStreamGetLine getLine(*pscript);
@@ -1048,15 +1048,14 @@ int BackupDaemon::UseScriptToSeeIfSyncAllowed()
catch(ConversionException &e)
{
BOX_ERROR("Invalid output from "
- "SyncAllowScript " <<
- script << ": '" << line << "'");
+ "SyncAllowScript: '" <<
+ line << "' (" << script << ")");
throw;
}
BOX_NOTICE("Delaying sync by " << waitInSeconds
- << " seconds (SyncAllowScript "
- << conf.GetKeyValue("SyncAllowScript")
- << ")");
+ << " seconds due to SyncAllowScript "
+ << "(" << script << ")");
}
}
@@ -1064,14 +1063,14 @@ int BackupDaemon::UseScriptToSeeIfSyncAllowed()
catch(std::exception &e)
{
BOX_ERROR("Internal error running SyncAllowScript: "
- << e.what());
+ << e.what() << " (" << script << ")");
}
catch(...)
{
// Ignore any exceptions
// Log that something bad happened
- BOX_ERROR("Error running SyncAllowScript '"
- << conf.GetKeyValue("SyncAllowScript") << "'");
+ BOX_ERROR("Unknown error running SyncAllowScript (" <<
+ script << ")");
}
// Wait and then cleanup child process, if any
@@ -2188,19 +2187,19 @@ void BackupDaemon::NotifySysadmin(SysadminNotifier::EventCode Event)
Event != SysadminNotifier::BackupFinish)
{
BOX_INFO("Not notifying administrator about event "
- << sEventNames[Event] << " -- set NotifyScript "
+ << sEventNames[Event] << ", set NotifyScript "
"to do this in future");
}
return;
}
// Script to run
- std::string script("\"" + conf.GetKeyValue("NotifyScript") + "\" " +
+ std::string script(conf.GetKeyValue("NotifyScript") + " " +
sEventNames[Event] + " \"" + GetConfigFileName() + "\"");
// Log what we're about to do
BOX_INFO("About to notify administrator about event "
- << sEventNames[Event] << ", running script " << script);
+ << sEventNames[Event] << ", running script '" << script << "'");
// Then do it
int returnCode = ::system(script.c_str());
diff --git a/lib/server/LocalProcessStream.cpp b/lib/server/LocalProcessStream.cpp
index af24de1b..c331a135 100644
--- a/lib/server/LocalProcessStream.cpp
+++ b/lib/server/LocalProcessStream.cpp
@@ -43,13 +43,14 @@
// Created: 12/3/04
//
// --------------------------------------------------------------------------
-std::auto_ptr<IOStream> LocalProcessStream(const char *CommandLine, pid_t &rPidOut)
+std::auto_ptr<IOStream> LocalProcessStream(const std::string& rCommandLine,
+ pid_t &rPidOut)
{
#ifndef WIN32
// Split up command
std::vector<std::string> command;
- SplitString(std::string(CommandLine), ' ', command);
+ SplitString(rCommandLine, ' ', command);
// Build arguments
char *args[MAX_ARGUMENTS + 4];
@@ -137,8 +138,8 @@ std::auto_ptr<IOStream> LocalProcessStream(const char *CommandLine, pid_t &rPidO
startupInfo.hStdInput = INVALID_HANDLE_VALUE;
startupInfo.dwFlags |= STARTF_USESTDHANDLES;
- CHAR* commandLineCopy = (CHAR*)malloc(strlen(CommandLine) + 1);
- strcpy(commandLineCopy, CommandLine);
+ CHAR* commandLineCopy = (CHAR*)malloc(rCommandLine.size() + 1);
+ strcpy(commandLineCopy, rCommandLine.c_str());
BOOL result = CreateProcess(NULL,
commandLineCopy, // command line
@@ -155,7 +156,7 @@ std::auto_ptr<IOStream> LocalProcessStream(const char *CommandLine, pid_t &rPidO
if(!result)
{
- BOX_ERROR("Failed to CreateProcess: '" << CommandLine <<
+ BOX_ERROR("Failed to CreateProcess: '" << rCommandLine <<
"': " << GetErrorMessage(GetLastError()));
CloseHandle(writeInChild);
CloseHandle(readFromChild);
diff --git a/lib/server/LocalProcessStream.h b/lib/server/LocalProcessStream.h
index 490c0f45..51e51f8a 100644
--- a/lib/server/LocalProcessStream.h
+++ b/lib/server/LocalProcessStream.h
@@ -13,7 +13,8 @@
#include <memory>
#include "IOStream.h"
-std::auto_ptr<IOStream> LocalProcessStream(const char *CommandLine, pid_t &rPidOut);
+std::auto_ptr<IOStream> LocalProcessStream(const std::string& rCommandLine,
+ pid_t &rPidOut);
#endif // LOCALPROCESSSTREAM__H