[Box Backup-dev] COMMIT r348 - in box/chris/bb-save-state: . bin/bbackupd lib/common lib/server
boxbackup-dev at fluffy.co.uk
boxbackup-dev at fluffy.co.uk
Sun Jan 29 19:59:05 GMT 2006
Author: chris
Date: 2006-01-29 19:58:58 +0000 (Sun, 29 Jan 2006)
New Revision: 348
Modified:
box/chris/bb-save-state/BUGS.txt
box/chris/bb-save-state/bin/bbackupd/BackupDaemon.cpp
box/chris/bb-save-state/bin/bbackupd/BackupDaemon.h
box/chris/bb-save-state/lib/common/Archive.h
box/chris/bb-save-state/lib/common/CommonException.txt
box/chris/bb-save-state/lib/common/Configuration.cpp
box/chris/bb-save-state/lib/common/Configuration.h
box/chris/bb-save-state/lib/server/Daemon.cpp
box/chris/bb-save-state/lib/server/Daemon.h
Log:
* lib/server/Daemon.h
* lib/server/Daemon.cpp
- Replaced #ifndef WIN32 with autoconfiscated HAVE_SYSLOG_H
- Store the configuration file name in a member variable
- Added a GetConfigFileName() method to return it
- Store the last modification time of the configuration when it's loaded
- Added a GetLoadedConfigModifiedTime() method to return it
- Minor spacing cleanups
* lib/common/CommonException.txt
- Added a new exception type, ArchiveBlockIncompleteRead
* lib/common/Archive.h
- Changed StreamableMemBlockIncompleteRead exception to
ArchiveBlockIncompleteRead
* lib/common/Configuration.h
* lib/common/Configuration.cpp
- Reverted the patch which added the file modification time to the
Configuration object
* bin/bbackupd/BackupDaemon.h
* bin/bbackupd/BackupDaemon.cpp
- Stopped using operator overloading for serialisation
- Code and formatting cleanups
- Use Daemon::GetLoadedConfigModifiedTime() to get the last modified time
instead of the method that no longer exists in Configuration
* BUGS.txt
- Added notes about tasks that still need doing, e.g. unit tests for Archive
and serialisation
Modified: box/chris/bb-save-state/BUGS.txt
===================================================================
--- box/chris/bb-save-state/BUGS.txt 2006-01-29 11:15:20 UTC (rev 347)
+++ box/chris/bb-save-state/BUGS.txt 2006-01-29 19:58:58 UTC (rev 348)
@@ -8,3 +8,8 @@
* if bbackupd gets an error then a signal, it may not wait it's full 100 seconds before retrying. And then won't stop the cycle...
* bbackupquery restore, if not root, then won't do file ownership properly, but won't alert the user to this fact
* empty (real) directories in the store aren't deleted when they're empty (and will never be used again) -- uses up disc space unnecessarily
+* need unit tests for SSL keepalives and state saving (serialisation)
+* make Archive derive from Protocol, eliminate << operator overloading >>
+* more automated tests for win32
+* change off_t to box_off_t in preparation for win32 large file support
+* support large files on win32 by using native *i64 functions instead of posix
Modified: box/chris/bb-save-state/bin/bbackupd/BackupDaemon.cpp
===================================================================
--- box/chris/bb-save-state/bin/bbackupd/BackupDaemon.cpp 2006-01-29 11:15:20 UTC (rev 347)
+++ box/chris/bb-save-state/bin/bbackupd/BackupDaemon.cpp 2006-01-29 19:58:58 UTC (rev 348)
@@ -2115,17 +2115,32 @@
void BackupDaemon::SerializeStoreObjectInfo(int64_t aClientStoreMarker, box_time_t theLastSyncTime, box_time_t theNextSyncTime) const
{
- if(!GetConfiguration().KeyExists("StoreObjectInfoFile") || GetConfiguration().GetKeyValue("StoreObjectInfoFile").size() <= 0)
+ if(!GetConfiguration().KeyExists("StoreObjectInfoFile"))
+ {
return;
+ }
+ std::string StoreObjectInfoFile =
+ GetConfiguration().GetKeyValue("StoreObjectInfoFile");
+
+ if (StoreObjectInfoFile.size() <= 0)
+ {
+ return;
+ }
+
try
{
- FileStream aFile(GetConfiguration().GetKeyValue("StoreObjectInfoFile").c_str(), O_WRONLY | O_CREAT | O_TRUNC);
+ FileStream aFile(StoreObjectInfoFile.c_str(),
+ O_WRONLY | O_CREAT | O_TRUNC);
IOStreamArchive anArchive(aFile, 0);
- anArchive << STOREOBJECTINFO_MAGIC_ID_VALUE << STOREOBJECTINFO_MAGIC_ID_STRING << STOREOBJECTINFO_VERSION
- << GetConfiguration().GetModTime()
- << aClientStoreMarker << theLastSyncTime << theNextSyncTime;
+ anArchive.Add(STOREOBJECTINFO_MAGIC_ID_VALUE);
+ anArchive.Add(STOREOBJECTINFO_MAGIC_ID_STRING);
+ anArchive.Add(STOREOBJECTINFO_VERSION);
+ anArchive.Add(GetLoadedConfigModifiedTime());
+ anArchive.Add(aClientStoreMarker);
+ anArchive.Add(theLastSyncTime);
+ anArchive.Add(theNextSyncTime);
//
//
@@ -2152,11 +2167,14 @@
//
//
aFile.Close();
- ::syslog(LOG_INFO, "Saved store object info file '%s'", GetConfiguration().GetKeyValue("StoreObjectInfoFile").c_str());
+ ::syslog(LOG_INFO, "Saved store object info file '%s'",
+ StoreObjectInfoFile.c_str());
}
catch (...)
{
- ::syslog(LOG_WARNING, "Requested store object info file '%s' not accessible or could not be created", GetConfiguration().GetKeyValue("StoreObjectInfoFile").c_str());
+ ::syslog(LOG_WARNING, "Requested store object info file '%s' "
+ "not accessible or could not be created",
+ StoreObjectInfoFile.c_str());
}
}
@@ -2251,7 +2269,7 @@
box_time_t lastKnownConfigModTime;
anArchive.Get(lastKnownConfigModTime);
- if (lastKnownConfigModTime != GetConfiguration().GetModTime())
+ if (lastKnownConfigModTime != GetLoadedConfigModifiedTime())
{
::syslog(LOG_WARNING, "Store object info file '%s' "
"out of date. Will re-cache from store",
@@ -2262,7 +2280,9 @@
//
// this is it, go at it
//
- anArchive >> aClientStoreMarker >> theLastSyncTime >> theNextSyncTime;
+ anArchive.Get(aClientStoreMarker);
+ anArchive.Get(theLastSyncTime);
+ anArchive.Get(theNextSyncTime);
//
//
Modified: box/chris/bb-save-state/bin/bbackupd/BackupDaemon.h
===================================================================
--- box/chris/bb-save-state/bin/bbackupd/BackupDaemon.h 2006-01-29 11:15:20 UTC (rev 347)
+++ box/chris/bb-save-state/bin/bbackupd/BackupDaemon.h 2006-01-29 19:58:58 UTC (rev 348)
@@ -14,15 +14,14 @@
#include <string>
#include <memory>
-#include "Daemon.h"
+#include "Archive.h"
#include "BoxTime.h"
+#include "Daemon.h"
#include "Socket.h"
#include "SocketListen.h"
#include "SocketStream.h"
#include "WinNamedPipeStream.h"
-#include "Archive.h"
-
class BackupClientDirectoryRecord;
class BackupClientContext;
class Configuration;
Modified: box/chris/bb-save-state/lib/common/Archive.h
===================================================================
--- box/chris/bb-save-state/lib/common/Archive.h 2006-01-29 11:15:20 UTC (rev 347)
+++ box/chris/bb-save-state/lib/common/Archive.h 2006-01-29 19:58:58 UTC (rev 348)
@@ -137,7 +137,7 @@
int32_t privItem;
if(!mStream.ReadFullBuffer(&privItem, sizeof(privItem), 0 /* not interested in bytes read if this fails */))
{
- THROW_EXCEPTION(CommonException, StreamableMemBlockIncompleteRead)
+ THROW_EXCEPTION(CommonException, ArchiveBlockIncompleteRead)
}
iItem = ntohl(privItem);
}
@@ -146,7 +146,7 @@
int64_t privItem;
if(!mStream.ReadFullBuffer(&privItem, sizeof(privItem), 0 /* not interested in bytes read if this fails */))
{
- THROW_EXCEPTION(CommonException, StreamableMemBlockIncompleteRead)
+ THROW_EXCEPTION(CommonException, ArchiveBlockIncompleteRead)
}
iItem = box_ntoh64(privItem);
}
@@ -155,7 +155,7 @@
uint64_t privItem;
if(!mStream.ReadFullBuffer(&privItem, sizeof(privItem), 0 /* not interested in bytes read if this fails */))
{
- THROW_EXCEPTION(CommonException, StreamableMemBlockIncompleteRead)
+ THROW_EXCEPTION(CommonException, ArchiveBlockIncompleteRead)
}
iItem = box_ntoh64(privItem);
}
@@ -177,7 +177,7 @@
// Fetch rest of pPayload, relying on the Protocol to error on stupidly large sizes for us
if(!mStream.ReadFullBuffer(buf, iSize, 0 /* not interested in bytes read if this fails */, mTimeout))
{
- THROW_EXCEPTION(CommonException, StreamableMemBlockIncompleteRead)
+ THROW_EXCEPTION(CommonException, ArchiveBlockIncompleteRead)
}
// assign to this string, storing the header and the extra pPayload
strItem.assign(buf, iSize);
@@ -191,7 +191,7 @@
// Fetch rest of pPayload, relying on the Protocol to error on stupidly large sizes for us
if(!mStream.ReadFullBuffer(pPayload, iSize, 0 /* not interested in bytes read if this fails */, mTimeout))
{
- THROW_EXCEPTION(CommonException, StreamableMemBlockIncompleteRead)
+ THROW_EXCEPTION(CommonException, ArchiveBlockIncompleteRead)
}
// assign to this string, storing the header and the extra pPayload
strItem.assign(pPayload, iSize);
Modified: box/chris/bb-save-state/lib/common/CommonException.txt
===================================================================
--- box/chris/bb-save-state/lib/common/CommonException.txt 2006-01-29 11:15:20 UTC (rev 347)
+++ box/chris/bb-save-state/lib/common/CommonException.txt 2006-01-29 19:58:58 UTC (rev 348)
@@ -43,3 +43,4 @@
KQueueNotSupportedOnThisPlatform 36
IOStreamGetLineNotEnoughDataToIgnore 37 Bad value passed to IOStreamGetLine::IgnoreBufferedData()
TempDirPathTooLong 38 Your temporary directory path is too long. Check the TMP and TEMP environment variables.
+ArchiveBlockIncompleteRead 39 The Store Object Info File is too short or corrupted, and will be rewritten automatically when the next backup completes.
Modified: box/chris/bb-save-state/lib/common/Configuration.cpp
===================================================================
--- box/chris/bb-save-state/lib/common/Configuration.cpp 2006-01-29 11:15:20 UTC (rev 347)
+++ box/chris/bb-save-state/lib/common/Configuration.cpp 2006-01-29 19:58:58 UTC (rev 348)
@@ -11,7 +11,6 @@
#include <stdlib.h>
#include <limits.h>
-#include <errno.h>
#include "Configuration.h"
#include "CommonException.h"
@@ -20,8 +19,6 @@
#include "MemLeakFindOn.h"
-#include "FileModificationTime.h"
-
// utility whitespace function
inline bool iw(int c)
{
@@ -32,19 +29,22 @@
static const char *sValueBooleanStrings[] = {"yes", "true", "no", "false", 0};
static const bool sValueBooleanValue[] = {true, true, false, false};
+
+
// --------------------------------------------------------------------------
//
// Function
-// Name: Configuration::Configuration(const std::string &, box_time_t)
+// Name: Configuration::Configuration(const std::string &)
// Purpose: Constructor
// Created: 2003/07/23
//
// --------------------------------------------------------------------------
-Configuration::Configuration(const std::string &rName, box_time_t configModTime)
- : mName(rName), mConfigModTime(configModTime)
+Configuration::Configuration(const std::string &rName)
+ : mName(rName)
{
}
+
// --------------------------------------------------------------------------
//
// Function
@@ -56,8 +56,7 @@
Configuration::Configuration(const Configuration &rToCopy)
: mName(rToCopy.mName),
mSubConfigurations(rToCopy.mSubConfigurations),
- mKeys(rToCopy.mKeys),
- mConfigModTime(rToCopy.mConfigModTime)
+ mKeys(rToCopy.mKeys)
{
}
@@ -95,19 +94,6 @@
// Just to make sure
rErrorMsg.erase();
- // Save modification time to be able to distinguish across configuration sets
- struct stat st;
- if(::stat(Filename, &st) != 0)
- {
- // Used to THROW_EXCEPTION(CommonException, OSFileError) here
- // but this is not the normal behaviour if the file doesn't
- // exist
- if (errno != ENOENT)
- {
- THROW_EXCEPTION(CommonException, OSFileError)
- }
- }
-
// Open the file
FileHandleGuard<O_RDONLY> file(Filename);
@@ -115,7 +101,7 @@
FdGetLine getline(file);
// Object to create
- Configuration *pconfig = new Configuration(std::string("<root>"), FileModificationTime(st));
+ Configuration *pconfig = new Configuration(std::string("<root>"));
try
{
@@ -190,7 +176,7 @@
if(startBlockExpected)
{
// New config object
- Configuration config(blockName, rConfig.mConfigModTime);
+ Configuration config(blockName);
// Continue processing into this block
if(!LoadInto(config, rGetLine, rErrorMsg, false))
Modified: box/chris/bb-save-state/lib/common/Configuration.h
===================================================================
--- box/chris/bb-save-state/lib/common/Configuration.h 2006-01-29 11:15:20 UTC (rev 347)
+++ box/chris/bb-save-state/lib/common/Configuration.h 2006-01-29 19:58:58 UTC (rev 348)
@@ -16,8 +16,6 @@
#include <string>
#include <memory>
-#include "BoxTime.h"
-
// For defining tests
enum
{
@@ -60,13 +58,11 @@
class Configuration
{
private:
- Configuration(const std::string &rName, box_time_t configModTime);
+ Configuration(const std::string &rName);
public:
Configuration(const Configuration &rToCopy);
~Configuration();
- box_time_t GetModTime() const { return mConfigModTime; }
-
enum
{
// The character to separate multi-values
@@ -92,8 +88,7 @@
SubConfigListType mSubConfigurations;
// Order of keys, not preserved
std::map<std::string, std::string> mKeys;
-protected:
- box_time_t mConfigModTime;
+
private:
static bool LoadInto(Configuration &rConfig, FdGetLine &rGetLine, std::string &rErrorMsg, bool RootLevel);
static bool Verify(Configuration &rConfig, const ConfigurationVerify &rVerify, const std::string &rLevel, std::string &rErrorMsg);
Modified: box/chris/bb-save-state/lib/server/Daemon.cpp
===================================================================
--- box/chris/bb-save-state/lib/server/Daemon.cpp 2006-01-29 11:15:20 UTC (rev 347)
+++ box/chris/bb-save-state/lib/server/Daemon.cpp 2006-01-29 19:58:58 UTC (rev 348)
@@ -9,14 +9,15 @@
#include "Box.h"
+#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <stdarg.h>
-#ifndef WIN32
-#include <syslog.h>
+#ifdef HAVE_SYSLOG_H
+ #include <syslog.h>
#endif
#include "Daemon.h"
@@ -24,6 +25,7 @@
#include "ServerException.h"
#include "Guards.h"
#include "UnixUser.h"
+#include "FileModificationTime.h"
#include "MemLeakFindOn.h"
@@ -92,22 +94,21 @@
}
std::string pidFileName;
- const char *configfile = 0;
try
{
// Find filename of config file
- configfile = DefaultConfigFile;
+ mConfigFileName = DefaultConfigFile;
if(argc >= 2)
{
// First argument is config file, or it's -c and the next arg is the config file
if(::strcmp(argv[1], "-c") == 0 && argc >= 3)
{
- configfile = argv[2];
+ mConfigFileName = argv[2];
}
else
{
- configfile = argv[1];
+ mConfigFileName = argv[1];
}
}
@@ -123,19 +124,25 @@
// Load the configuration file.
std::string errors;
- std::auto_ptr<Configuration> pconfig = Configuration::LoadAndVerify(configfile, GetConfigVerify(), errors);
+ std::auto_ptr<Configuration> pconfig =
+ Configuration::LoadAndVerify(
+ mConfigFileName.c_str(),
+ GetConfigVerify(), errors);
// Got errors?
if(pconfig.get() == 0 || !errors.empty())
{
// Tell user about errors
- fprintf(stderr, "%s: Errors in config file %s:\n%s", DaemonName(), configfile, errors.c_str());
+ fprintf(stderr, "%s: Errors in config file %s:\n%s",
+ DaemonName(), mConfigFileName.c_str(),
+ errors.c_str());
// And give up
return 1;
}
// Store configuration
mpConfiguration = pconfig.release();
+ mLoadedConfigModifiedTime = GetConfigFileModifiedTime();
// Server configuration
const Configuration &serverConfig(mpConfiguration->GetSubConfiguration("Server"));
@@ -228,7 +235,8 @@
// open the log
::openlog(DaemonName(), LOG_PID, LOG_LOCAL6);
// Log the start message
- ::syslog(LOG_INFO, "Starting daemon (config: %s) (version " BOX_VERSION ")", configfile);
+ ::syslog(LOG_INFO, "Starting daemon (config: %s) (version "
+ BOX_VERSION ")", mConfigFileName.c_str());
#ifndef WIN32
// Write PID to file
@@ -306,15 +314,23 @@
if(mReloadConfigWanted && !mTerminateWanted)
{
// Need to reload that config file...
- ::syslog(LOG_INFO, "Reloading configuration (config: %s)", configfile);
+ ::syslog(LOG_INFO, "Reloading configuration "
+ "(config: %s)",
+ mConfigFileName.c_str());
std::string errors;
- std::auto_ptr<Configuration> pconfig = Configuration::LoadAndVerify(configfile, GetConfigVerify(), errors);
+ std::auto_ptr<Configuration> pconfig =
+ Configuration::LoadAndVerify(
+ mConfigFileName.c_str(),
+ GetConfigVerify(), errors);
// Got errors?
if(pconfig.get() == 0 || !errors.empty())
{
// Tell user about errors
- ::syslog(LOG_ERR, "Errors in config file %s:\n%s", configfile, errors.c_str());
+ ::syslog(LOG_ERR, "Errors in config "
+ "file %s:\n%s",
+ mConfigFileName.c_str(),
+ errors.c_str());
// And give up
return 1;
}
@@ -325,6 +341,8 @@
// Store configuration
mpConfiguration = pconfig.release();
+ mLoadedConfigModifiedTime =
+ GetConfigFileModifiedTime();
// Stop being marked for loading config again
mReloadConfigWanted = false;
@@ -547,3 +565,53 @@
#endif // HAVE_SETPROCTITLE
}
+
+std::string Daemon::GetConfigFileName() const
+{
+ return mConfigFileName;
+}
+
+// --------------------------------------------------------------------------
+//
+// Function
+// Name: Daemon::GetConfigFileModifiedTime()
+// Purpose: Returns the timestamp when the configuration file
+// was last modified
+//
+// Created: 2006/01/29
+//
+// --------------------------------------------------------------------------
+
+box_time_t Daemon::GetConfigFileModifiedTime() const
+{
+ struct stat st;
+
+ if(::stat(GetConfigFileName().c_str(), &st) != 0)
+ {
+ if (errno == ENOENT)
+ {
+ return 0;
+ }
+ THROW_EXCEPTION(CommonException, OSFileError)
+ }
+
+ return FileModificationTime(st);
+}
+
+// --------------------------------------------------------------------------
+//
+// Function
+// Name: Daemon::GetLoadedConfigModifiedTime()
+// Purpose: Returns the timestamp when the configuration file
+// had been last modified, at the time when it was
+// loaded
+//
+// Created: 2006/01/29
+//
+// --------------------------------------------------------------------------
+
+box_time_t Daemon::GetLoadedConfigModifiedTime() const
+{
+ return mLoadedConfigModifiedTime;
+}
+
Modified: box/chris/bb-save-state/lib/server/Daemon.h
===================================================================
--- box/chris/bb-save-state/lib/server/Daemon.h 2006-01-29 11:15:20 UTC (rev 347)
+++ box/chris/bb-save-state/lib/server/Daemon.h 2006-01-29 19:58:58 UTC (rev 348)
@@ -16,6 +16,10 @@
#ifndef DAEMON__H
#define DAEMON__H
+#include <string>
+
+#include "BoxTime.h"
+
class Configuration;
class ConfigurationVerify;
@@ -40,7 +44,8 @@
virtual void Run();
const Configuration &GetConfiguration() const;
-
+ std::string GetConfigFileName() const;
+
virtual const char *DaemonName() const;
virtual const char *DaemonBanner() const;
virtual const ConfigurationVerify *GetConfigVerify() const;
@@ -57,12 +62,18 @@
virtual void EnterChild();
static void SetProcessTitle(const char *format, ...);
+
+protected:
+ box_time_t GetLoadedConfigModifiedTime() const;
private:
static void SignalHandler(int sigraised);
+ box_time_t GetConfigFileModifiedTime() const;
private:
+ std::string mConfigFileName;
Configuration *mpConfiguration;
+ box_time_t mLoadedConfigModifiedTime;
bool mReloadConfigWanted;
bool mTerminateWanted;
static Daemon *spDaemon;
More information about the Boxbackup-dev
mailing list