[Box Backup-commit] COMMIT r1784 - in box/chris/general: bin/bbackupctl bin/bbackupd bin/bbackupquery bin/bbstored lib/backupclient lib/common lib/raidfile lib/server
boxbackup-dev at fluffy.co.uk
boxbackup-dev at fluffy.co.uk
Wed Aug 1 00:18:50 BST 2007
Author: chris
Date: 2007-08-01 00:18:50 +0100 (Wed, 01 Aug 2007)
New Revision: 1784
Modified:
box/chris/general/bin/bbackupctl/bbackupctl.cpp
box/chris/general/bin/bbackupd/BackupClientContext.cpp
box/chris/general/bin/bbackupd/Win32ServiceFunctions.cpp
box/chris/general/bin/bbackupquery/BackupQueries.cpp
box/chris/general/bin/bbstored/BBStoreDHousekeeping.cpp
box/chris/general/bin/bbstored/BackupCommands.cpp
box/chris/general/bin/bbstored/BackupStoreDaemon.cpp
box/chris/general/bin/bbstored/HousekeepStoreAccount.cpp
box/chris/general/lib/backupclient/BackupClientFileAttributes.cpp
box/chris/general/lib/backupclient/BackupClientRestore.cpp
box/chris/general/lib/backupclient/BackupStoreFile.cpp
box/chris/general/lib/common/BoxTime.cpp
box/chris/general/lib/common/DebugPrintf.cpp
box/chris/general/lib/common/Logging.h
box/chris/general/lib/raidfile/RaidFileRead.cpp
box/chris/general/lib/server/Daemon.cpp
box/chris/general/lib/server/LocalProcessStream.cpp
box/chris/general/lib/server/SSLLib.cpp
box/chris/general/lib/server/ServerStream.h
box/chris/general/lib/server/Socket.cpp
box/chris/general/lib/server/WinNamedPipeStream.cpp
Log:
Replace almost all calls to syslog() with logging framework. (merges [1783])
Modified: box/chris/general/bin/bbackupctl/bbackupctl.cpp
===================================================================
--- box/chris/general/bin/bbackupctl/bbackupctl.cpp 2007-07-31 23:18:05 UTC (rev 1783)
+++ box/chris/general/bin/bbackupctl/bbackupctl.cpp 2007-07-31 23:18:50 UTC (rev 1784)
@@ -162,7 +162,7 @@
);
#if defined WIN32 && ! defined NDEBUG
- syslog(LOG_ERR,"Failed to connect to the command socket");
+ BOX_ERROR("Failed to connect to the command socket");
#endif
return 1;
@@ -175,29 +175,16 @@
std::string configSummary;
if(!getLine.GetLine(configSummary))
{
-#if defined WIN32 && ! defined NDEBUG
- syslog(LOG_ERR, "Failed to receive configuration summary "
+ BOX_ERROR("Failed to receive configuration summary "
"from daemon");
-#else
- printf("Failed to receive configuration summary from daemon\n");
-#endif
-
return 1;
}
// Was the connection rejected by the server?
if(getLine.IsEOF())
{
-#if defined WIN32 && ! defined NDEBUG
- syslog(LOG_ERR, "Server rejected the connection. "
- "Are you running bbackupctl as the same user "
- "as the daemon?");
-#else
- printf("Server rejected the connection. "
- "Are you running bbackupctl as the same user "
- "as the daemon?\n");
-#endif
-
+ BOX_ERROR("Server rejected the connection. Are you running "
+ "bbackupctl as the same user as the daemon?");
return 1;
}
@@ -224,11 +211,7 @@
std::string stateLine;
if(!getLine.GetLine(stateLine) || getLine.IsEOF())
{
-#if defined WIN32 && ! defined NDEBUG
- syslog(LOG_ERR, "Failed to receive state line from daemon");
-#else
- printf("Failed to receive state line from daemon\n");
-#endif
+ BOX_ERROR("Failed to receive state line from daemon");
return 1;
}
@@ -236,7 +219,7 @@
int currentState;
if(::sscanf(stateLine.c_str(), "state %d", ¤tState) != 1)
{
- printf("State line didn't decode\n");
+ BOX_ERROR("Received invalid state line from daemon");
return 1;
}
@@ -266,8 +249,8 @@
if(!autoBackup)
{
- printf("ERROR: Daemon is not in automatic mode -- "
- "sync will never start!\n");
+ BOX_ERROR("Daemon is not in automatic mode, "
+ "sync will never start!");
return 1;
}
Modified: box/chris/general/bin/bbackupd/BackupClientContext.cpp
===================================================================
--- box/chris/general/bin/bbackupd/BackupClientContext.cpp 2007-07-31 23:18:05 UTC (rev 1783)
+++ box/chris/general/bin/bbackupd/BackupClientContext.cpp 2007-07-31 23:18:50 UTC (rev 1784)
@@ -9,12 +9,10 @@
#include "Box.h"
-#ifdef HAVE_SYSLOG_H
- #include <syslog.h>
-#endif
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif
+
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
@@ -127,7 +125,8 @@
}
// Log intention
- ::syslog(LOG_INFO, "Opening connection to server %s...", mHostname.c_str());
+ BOX_INFO("Opening connection to server '" <<
+ mHostname << "'...");
// Connect!
mpSocket->Open(mrTLSContext, Socket::TypeINET, mHostname.c_str(), BOX_PORT_BBSTORED);
@@ -147,8 +146,8 @@
if (!mpExtendedLogFileHandle)
{
- ::syslog(LOG_ERR, "Failed to open extended "
- "log file: %s", strerror(errno));
+ BOX_ERROR("Failed to open extended log "
+ "file: " << strerror(errno));
}
else
{
@@ -194,7 +193,7 @@
}
// Log success
- ::syslog(LOG_INFO, "Connection made, login successful");
+ BOX_INFO("Connection made, login successful");
// Check to see if there is any space available on the server
if(loginConf->GetBlocksUsed() >= loginConf->GetBlocksHardLimit())
@@ -202,7 +201,8 @@
// no -- flag so only things like deletions happen
mStorageLimitExceeded = true;
// Log
- ::syslog(LOG_WARNING, "Exceeded storage hard-limit on server -- not uploading changes to files");
+ BOX_WARNING("Exceeded storage hard-limit on server, "
+ "not uploading changes to files");
}
}
catch(...)
Modified: box/chris/general/bin/bbackupd/Win32ServiceFunctions.cpp
===================================================================
--- box/chris/general/bin/bbackupd/Win32ServiceFunctions.cpp 2007-07-31 23:18:05 UTC (rev 1783)
+++ box/chris/general/bin/bbackupd/Win32ServiceFunctions.cpp 2007-07-31 23:18:50 UTC (rev 1784)
@@ -44,7 +44,7 @@
char buf[256];
memset(buf, 0, sizeof(buf));
_snprintf(buf, sizeof(buf)-1, "%s (%d)", s, err);
- ::syslog(LOG_ERR, "%s", buf);
+ BOX_ERROR(buf);
MessageBox(0, buf, "Error",
MB_OK | MB_SETFOREGROUND | MB_DEFAULT_DESKTOP_ONLY);
ExitProcess(err);
@@ -191,16 +191,16 @@
if (emu_stat(pConfigFileName, &st) != 0)
{
- syslog(LOG_ERR, "Failed to open configuration file: "
- "%s: %s", pConfigFileName, strerror(errno));
+ BOX_ERROR("Failed to open configuration file '" <<
+ pConfigFileName << "': " << strerror(errno));
return 1;
}
if (!(st.st_mode & S_IFREG))
{
- syslog(LOG_ERR, "Failed to open configuration file: "
- "%s: not a file", pConfigFileName);
+ BOX_ERROR("Failed to open configuration file '" <<
+ pConfigFileName << "': not a file");
return 1;
}
}
@@ -209,8 +209,8 @@
if (!scm)
{
- syslog(LOG_ERR, "Failed to open service control manager: "
- "error %d", GetLastError());
+ BOX_ERROR("Failed to open service control manager: " <<
+ GetErrorMessage(GetLastError()));
return 1;
}
@@ -248,21 +248,21 @@
{
case ERROR_SERVICE_EXISTS:
{
- ::syslog(LOG_ERR, "Failed to create Box Backup "
+ BOX_ERROR("Failed to create Box Backup "
"service: it already exists");
}
break;
case ERROR_SERVICE_MARKED_FOR_DELETE:
{
- ::syslog(LOG_ERR, "Failed to create Box Backup "
+ BOX_ERROR("Failed to create Box Backup "
"service: it is waiting to be deleted");
}
break;
case ERROR_DUPLICATE_SERVICE_NAME:
{
- ::syslog(LOG_ERR, "Failed to create Box Backup "
+ BOX_ERROR("Failed to create Box Backup "
"service: a service with this name "
"already exists");
}
@@ -270,15 +270,16 @@
default:
{
- ::syslog(LOG_ERR, "Failed to create Box Backup "
- "service: error %d", err);
+ BOX_ERROR("Failed to create Box Backup "
+ "service: error " <<
+ GetErrorMessage(GetLastError()));
}
}
return 1;
}
- ::syslog(LOG_INFO, "Created Box Backup service");
+ BOX_INFO("Created Box Backup service");
SERVICE_DESCRIPTION desc;
desc.lpDescription = "Backs up your data files over the Internet";
@@ -286,8 +287,8 @@
if (!ChangeServiceConfig2(newService, SERVICE_CONFIG_DESCRIPTION,
&desc))
{
- ::syslog(LOG_WARNING, "Failed to set description for "
- "Box Backup service: error %d", GetLastError());
+ BOX_WARNING("Failed to set description for Box Backup "
+ "service: " << GetErrorMessage(GetLastError()));
}
CloseServiceHandle(newService);
@@ -301,8 +302,8 @@
if (!scm)
{
- syslog(LOG_ERR, "Failed to open service control manager: "
- "error %d", GetLastError());
+ BOX_ERROR("Failed to open service control manager: " <<
+ GetErrorMessage(GetLastError()));
return 1;
}
@@ -317,13 +318,13 @@
err == ERROR_IO_PENDING)
// hello microsoft? anyone home?
{
- syslog(LOG_ERR, "Failed to open Box Backup service: "
+ BOX_ERROR("Failed to open Box Backup service: "
"not installed or not found");
}
else
{
- syslog(LOG_ERR, "Failed to open Box Backup service: "
- "error %d", err);
+ BOX_ERROR("Failed to open Box Backup service: " <<
+ GetErrorMessage(err));
}
return 1;
}
@@ -334,8 +335,8 @@
err = GetLastError();
if (err != ERROR_SERVICE_NOT_ACTIVE)
{
- syslog(LOG_WARNING, "Failed to stop Box Backup "
- "service: error %d", err);
+ BOX_WARNING("Failed to stop Box Backup service: " <<
+ GetErrorMessage(err));
}
}
@@ -345,18 +346,18 @@
if (deleted)
{
- syslog(LOG_INFO, "Box Backup service deleted");
+ BOX_INFO("Box Backup service deleted");
return 0;
}
else if (err == ERROR_SERVICE_MARKED_FOR_DELETE)
{
- syslog(LOG_ERR, "Failed to remove Box Backup service: "
+ BOX_ERROR("Failed to remove Box Backup service: "
"it is already being deleted");
}
else
{
- syslog(LOG_ERR, "Failed to remove Box Backup service: "
- "error %d", err);
+ BOX_ERROR("Failed to remove Box Backup service: " <<
+ GetErrorMessage(err));
}
return 1;
Modified: box/chris/general/bin/bbackupquery/BackupQueries.cpp
===================================================================
--- box/chris/general/bin/bbackupquery/BackupQueries.cpp 2007-07-31 23:18:05 UTC (rev 1783)
+++ box/chris/general/bin/bbackupquery/BackupQueries.cpp 2007-07-31 23:18:50 UTC (rev 1784)
@@ -2009,19 +2009,14 @@
false /* don't undelete after restore! */,
opts['r'] /* resume? */);
}
- catch (BoxException &e)
- {
- ::syslog(LOG_ERR, "Failed to restore: %s", e.what());
- return;
- }
catch(std::exception &e)
{
- ::syslog(LOG_ERR, "Failed to restore: %s", e.what());
+ BOX_ERROR("Failed to restore: " << e.what());
return;
}
catch(...)
{
- ::syslog(LOG_ERR, "Failed to restore: unknown error");
+ BOX_ERROR("Failed to restore: unknown exception");
return;
}
Modified: box/chris/general/bin/bbstored/BBStoreDHousekeeping.cpp
===================================================================
--- box/chris/general/bin/bbstored/BBStoreDHousekeeping.cpp 2007-07-31 23:18:05 UTC (rev 1783)
+++ box/chris/general/bin/bbstored/BBStoreDHousekeeping.cpp 2007-07-31 23:18:50 UTC (rev 1784)
@@ -11,10 +11,6 @@
#include <stdio.h>
-#ifdef HAVE_SYSLOG_H
- #include <syslog.h>
-#endif
-
#include "BackupStoreDaemon.h"
#include "BackupStoreAccountDatabase.h"
#include "BackupStoreAccounts.h"
@@ -82,7 +78,7 @@
// Store the time
mLastHousekeepingRun = timeNow;
- ::syslog(LOG_INFO, "Starting housekeeping");
+ BOX_INFO("Starting housekeeping");
// Get the list of accounts
std::vector<int32_t> accounts;
@@ -112,18 +108,25 @@
}
catch(BoxException &e)
{
- ::syslog(LOG_ERR, "while housekeeping account %08X, exception %s (%d/%d) -- aborting housekeeping run for this account",
- *i, e.what(), e.GetType(), e.GetSubType());
+ BOX_ERROR("Housekeeping on account " <<
+ BOX_FORMAT_ACCOUNT(*i) << " threw exception, "
+ "aborting run for this account: " <<
+ e.what() << " (" <<
+ e.GetType() << "/" << e.GetSubType() << ")");
}
catch(std::exception &e)
{
- ::syslog(LOG_ERR, "while housekeeping account %08X, exception %s -- aborting housekeeping run for this account",
- *i, e.what());
+ BOX_ERROR("Housekeeping on account " <<
+ BOX_FORMAT_ACCOUNT(*i) << " threw exception, "
+ "aborting run for this account: " <<
+ e.what());
}
catch(...)
{
- ::syslog(LOG_ERR, "while housekeeping account %08X, unknown exception -- aborting housekeeping run for this account",
- *i);
+ BOX_ERROR("Housekeeping on account " <<
+ BOX_FORMAT_ACCOUNT(*i) << " threw exception, "
+ "aborting run for this account: "
+ "unknown exception");
}
int64_t timeNow = GetCurrentBoxTime();
@@ -144,7 +147,7 @@
}
}
- ::syslog(LOG_INFO, "Finished housekeeping");
+ BOX_INFO("Finished housekeeping");
// Placed here for accuracy, if StopRun() is true, for example.
SetProcessTitle("housekeeping, idle");
@@ -190,7 +193,7 @@
std::string line;
if(mInterProcessComms.GetLine(line, false /* no pre-processing */, MaximumWaitTime))
{
- TRACE1("housekeeping received command '%s' over interprocess comms\n", line.c_str());
+ TRACE1("Housekeeping received command '%s' over interprocess comms\n", line.c_str());
int account = 0;
@@ -212,7 +215,9 @@
if(account == AccountNum)
{
// Yes! -- need to stop now so when it retries to get the lock, it will succeed
- ::syslog(LOG_INFO, "Housekeeping giving way to connection for account 0x%08x", AccountNum);
+ BOX_INFO("Housekeeping on account " <<
+ BOX_FORMAT_ACCOUNT(AccountNum) <<
+ "giving way to client connection");
return true;
}
}
Modified: box/chris/general/bin/bbstored/BackupCommands.cpp
===================================================================
--- box/chris/general/bin/bbstored/BackupCommands.cpp 2007-07-31 23:18:05 UTC (rev 1783)
+++ box/chris/general/bin/bbstored/BackupCommands.cpp 2007-07-31 23:18:50 UTC (rev 1784)
@@ -9,10 +9,6 @@
#include "Box.h"
-#ifdef HAVE_SYSLOG_H
-#include <syslog.h>
-#endif
-
#include <set>
#include <sstream>
@@ -88,22 +84,40 @@
// Check given client ID against the ID in the certificate certificate
// and that the client actually has an account on this machine
- if(mClientID != rContext.GetClientID() || !rContext.GetClientHasAccount())
+ if(mClientID != rContext.GetClientID())
{
- ::syslog(LOG_INFO, "Failed login: Client ID presented was %08X", mClientID);
- return std::auto_ptr<ProtocolObject>(new BackupProtocolServerError(
- BackupProtocolServerError::ErrorType, BackupProtocolServerError::Err_BadLogin));
+ BOX_WARNING("Failed login from client ID " <<
+ BOX_FORMAT_ACCOUNT(mClientID) <<
+ ": wrong certificate for this account");
+ return std::auto_ptr<ProtocolObject>(
+ new BackupProtocolServerError(
+ BackupProtocolServerError::ErrorType,
+ BackupProtocolServerError::Err_BadLogin));
}
+ if(!rContext.GetClientHasAccount())
+ {
+ BOX_WARNING("Failed login from client ID " <<
+ BOX_FORMAT_ACCOUNT(mClientID) <<
+ ": no such account on this server");
+ return std::auto_ptr<ProtocolObject>(
+ new BackupProtocolServerError(
+ BackupProtocolServerError::ErrorType,
+ BackupProtocolServerError::Err_BadLogin));
+ }
+
// If we need to write, check that nothing else has got a write lock
if((mFlags & Flags_ReadOnly) != Flags_ReadOnly)
{
// See if the context will get the lock
if(!rContext.AttemptToGetWriteLock())
{
- ::syslog(LOG_INFO, "Failed to get write lock (for Client ID %08X)", mClientID);
- return std::auto_ptr<ProtocolObject>(new BackupProtocolServerError(
- BackupProtocolServerError::ErrorType, BackupProtocolServerError::Err_CannotLockStoreForWriting));
+ BOX_WARNING("Failed to get write lock for Client ID " <<
+ BOX_FORMAT_ACCOUNT(mClientID));
+ return std::auto_ptr<ProtocolObject>(
+ new BackupProtocolServerError(
+ BackupProtocolServerError::ErrorType,
+ BackupProtocolServerError::Err_CannotLockStoreForWriting));
}
// Debug: check we got the lock
@@ -120,7 +134,11 @@
rContext.SetPhase(BackupContext::Phase_Commands);
// Log login
- ::syslog(LOG_INFO, "Login: Client ID %08X, %s", mClientID, ((mFlags & Flags_ReadOnly) != Flags_ReadOnly)?"Read/Write":"Read-only");
+ BOX_NOTICE("Login from Client ID " <<
+ BOX_FORMAT_ACCOUNT(mClientID) <<
+ " " <<
+ (((mFlags & Flags_ReadOnly) != Flags_ReadOnly)
+ ?"Read/Write":"Read-only"));
// Get the usage info for reporting to the client
int64_t blocksUsed = 0, blocksSoftLimit = 0, blocksHardLimit = 0;
@@ -140,7 +158,8 @@
// --------------------------------------------------------------------------
std::auto_ptr<ProtocolObject> BackupProtocolServerFinished::DoCommand(BackupProtocolServer &rProtocol, BackupContext &rContext)
{
- ::syslog(LOG_INFO, "Session finished");
+ BOX_NOTICE("Session finished for Client ID " <<
+ BOX_FORMAT_ACCOUNT(rContext.GetClientID()));
// Let the context know about it
rContext.ReceivedFinishCommand();
@@ -311,13 +330,23 @@
en = rdir.FindEntryByID(id);
if(en == 0)
{
- ::syslog(LOG_ERR, "Object %llx in dir %llx for account %x references object %llx which does not exist in dir",
- mObjectID, mInDirectory, rContext.GetClientID(), id);
- return std::auto_ptr<ProtocolObject>(new BackupProtocolServerError(
- BackupProtocolServerError::ErrorType, BackupProtocolServerError::Err_PatchConsistencyError));
+ BOX_ERROR("Object " <<
+ BOX_FORMAT_OBJECTID(mObjectID) <<
+ " in dir " <<
+ BOX_FORMAT_OBJECTID(mInDirectory) <<
+ " for account " <<
+ BOX_FORMAT_ACCOUNT(rContext.GetClientID()) <<
+ " references object " <<
+ BOX_FORMAT_OBJECTID(id) <<
+ " which does not exist in dir");
+ return std::auto_ptr<ProtocolObject>(
+ new BackupProtocolServerError(
+ BackupProtocolServerError::ErrorType,
+ BackupProtocolServerError::Err_PatchConsistencyError));
}
id = en->GetDependsNewer();
- } while(en != 0 && id != 0);
+ }
+ while(en != 0 && id != 0);
// OK! The last entry in the chain is the full file, the others are patches back from it.
// Open the last one, which is the current from file
Modified: box/chris/general/bin/bbstored/BackupStoreDaemon.cpp
===================================================================
--- box/chris/general/bin/bbstored/BackupStoreDaemon.cpp 2007-07-31 23:18:05 UTC (rev 1783)
+++ box/chris/general/bin/bbstored/BackupStoreDaemon.cpp 2007-07-31 23:18:50 UTC (rev 1784)
@@ -208,7 +208,7 @@
// Change the log name
::openlog("bbstored/hk", LOG_PID, LOG_LOCAL6);
// Log that housekeeping started
- ::syslog(LOG_INFO, "Housekeeping process started");
+ BOX_INFO("Housekeeping process started");
// Ignore term and hup
// Parent will handle these and alert the child via the socket, don't want to randomly die
::signal(SIGHUP, SIG_IGN);
@@ -281,19 +281,19 @@
}
catch(BoxException &e)
{
- ::syslog(LOG_ERR, "%s: disconnecting due to "
- "exception %s (%d/%d)", DaemonName(),
- e.what(), e.GetType(), e.GetSubType());
+ BOX_ERROR("Error in child process, terminating connection: " <<
+ e.what() << " (" << e.GetType() << "/" <<
+ e.GetSubType() << ")");
}
catch(std::exception &e)
{
- ::syslog(LOG_ERR, "%s: disconnecting due to "
- "exception %s", DaemonName(), e.what());
+ BOX_ERROR("Error in child process, terminating connection: " <<
+ e.what());
}
catch(...)
{
- ::syslog(LOG_ERR, "%s: disconnecting due to "
- "unknown exception", DaemonName());
+ BOX_ERROR("Error in child process, terminating connection: " <<
+ "unknown exception");
}
}
@@ -311,7 +311,7 @@
std::string clientCommonName(rStream.GetPeerCommonName());
// Log the name
- ::syslog(LOG_INFO, "Certificate CN: %s", clientCommonName.c_str());
+ BOX_INFO("Client certificate CN: " << clientCommonName);
// Check it
int32_t id;
@@ -357,10 +357,8 @@
const SocketStreamTLS &s)
{
// Log the amount of data transferred
- ::syslog(LOG_INFO, "Connection statistics for %s: "
- "IN=%lld OUT=%lld TOTAL=%lld", commonName,
- (long long)s.GetBytesRead(),
- (long long)s.GetBytesWritten(),
- (long long)s.GetBytesRead() +
- (long long)s.GetBytesWritten());
+ BOX_INFO("Connection statistics for " << commonName << ":"
+ " IN=" << s.GetBytesRead() <<
+ " OUT=" << s.GetBytesWritten() <<
+ " TOTAL=" << (s.GetBytesRead() + s.GetBytesWritten()));
}
Modified: box/chris/general/bin/bbstored/HousekeepStoreAccount.cpp
===================================================================
--- box/chris/general/bin/bbstored/HousekeepStoreAccount.cpp 2007-07-31 23:18:05 UTC (rev 1783)
+++ box/chris/general/bin/bbstored/HousekeepStoreAccount.cpp 2007-07-31 23:18:50 UTC (rev 1784)
@@ -9,9 +9,10 @@
#include "Box.h"
-#include <map>
#include <stdio.h>
+#include <map>
+
#include "HousekeepStoreAccount.h"
#include "BackupStoreDaemon.h"
#include "StoreStructure.h"
@@ -137,11 +138,18 @@
|| (usedDeleted + mBlocksInDeletedFilesDelta) != mBlocksInDeletedFiles || usedDirectories != mBlocksInDirectories)
{
// Log this
- ::syslog(LOG_ERR, "On housekeeping, sizes in store do not match calculated sizes, correcting");
- ::syslog(LOG_ERR, "different (store,calc): acc 0x%08x, used (%lld,%lld), old (%lld,%lld), deleted (%lld,%lld), dirs (%lld,%lld)",
- mAccountID,
- (used + mBlocksUsedDelta), mBlocksUsed, (usedOld + mBlocksInOldFilesDelta), mBlocksInOldFiles,
- (usedDeleted + mBlocksInDeletedFilesDelta), mBlocksInDeletedFiles, usedDirectories, mBlocksInDirectories);
+ BOX_ERROR("Housekeeping on account " <<
+ BOX_FORMAT_ACCOUNT(mAccountID) << " found "
+ "and fixed wrong block counts: "
+ "used (" <<
+ (used + mBlocksUsedDelta) << "," <<
+ mBlocksUsed << "), old (" <<
+ (usedOld + mBlocksInOldFilesDelta) << "," <<
+ mBlocksInOldFiles << "), deleted (" <<
+ (usedDeleted + mBlocksInDeletedFilesDelta) <<
+ "," << mBlocksInDeletedFiles << "), dirs (" <<
+ usedDirectories << "," << mBlocksInDirectories
+ << ")");
}
// If the current values don't match, store them
@@ -173,17 +181,33 @@
// Log deletion if anything was deleted
if(mFilesDeleted > 0 || mEmptyDirectoriesDeleted > 0)
{
- ::syslog(LOG_INFO, "Account 0x%08x, removed %lld blocks (%lld files, %lld dirs)%s", mAccountID, 0 - (mBlocksUsedDelta + removeASAPBlocksUsedDelta),
- mFilesDeleted, mEmptyDirectoriesDeleted,
- deleteInterrupted?" was interrupted":"");
+ BOX_INFO("Housekeeping on account " <<
+ BOX_FORMAT_ACCOUNT(mAccountID) << " "
+ "removed " <<
+ (0 - (mBlocksUsedDelta + removeASAPBlocksUsedDelta)) <<
+ " blocks (" << mFilesDeleted << " files, " <<
+ mEmptyDirectoriesDeleted << " dirs)" <<
+ (deleteInterrupted?" and was interrupted":""));
}
// Make sure the delta's won't cause problems if the counts are really wrong, and
// it wasn't fixed because the store was updated during the scan.
- if(mBlocksUsedDelta < (0 - info->GetBlocksUsed())) mBlocksUsedDelta = (0 - info->GetBlocksUsed());
- if(mBlocksInOldFilesDelta < (0 - info->GetBlocksInOldFiles())) mBlocksInOldFilesDelta = (0 - info->GetBlocksInOldFiles());
- if(mBlocksInDeletedFilesDelta < (0 - info->GetBlocksInDeletedFiles())) mBlocksInDeletedFilesDelta =(0 - info->GetBlocksInDeletedFiles());
- if(mBlocksInDirectoriesDelta < (0 - info->GetBlocksInDirectories())) mBlocksInDirectoriesDelta = (0 - info->GetBlocksInDirectories());
+ if(mBlocksUsedDelta < (0 - info->GetBlocksUsed()))
+ {
+ mBlocksUsedDelta = (0 - info->GetBlocksUsed());
+ }
+ if(mBlocksInOldFilesDelta < (0 - info->GetBlocksInOldFiles()))
+ {
+ mBlocksInOldFilesDelta = (0 - info->GetBlocksInOldFiles());
+ }
+ if(mBlocksInDeletedFilesDelta < (0 - info->GetBlocksInDeletedFiles()))
+ {
+ mBlocksInDeletedFilesDelta = (0 - info->GetBlocksInDeletedFiles());
+ }
+ if(mBlocksInDirectoriesDelta < (0 - info->GetBlocksInDirectories()))
+ {
+ mBlocksInDirectoriesDelta = (0 - info->GetBlocksInDirectories());
+ }
// Update the usage counts in the store
info->ChangeBlocksUsed(mBlocksUsedDelta);
@@ -554,7 +578,14 @@
BackupStoreDirectory::Entry *pentry = rDirectory.FindEntryByID(ObjectID);
if(pentry == 0)
{
- ::syslog(LOG_ERR, "acc 0x%08x, object %lld not found in dir %lld, logic error/corruption? Run bbstoreaccounts check <accid> fix", mAccountID, ObjectID, InDirectory);
+ BOX_ERROR("Housekeeping on account " <<
+ BOX_FORMAT_ACCOUNT(mAccountID) << " "
+ "found error: object " <<
+ BOX_FORMAT_OBJECTID(ObjectID) << " "
+ "not found in dir " <<
+ BOX_FORMAT_OBJECTID(InDirectory) << ", "
+ "indicates logic error/corruption? Run "
+ "bbstoreaccounts check <accid> fix");
return;
}
Modified: box/chris/general/lib/backupclient/BackupClientFileAttributes.cpp
===================================================================
--- box/chris/general/lib/backupclient/BackupClientFileAttributes.cpp 2007-07-31 23:18:05 UTC (rev 1783)
+++ box/chris/general/lib/backupclient/BackupClientFileAttributes.cpp 2007-07-31 23:18:50 UTC (rev 1784)
@@ -344,8 +344,8 @@
// to be true (still aborts), but it can at least hold 2^32.
if (winTime >= 0x100000000LL || _gmtime64(&winTime) == 0)
{
- ::syslog(LOG_ERR, "Invalid Modification Time "
- "caught for file: %s", Filename);
+ BOX_ERROR("Invalid Modification Time caught for "
+ "file: '" << Filename << "'");
pattr->ModificationTime = 0;
}
@@ -355,8 +355,8 @@
if (winTime > 0x100000000LL || _gmtime64(&winTime) == 0)
{
- ::syslog(LOG_ERR, "Invalid Attribute Modification "
- "Time caught for file: %s", Filename);
+ BOX_ERROR("Invalid Attribute Modification Time "
+ "caught for file: '" << Filename << "'");
pattr->AttrModificationTime = 0;
}
#endif
@@ -627,9 +627,8 @@
}
#ifdef WIN32
- ::syslog(LOG_WARNING,
- "Cannot create symbolic links on Windows: %s",
- Filename);
+ BOX_WARNING("Cannot create symbolic links on Windows: '" <<
+ Filename << "'");
#else
// Make a symlink, first deleting anything in the way
::unlink(Filename);
Modified: box/chris/general/lib/backupclient/BackupClientRestore.cpp
===================================================================
--- box/chris/general/lib/backupclient/BackupClientRestore.cpp 2007-07-31 23:18:05 UTC (rev 1783)
+++ box/chris/general/lib/backupclient/BackupClientRestore.cpp 2007-07-31 23:18:50 UTC (rev 1784)
@@ -235,20 +235,20 @@
}
catch (BoxException &e)
{
- ::syslog(LOG_ERR, "Failed to check existence for %s: %s",
- rLocalDirectoryName.c_str(), e.what());
+ BOX_ERROR("Failed to check existence for " <<
+ rLocalDirectoryName << ": " << e.what());
return Restore_UnknownError;
}
catch(std::exception &e)
{
- ::syslog(LOG_ERR, "Failed to check existence for %s: %s",
- rLocalDirectoryName.c_str(), e.what());
+ BOX_ERROR("Failed to check existence for " <<
+ rLocalDirectoryName << ": " << e.what());
return Restore_UnknownError;
}
catch(...)
{
- ::syslog(LOG_ERR, "Failed to check existence for %s: "
- "unknown error", rLocalDirectoryName.c_str());
+ BOX_ERROR("Failed to check existence for " <<
+ rLocalDirectoryName << ": unknown error");
return Restore_UnknownError;
}
@@ -263,13 +263,14 @@
::printf("WARNING: File present with name '%s', removing out of the way of restored directory. Use specific restore with ID to restore this object.", rLocalDirectoryName.c_str());
if(::unlink(rLocalDirectoryName.c_str()) != 0)
{
- ::syslog(LOG_ERR, "Failed to delete "
- "file %s: %s",
- rLocalDirectoryName.c_str(),
+ BOX_ERROR("Failed to delete file " <<
+ rLocalDirectoryName << ": " <<
strerror(errno));
return Restore_UnknownError;
}
- TRACE1("In restore, directory name collision with file %s", rLocalDirectoryName.c_str());
+ BOX_TRACE("In restore, directory name "
+ "collision with file " <<
+ rLocalDirectoryName);
}
break;
case ObjectExists_NoObject:
@@ -325,20 +326,20 @@
}
catch (BoxException &e)
{
- ::syslog(LOG_ERR, "Failed to check existence for %s: "
- "%s", parentDirectoryName.c_str(), e.what());
+ BOX_ERROR("Failed to check existence for " <<
+ parentDirectoryName << ": " << e.what());
return Restore_UnknownError;
}
catch(std::exception &e)
{
- ::syslog(LOG_ERR, "Failed to check existence for %s: "
- "%s", parentDirectoryName.c_str(), e.what());
+ BOX_ERROR("Failed to check existence for " <<
+ parentDirectoryName << ": " << e.what());
return Restore_UnknownError;
}
catch(...)
{
- ::syslog(LOG_ERR, "Failed to check existence for %s: "
- "unknown error", parentDirectoryName.c_str());
+ BOX_ERROR("Failed to check existence for " <<
+ parentDirectoryName << ": unknown error");
return Restore_UnknownError;
}
@@ -349,24 +350,22 @@
break;
case ObjectExists_File:
- fprintf(stderr, "Failed to restore: '%s' "
+ BOX_ERROR("Failed to restore: '" <<
+ parentDirectoryName << "' "
"is a file, but should be a "
- "directory.\n",
- parentDirectoryName.c_str());
+ "directory.");
return Restore_TargetPathNotFound;
case ObjectExists_NoObject:
- fprintf(stderr, "Failed to restore: "
- "parent '%s' of target directory "
- "does not exist.\n",
- parentDirectoryName.c_str());
+ BOX_ERROR("Failed to restore: parent '" <<
+ parentDirectoryName << "' of target "
+ "directory does not exist.");
return Restore_TargetPathNotFound;
default:
- fprintf(stderr, "Failed to restore: "
- "unknown result from "
- "ObjectExists('%s').\n",
- parentDirectoryName.c_str());
+ BOX_ERROR("Failed to restore: unknown "
+ "result from ObjectExists('" <<
+ parentDirectoryName << "')");
return Restore_UnknownError;
}
}
@@ -375,8 +374,8 @@
exists == ObjectExists_File) &&
::mkdir(rLocalDirectoryName.c_str(), S_IRWXU) != 0)
{
- ::syslog(LOG_ERR, "Failed to create directory %s: %s",
- rLocalDirectoryName.c_str(),
+ BOX_ERROR("Failed to create directory '" <<
+ rLocalDirectoryName << "': " <<
strerror(errno));
return Restore_UnknownError;
}
@@ -386,23 +385,18 @@
{
Params.mResumeInfo.Save(Params.mRestoreResumeInfoFilename);
}
- catch (BoxException &e)
- {
- ::syslog(LOG_ERR, "Failed to save resume info file %s: %s",
- Params.mRestoreResumeInfoFilename.c_str(), e.what());
- return Restore_UnknownError;
- }
catch(std::exception &e)
{
- ::syslog(LOG_ERR, "Failed to save resume info file %s: %s",
- Params.mRestoreResumeInfoFilename.c_str(), e.what());
+ BOX_ERROR("Failed to save resume info file '" <<
+ Params.mRestoreResumeInfoFilename << "': " <<
+ e.what());
return Restore_UnknownError;
}
catch(...)
{
- ::syslog(LOG_ERR, "Failed to save resume info file %s: "
- "unknown error",
- Params.mRestoreResumeInfoFilename.c_str());
+ BOX_ERROR("Failed to save resume info file '" <<
+ Params.mRestoreResumeInfoFilename <<
+ "': unknown error");
return Restore_UnknownError;
}
@@ -427,22 +421,16 @@
{
dirAttr.WriteAttributes(rLocalDirectoryName.c_str(), true);
}
- catch (BoxException &e)
- {
- ::syslog(LOG_ERR, "Failed to restore attributes for %s: %s",
- rLocalDirectoryName.c_str(), e.what());
- return Restore_UnknownError;
- }
catch(std::exception &e)
{
- ::syslog(LOG_ERR, "Failed to restore attributes for %s: %s",
- rLocalDirectoryName.c_str(), e.what());
+ BOX_ERROR("Failed to restore attributes for '" <<
+ rLocalDirectoryName << "': " << e.what());
return Restore_UnknownError;
}
catch(...)
{
- ::syslog(LOG_ERR, "Failed to restore attributes for %s: "
- "unknown error", rLocalDirectoryName.c_str());
+ BOX_ERROR("Failed to restore attributes for '" <<
+ rLocalDirectoryName << "': unknown error");
return Restore_UnknownError;
}
@@ -464,9 +452,8 @@
// Unlink anything which already exists -- for resuming restores, we can't overwrite files already there.
if(::unlink(localFilename.c_str()) == 0)
{
- ::syslog(LOG_ERR, "Failed to delete "
- "file %s: %s",
- localFilename.c_str(),
+ BOX_ERROR("Failed to delete file '" <<
+ localFilename << "': " <<
strerror(errno));
return Restore_UnknownError;
}
@@ -494,27 +481,18 @@
BackupStoreFile::DecodeFile(*objectStream, localFilename.c_str(), rConnection.GetTimeout());
}
}
- catch (BoxException &e)
- {
- ::syslog(LOG_ERR, "Failed to restore "
- "file %s: %s",
- localFilename.c_str(),
- e.what());
- return Restore_UnknownError;
- }
catch(std::exception &e)
{
- ::syslog(LOG_ERR, "Failed to restore "
- "file %s: %s",
- localFilename.c_str(),
+ BOX_ERROR("Failed to restore file '" <<
+ localFilename << "': " <<
e.what());
return Restore_UnknownError;
}
catch(...)
{
- ::syslog(LOG_ERR, "Failed to restore "
- "file %s: unknown error",
- localFilename.c_str());
+ BOX_ERROR("Failed to restore file '" <<
+ localFilename <<
+ "': unknown error");
return Restore_UnknownError;
}
@@ -540,28 +518,20 @@
true /* treat links as not
existing */);
}
- catch (BoxException &e)
- {
- ::syslog(LOG_ERR, "Failed to determine "
- "whether file exists: %s: %s",
- localFilename.c_str(),
- e.what());
- return Restore_UnknownError;
- }
catch(std::exception &e)
{
- ::syslog(LOG_ERR, "Failed to determine "
- "whether file exists: %s: %s",
- localFilename.c_str(),
+ BOX_ERROR("Failed to determine "
+ "whether file exists: '" <<
+ localFilename << "': " <<
e.what());
return Restore_UnknownError;
}
catch(...)
{
- ::syslog(LOG_ERR, "Failed to determine "
- "whether file exists: %s: "
- "unknown error",
- localFilename.c_str());
+ BOX_ERROR("Failed to determine "
+ "whether file exists: '" <<
+ localFilename << "': "
+ "unknown error");
return Restore_UnknownError;
}
@@ -577,23 +547,18 @@
{
Params.mResumeInfo.Save(Params.mRestoreResumeInfoFilename);
}
- catch (BoxException &e)
- {
- ::syslog(LOG_ERR, "Failed to save resume info file %s: %s",
- Params.mRestoreResumeInfoFilename.c_str(), e.what());
- return Restore_UnknownError;
- }
catch(std::exception &e)
{
- ::syslog(LOG_ERR, "Failed to save resume info file %s: %s",
- Params.mRestoreResumeInfoFilename.c_str(), e.what());
+ BOX_ERROR("Failed to save resume info file '" <<
+ Params.mRestoreResumeInfoFilename <<
+ "': " << e.what());
return Restore_UnknownError;
}
catch(...)
{
- ::syslog(LOG_ERR, "Failed to save resume info file %s: "
- "unknown error",
- Params.mRestoreResumeInfoFilename.c_str());
+ BOX_ERROR("Failed to save resume info file '" <<
+ Params.mRestoreResumeInfoFilename <<
+ "': unknown error");
return Restore_UnknownError;
}
@@ -613,27 +578,18 @@
Params.mResumeInfo.Save(
Params.mRestoreResumeInfoFilename);
}
- catch (BoxException &e)
- {
- ::syslog(LOG_ERR, "Failed to save resume info file "
- "%s: %s",
- Params.mRestoreResumeInfoFilename.c_str(),
- e.what());
- return Restore_UnknownError;
- }
catch(std::exception &e)
{
- ::syslog(LOG_ERR, "Failed to save resume info file "
- "%s: %s",
- Params.mRestoreResumeInfoFilename.c_str(),
+ BOX_ERROR("Failed to save resume info file '" <<
+ Params.mRestoreResumeInfoFilename << "': " <<
e.what());
return Restore_UnknownError;
}
catch(...)
{
- ::syslog(LOG_ERR, "Failed to save resume info file "
- "%s: unknown error",
- Params.mRestoreResumeInfoFilename.c_str());
+ BOX_ERROR("Failed to save resume info file '" <<
+ Params.mRestoreResumeInfoFilename <<
+ "': unknown error");
return Restore_UnknownError;
}
@@ -681,22 +637,16 @@
{
dirAttr.WriteAttributes(rLocalDirectoryName.c_str(), false);
}
- catch (BoxException &e)
- {
- ::syslog(LOG_ERR, "Failed to restore attributes for %s: %s",
- rLocalDirectoryName.c_str(), e.what());
- return Restore_UnknownError;
- }
catch(std::exception &e)
{
- ::syslog(LOG_ERR, "Failed to restore attributes for %s: %s",
- rLocalDirectoryName.c_str(), e.what());
+ BOX_ERROR("Failed to restore attributes for '" <<
+ rLocalDirectoryName << "': " << e.what());
return Restore_UnknownError;
}
catch(...)
{
- ::syslog(LOG_ERR, "Failed to restore attributes for %s: "
- "unknown error", rLocalDirectoryName.c_str());
+ BOX_ERROR("Failed to restore attributes for '" <<
+ rLocalDirectoryName << "': unknown error");
return Restore_UnknownError;
}
Modified: box/chris/general/lib/backupclient/BackupStoreFile.cpp
===================================================================
--- box/chris/general/lib/backupclient/BackupStoreFile.cpp 2007-07-31 23:18:05 UTC (rev 1783)
+++ box/chris/general/lib/backupclient/BackupStoreFile.cpp 2007-07-31 23:18:50 UTC (rev 1784)
@@ -17,10 +17,8 @@
#include <string.h>
#include <new>
#include <string.h>
+
#ifndef BOX_DISABLE_BACKWARDS_COMPATIBILITY_BACKUPSTOREFILE
- #ifndef WIN32
- #include <syslog.h>
- #endif
#include <stdio.h>
#endif
@@ -758,8 +756,7 @@
// Warn and log this issue
if(!sWarnedAboutBackwardsCompatiblity)
{
- ::printf("WARNING: Decoded one or more files using backwards compatibility mode for block index.\n");
- ::syslog(LOG_ERR, "WARNING: Decoded one or more files using backwards compatibility mode for block index.\n");
+ BOX_WARNING("WARNING: Decoded one or more files using backwards compatibility mode for block index.");
sWarnedAboutBackwardsCompatiblity = true;
}
}
Modified: box/chris/general/lib/common/BoxTime.cpp
===================================================================
--- box/chris/general/lib/common/BoxTime.cpp 2007-07-31 23:18:05 UTC (rev 1783)
+++ box/chris/general/lib/common/BoxTime.cpp 2007-07-31 23:18:50 UTC (rev 1784)
@@ -12,12 +12,11 @@
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
+
#ifdef HAVE_TIME_H
#include <time.h>
#endif
-#ifdef HAVE_SYSLOG_H
- #include <syslog.h>
-#endif
+
#include <errno.h>
#include <string.h>
@@ -40,8 +39,8 @@
struct timeval tv;
if (gettimeofday(&tv, NULL) != 0)
{
- ::syslog(LOG_ERR, "gettimeofday() failed (%s), "
- "dropping precision", strerror(errno));
+ BOX_ERROR("Failed to gettimeofday(), dropping "
+ "precision: " << strerror(errno));
}
else
{
Modified: box/chris/general/lib/common/DebugPrintf.cpp
===================================================================
--- box/chris/general/lib/common/DebugPrintf.cpp 2007-07-31 23:18:05 UTC (rev 1783)
+++ box/chris/general/lib/common/DebugPrintf.cpp 2007-07-31 23:18:50 UTC (rev 1784)
@@ -14,12 +14,6 @@
#include <stdio.h>
#include <stdarg.h>
-#ifdef WIN32
- #include "emu.h"
-#else
- #include <syslog.h>
-#endif
-
#include "MemLeakFindOn.h"
// Use this apparently superflous printf function to avoid having to
Modified: box/chris/general/lib/common/Logging.h
===================================================================
--- box/chris/general/lib/common/Logging.h 2007-07-31 23:18:05 UTC (rev 1783)
+++ box/chris/general/lib/common/Logging.h 2007-07-31 23:18:50 UTC (rev 1784)
@@ -10,6 +10,7 @@
#ifndef LOGGING__H
#define LOGGING__H
+#include <iomanip>
#include <sstream>
#include <vector>
@@ -42,6 +43,19 @@
#define BOX_TRACE(stuff) BOX_LOG(Log::TRACE, stuff)
#endif
+#define BOX_FORMAT_ACCOUNT(accno) \
+ std::hex << \
+ std::showbase << \
+ std::internal << \
+ std::setw(8) << \
+ std::setfill('0') << \
+ (accno)
+
+#define BOX_FORMAT_OBJECTID(objectid) \
+ std::hex << \
+ std::showbase << \
+ (objectid)
+
#undef ERROR
namespace Log
Modified: box/chris/general/lib/raidfile/RaidFileRead.cpp
===================================================================
--- box/chris/general/lib/raidfile/RaidFileRead.cpp 2007-07-31 23:18:05 UTC (rev 1783)
+++ box/chris/general/lib/raidfile/RaidFileRead.cpp 2007-07-31 23:18:50 UTC (rev 1784)
@@ -21,10 +21,6 @@
#include <sys/uio.h>
#endif
-#ifdef HAVE_SYSLOG_H
- #include <syslog.h>
-#endif
-
#ifdef HAVE_DIRENT_H
#include <dirent.h>
#endif
@@ -548,8 +544,8 @@
// --------------------------------------------------------------------------
void RaidFileRead_Raid::AttemptToRecoverFromIOError(bool Stripe1)
{
- TRACE3("Attempting to recover from I/O error: %d %s, on stripe %d\n", mSetNumber, mFilename.c_str(), Stripe1?1:2);
- ::syslog(LOG_ERR | LOG_LOCAL5, "Attempting to recover from I/O error: %d %s, on stripe %d\n", mSetNumber, mFilename.c_str(), Stripe1?1:2);
+ BOX_WARNING("Attempting to recover from I/O error: " << mSetNumber <<
+ " " << mFilename << ", on stripe " << (Stripe1?1:2));
// Close offending file
if(Stripe1)
@@ -861,8 +857,10 @@
{
if(errno == EIO)
{
- TRACE3("I/O error when seeking in %d %s (to %d), stripe 1\n", mSetNumber, mFilename.c_str(), (int)FilePosition);
- ::syslog(LOG_ERR | LOG_LOCAL5, "I/O error when seeking in %d %s (to %d), stripe 1\n", mSetNumber, mFilename.c_str(), (int)FilePosition);
+ BOX_ERROR("I/O error when seeking in " <<
+ mSetNumber << " " << mFilename <<
+ " (to " << FilePosition << "), " <<
+ "stripe 1");
// Attempt to recover
AttemptToRecoverFromIOError(true /* is stripe 1 */);
ASSERT(mStripe1Handle == -1);
@@ -879,8 +877,10 @@
{
if(errno == EIO)
{
- TRACE3("I/O error when seeking in %d %s (to %d), stripe 2\n", mSetNumber, mFilename.c_str(), (int)FilePosition);
- ::syslog(LOG_ERR | LOG_LOCAL5, "I/O error when seeking in %d %s (to %d), stripe 2\n", mSetNumber, mFilename.c_str(), (int)FilePosition);
+ BOX_ERROR("I/O error when seeking in " <<
+ mSetNumber << " " << mFilename <<
+ " (to " << FilePosition << "), " <<
+ "stripe 2");
// Attempt to recover
AttemptToRecoverFromIOError(false /* is stripe 2 */);
ASSERT(mStripe2Handle == -1);
@@ -1054,8 +1054,9 @@
{
if(existance != RaidFileUtil::AsRaid)
{
- TRACE2("Opening %d %s in normal mode, but parity file doesn't exist\n", SetNumber, Filename.c_str());
- ::syslog(LOG_ERR | LOG_LOCAL5, "Opening %d %s in normal mode, but parity file doesn't exist\n", SetNumber, Filename.c_str());
+ BOX_ERROR("Opening " << SetNumber << " " <<
+ Filename << " in normal mode, but "
+ "parity file doesn't exist");
// TODO: Alert recovery daemon
}
@@ -1130,8 +1131,9 @@
bool oktotryagain = true;
if(stripe1errno == EIO)
{
- TRACE2("I/O error on opening %d %s stripe 1, trying recovery mode\n", SetNumber, Filename.c_str());
- ::syslog(LOG_ERR | LOG_LOCAL5, "I/O error on opening %d %s stripe 1, trying recovery mode\n", SetNumber, Filename.c_str());
+ BOX_ERROR("I/O error on opening " <<
+ SetNumber << " " << Filename <<
+ " stripe 1, trying recovery mode");
RaidFileRead_Raid::MoveDamagedFileAlertDaemon(SetNumber, Filename, true /* is stripe 1 */);
existingFiles = existingFiles & ~RaidFileUtil::Stripe1Exists;
@@ -1146,8 +1148,9 @@
if(stripe2errno == EIO)
{
- TRACE2("I/O error on opening %d %s stripe 2, trying recovery mode\n", SetNumber, Filename.c_str());
- ::syslog(LOG_ERR | LOG_LOCAL5, "I/O error on opening %d %s stripe 2, trying recovery mode\n", SetNumber, Filename.c_str());
+ BOX_ERROR("I/O error on opening " <<
+ SetNumber << " " << Filename <<
+ " stripe 2, trying recovery mode");
RaidFileRead_Raid::MoveDamagedFileAlertDaemon(SetNumber, Filename, false /* is stripe 2 */);
existingFiles = existingFiles & ~RaidFileUtil::Stripe2Exists;
@@ -1169,8 +1172,10 @@
if(existance == RaidFileUtil::AsRaidWithMissingReadable)
{
- TRACE3("Attempting to open RAID file %d %s in recovery mode (stripe %d present)\n", SetNumber, Filename.c_str(), (existingFiles & RaidFileUtil::Stripe1Exists)?1:2);
- ::syslog(LOG_ERR | LOG_LOCAL5, "Attempting to open RAID file %d %s in recovery mode (stripe %d present)\n", SetNumber, Filename.c_str(), (existingFiles & RaidFileUtil::Stripe1Exists)?1:2);
+ BOX_ERROR("Attempting to open RAID file " << SetNumber <<
+ " " << Filename << " in recovery mode (stripe " <<
+ ((existingFiles & RaidFileUtil::Stripe1Exists)?1:2) <<
+ " present)");
// Generate the filenames of all the lovely files
std::string stripe1Filename(RaidFileUtil::MakeRaidComponentName(rdiscSet, Filename, (0 + startDisc) % READ_NUMBER_DISCS_REQUIRED));
Modified: box/chris/general/lib/server/Daemon.cpp
===================================================================
--- box/chris/general/lib/server/Daemon.cpp 2007-07-31 23:18:05 UTC (rev 1783)
+++ box/chris/general/lib/server/Daemon.cpp 2007-07-31 23:18:50 UTC (rev 1784)
@@ -19,10 +19,6 @@
#include <string.h>
#include <stdarg.h>
-#ifdef HAVE_SYSLOG_H
- #include <syslog.h>
-#endif
-
#ifdef WIN32
#include <ws2tcpip.h>
#endif
@@ -353,7 +349,8 @@
// Set new session
if(::setsid() == -1)
{
- ::syslog(LOG_ERR, "can't setsid");
+ BOX_ERROR("Failed to setsid(): " <<
+ strerror(errno));
THROW_EXCEPTION(ServerException, DaemoniseFailed)
}
Modified: box/chris/general/lib/server/LocalProcessStream.cpp
===================================================================
--- box/chris/general/lib/server/LocalProcessStream.cpp 2007-07-31 23:18:05 UTC (rev 1783)
+++ box/chris/general/lib/server/LocalProcessStream.cpp 2007-07-31 23:18:50 UTC (rev 1784)
@@ -120,8 +120,8 @@
HANDLE writeInChild, readFromChild;
if(!CreatePipe(&readFromChild, &writeInChild, &secAttr, 0))
{
- ::syslog(LOG_ERR, "Failed to CreatePipe for child process: "
- "error %d", GetLastError());
+ BOX_ERROR("Failed to CreatePipe for child process: "
+ GetErrorMessage(GetLastError()));
THROW_EXCEPTION(ServerException, SocketPairFailed)
}
SetHandleInformation(readFromChild, HANDLE_FLAG_INHERIT, 0);
@@ -155,8 +155,8 @@
if(!result)
{
- ::syslog(LOG_ERR, "Failed to CreateProcess: '%s': "
- "error %d", CommandLine, GetLastError());
+ BOX_ERROR("Failed to CreateProcess: '" << CommandLine <<
+ "': " << GetErrorMessage(GetLastError()));
CloseHandle(writeInChild);
CloseHandle(readFromChild);
THROW_EXCEPTION(ServerException, ServerForkError)
Modified: box/chris/general/lib/server/SSLLib.cpp
===================================================================
--- box/chris/general/lib/server/SSLLib.cpp 2007-07-31 23:18:05 UTC (rev 1783)
+++ box/chris/general/lib/server/SSLLib.cpp 2007-07-31 23:18:50 UTC (rev 1784)
@@ -14,10 +14,6 @@
#include <openssl/err.h>
#include <openssl/rand.h>
-#ifndef WIN32
-#include <syslog.h>
-#endif
-
#include "SSLLib.h"
#include "ServerException.h"
@@ -73,13 +69,8 @@
while((errcode = ERR_get_error()) != 0)
{
::ERR_error_string_n(errcode, errname, sizeof(errname));
- #ifndef NDEBUG
- if(SSLLib__TraceErrors)
- {
- TRACE2("SSL err during %s: %s\n", ErrorDuringAction, errname);
- }
- #endif
- ::syslog(LOG_ERR, "SSL err during %s: %s", ErrorDuringAction, errname);
+ BOX_ERROR("SSL error during " << ErrorDuringAction << ": " <<
+ errname);
}
}
Modified: box/chris/general/lib/server/ServerStream.h
===================================================================
--- box/chris/general/lib/server/ServerStream.h 2007-07-31 23:18:05 UTC (rev 1783)
+++ box/chris/general/lib/server/ServerStream.h 2007-07-31 23:18:50 UTC (rev 1784)
@@ -14,7 +14,6 @@
#include <errno.h>
#ifndef WIN32
- #include <syslog.h>
#include <sys/wait.h>
#endif
@@ -73,7 +72,10 @@
{
if(childExit)
{
- ::syslog(LOG_ERR, "in server child, exception %s (%d/%d) -- terminating child", e.what(), e.GetType(), e.GetSubType());
+ BOX_ERROR("Error in child process, "
+ "terminating connection: exception " <<
+ e.what() << "(" << e.GetType() <<
+ "/" << e.GetSubType() << ")");
_exit(1);
}
else throw;
@@ -82,7 +84,9 @@
{
if(childExit)
{
- ::syslog(LOG_ERR, "in server child, exception %s -- terminating child", e.what());
+ BOX_ERROR("Error in child process, "
+ "terminating connection: exception " <<
+ e.what());
_exit(1);
}
else throw;
@@ -91,7 +95,9 @@
{
if(childExit)
{
- ::syslog(LOG_ERR, "in server child, unknown exception -- terminating child");
+ BOX_ERROR("Error in child process, "
+ "terminating connection: "
+ "unknown exception");
_exit(1);
}
else throw;
@@ -266,7 +272,7 @@
}
// Log it
- ::syslog(LOG_INFO, "%s (handling in child %d)", logMessage.c_str(), pid);
+ BOX_WARNING("Error message from child process " << pid << ": " << logMessage);
}
else
{
Modified: box/chris/general/lib/server/Socket.cpp
===================================================================
--- box/chris/general/lib/server/Socket.cpp 2007-07-31 23:18:05 UTC (rev 1783)
+++ box/chris/general/lib/server/Socket.cpp 2007-07-31 23:18:50 UTC (rev 1784)
@@ -17,7 +17,6 @@
#ifndef WIN32
#include <sys/socket.h>
#include <netdb.h>
-#include <syslog.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#endif
@@ -124,18 +123,20 @@
switch(addr->sa_family)
{
case AF_UNIX:
- ::syslog(LOG_INFO, "Incoming connection from local (UNIX socket)");
+ BOX_INFO("Incoming connection from local (UNIX socket)");
break;
case AF_INET:
{
sockaddr_in *a = (sockaddr_in*)addr;
- ::syslog(LOG_INFO, "Incoming connection from %s port %d", inet_ntoa(a->sin_addr), ntohs(a->sin_port));
+ BOX_INFO("Incoming connection from " <<
+ inet_ntoa(a->sin_addr) << " port " <<
+ ntohs(a->sin_port));
}
break;
default:
- ::syslog(LOG_INFO, "Incoming connection of unknown type");
+ BOX_WARNING("Incoming connection of unknown type");
break;
}
}
Modified: box/chris/general/lib/server/WinNamedPipeStream.cpp
===================================================================
--- box/chris/general/lib/server/WinNamedPipeStream.cpp 2007-07-31 23:18:05 UTC (rev 1783)
+++ box/chris/general/lib/server/WinNamedPipeStream.cpp 2007-07-31 23:18:50 UTC (rev 1784)
@@ -63,8 +63,8 @@
}
catch (std::exception &e)
{
- ::syslog(LOG_ERR, "Caught exception while destroying "
- "named pipe, ignored.");
+ BOX_ERROR("Caught exception while destroying "
+ "named pipe, ignored: " << e.what());
}
}
}
@@ -100,8 +100,8 @@
if (mSocketHandle == INVALID_HANDLE_VALUE)
{
- ::syslog(LOG_ERR, "CreateNamedPipeW failed: %s",
- GetErrorMessage(GetLastError()).c_str());
+ BOX_ERROR("Failed to CreateNamedPipeW(" << pName << "): " <<
+ GetErrorMessage(GetLastError()));
THROW_EXCEPTION(ServerException, SocketOpenError)
}
@@ -109,8 +109,8 @@
if (!connected)
{
- ::syslog(LOG_ERR, "ConnectNamedPipe failed: %s",
- GetErrorMessage(GetLastError()).c_str());
+ BOX_ERROR("Failed to ConnectNamedPipe(" << pName << "): " <<
+ GetErrorMessage(GetLastError()));
Close();
THROW_EXCEPTION(ServerException, SocketOpenError)
}
@@ -126,8 +126,8 @@
if (mReadableEvent == INVALID_HANDLE_VALUE)
{
- ::syslog(LOG_ERR, "Failed to create the Readable event: %s",
- GetErrorMessage(GetLastError()).c_str());
+ BOX_ERROR("Failed to create the Readable event: " <<
+ GetErrorMessage(GetLastError()));
Close();
THROW_EXCEPTION(CommonException, Internal)
}
@@ -144,8 +144,8 @@
if (err != ERROR_IO_PENDING)
{
- ::syslog(LOG_ERR, "Failed to start overlapped read: "
- "%s", GetErrorMessage(err).c_str());
+ BOX_ERROR("Failed to start overlapped read: " <<
+ GetErrorMessage(err));
Close();
THROW_EXCEPTION(ConnectionException,
Conn_SocketReadError)
@@ -183,13 +183,13 @@
DWORD err = GetLastError();
if (err == ERROR_PIPE_BUSY)
{
- ::syslog(LOG_ERR, "Failed to connect to backup "
- "daemon: it is busy with another connection");
+ BOX_ERROR("Failed to connect to backup daemon: "
+ "it is busy with another connection");
}
else
{
- ::syslog(LOG_ERR, "Failed to connect to backup "
- "daemon: %s", GetErrorMessage(err).c_str());
+ BOX_ERROR("Failed to connect to backup daemon: " <<
+ GetErrorMessage(err));
}
THROW_EXCEPTION(ServerException, SocketOpenError)
}
@@ -261,16 +261,14 @@
{
if (err == ERROR_BROKEN_PIPE)
{
- ::syslog(LOG_ERR, "Control "
- "client disconnected");
+ BOX_ERROR("Control client "
+ "disconnected");
}
else
{
- ::syslog(LOG_ERR,
- "Failed to wait for "
+ BOX_ERROR("Failed to wait for "
"ReadFile to complete: "
- "%s",
- GetErrorMessage(err).c_str());
+ << GetErrorMessage(err));
}
Close();
@@ -326,15 +324,13 @@
}
else if (err == ERROR_BROKEN_PIPE)
{
- ::syslog(LOG_ERR,
- "Control client disconnected");
+ BOX_ERROR("Control client disconnected");
mReadClosed = true;
}
else
{
- ::syslog(LOG_ERR, "Failed to start "
- "overlapped read: %s",
- GetErrorMessage(err).c_str());
+ BOX_ERROR("Failed to start overlapped read: "
+ << GetErrorMessage(err));
Close();
THROW_EXCEPTION(ConnectionException,
Conn_SocketReadError)
@@ -387,9 +383,8 @@
}
else
{
- ::syslog(LOG_ERR, "Failed to read from "
- "control socket: %s",
- GetErrorMessage(err).c_str());
+ BOX_ERROR("Failed to read from control socket: "
+ << GetErrorMessage(err));
THROW_EXCEPTION(ConnectionException,
Conn_SocketReadError)
}
@@ -440,8 +435,8 @@
if (!Success)
{
DWORD err = GetLastError();
- ::syslog(LOG_ERR, "Failed to write to control socket: "
- "%s", GetErrorMessage(err).c_str());
+ BOX_ERROR("Failed to write to control socket: " <<
+ GetErrorMessage(err));
Close();
// ERROR_NO_DATA is a strange name for
@@ -474,8 +469,7 @@
{
if (mSocketHandle == INVALID_HANDLE_VALUE && mIsConnected)
{
- fprintf(stderr, "Inconsistent connected state\n");
- ::syslog(LOG_ERR, "Inconsistent connected state");
+ BOX_ERROR("Named pipe: inconsistent connected state");
mIsConnected = false;
}
@@ -488,29 +482,27 @@
{
if (!CancelIo(mSocketHandle))
{
- ::syslog(LOG_ERR, "Failed to cancel outstanding "
- "I/O: %s",
- GetErrorMessage(GetLastError()).c_str());
+ BOX_ERROR("Failed to cancel outstanding I/O: " <<
+ GetErrorMessage(GetLastError()));
}
if (mReadableEvent == INVALID_HANDLE_VALUE)
{
- ::syslog(LOG_ERR, "Failed to destroy Readable "
- "event: invalid handle");
+ BOX_ERROR("Failed to destroy Readable event: "
+ "invalid handle");
}
else if (!CloseHandle(mReadableEvent))
{
- ::syslog(LOG_ERR, "Failed to destroy Readable "
- "event: %s",
- GetErrorMessage(GetLastError()).c_str());
+ BOX_ERROR("Failed to destroy Readable event: " <<
+ GetErrorMessage(GetLastError()));
}
mReadableEvent = INVALID_HANDLE_VALUE;
if (!FlushFileBuffers(mSocketHandle))
{
- ::syslog(LOG_INFO, "FlushFileBuffers failed: %s",
- GetErrorMessage(GetLastError()).c_str());
+ BOX_ERROR("Failed to FlushFileBuffers: " <<
+ GetErrorMessage(GetLastError()));
}
if (!DisconnectNamedPipe(mSocketHandle))
@@ -518,9 +510,8 @@
DWORD err = GetLastError();
if (err != ERROR_PIPE_NOT_CONNECTED)
{
- ::syslog(LOG_ERR, "DisconnectNamedPipe "
- "failed: %s",
- GetErrorMessage(err).c_str());
+ BOX_ERROR("Failed to DisconnectNamedPipe: " <<
+ GetErrorMessage(err));
}
}
@@ -536,8 +527,8 @@
if (!result)
{
- ::syslog(LOG_ERR, "CloseHandle failed: %s",
- GetErrorMessage(GetLastError()).c_str());
+ BOX_ERROR("Failed to CloseHandle: " <<
+ GetErrorMessage(GetLastError()));
THROW_EXCEPTION(ServerException, SocketCloseError)
}
}
@@ -585,8 +576,8 @@
if (!FlushFileBuffers(mSocketHandle))
{
- ::syslog(LOG_WARNING, "FlushFileBuffers failed: %s",
- GetErrorMessage(GetLastError()).c_str());
+ BOX_ERROR("Failed to FlushFileBuffers: " <<
+ GetErrorMessage(GetLastError()));
}
}
More information about the Boxbackup-commit
mailing list