From 0b2fd98dd63c533e00c0d61ce022f37ee75857cc Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Tue, 31 Jul 2007 23:18:05 +0000 Subject: Replace almost all calls to syslog() with logging framework. (refs #3) --- bin/bbackupctl/bbackupctl.cpp | 33 ++--- bin/bbackupd/BackupClientContext.cpp | 16 +-- bin/bbackupd/Win32ServiceFunctions.cpp | 53 +++---- bin/bbackupquery/BackupQueries.cpp | 9 +- bin/bbstored/BBStoreDHousekeeping.cpp | 33 +++-- bin/bbstored/BackupCommands.cpp | 65 ++++++--- bin/bbstored/BackupStoreDaemon.cpp | 28 ++-- bin/bbstored/HousekeepStoreAccount.cpp | 59 ++++++-- lib/backupclient/BackupClientFileAttributes.cpp | 13 +- lib/backupclient/BackupClientRestore.cpp | 184 +++++++++--------------- lib/backupclient/BackupStoreFile.cpp | 7 +- lib/common/BoxTime.cpp | 9 +- lib/common/DebugPrintf.cpp | 6 - lib/common/Logging.h | 14 ++ lib/raidfile/RaidFileRead.cpp | 41 +++--- lib/server/Daemon.cpp | 7 +- lib/server/LocalProcessStream.cpp | 8 +- lib/server/SSLLib.cpp | 13 +- lib/server/ServerStream.h | 16 ++- lib/server/Socket.cpp | 9 +- lib/server/WinNamedPipeStream.cpp | 89 ++++++------ 21 files changed, 349 insertions(+), 363 deletions(-) diff --git a/bin/bbackupctl/bbackupctl.cpp b/bin/bbackupctl/bbackupctl.cpp index f0a966c4..a5dc4c10 100644 --- a/bin/bbackupctl/bbackupctl.cpp +++ b/bin/bbackupctl/bbackupctl.cpp @@ -162,7 +162,7 @@ int main(int argc, const char *argv[]) ); #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 @@ int main(int argc, const char *argv[]) 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 @@ int main(int argc, const char *argv[]) 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 main(int argc, const char *argv[]) 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 @@ int main(int argc, const char *argv[]) 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; } diff --git a/bin/bbackupd/BackupClientContext.cpp b/bin/bbackupd/BackupClientContext.cpp index 18859393..4b4efd90 100644 --- a/bin/bbackupd/BackupClientContext.cpp +++ b/bin/bbackupd/BackupClientContext.cpp @@ -9,12 +9,10 @@ #include "Box.h" -#ifdef HAVE_SYSLOG_H - #include -#endif #ifdef HAVE_SIGNAL_H #include #endif + #ifdef HAVE_SYS_TIME_H #include #endif @@ -127,7 +125,8 @@ BackupProtocolClient &BackupClientContext::GetConnection() } // 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 @@ BackupProtocolClient &BackupClientContext::GetConnection() 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 @@ BackupProtocolClient &BackupClientContext::GetConnection() } // 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 @@ BackupProtocolClient &BackupClientContext::GetConnection() // 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(...) diff --git a/bin/bbackupd/Win32ServiceFunctions.cpp b/bin/bbackupd/Win32ServiceFunctions.cpp index 3010cf3f..f4c8894b 100644 --- a/bin/bbackupd/Win32ServiceFunctions.cpp +++ b/bin/bbackupd/Win32ServiceFunctions.cpp @@ -44,7 +44,7 @@ void ErrorHandler(char *s, DWORD err) 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 @@ int InstallService(const char* pConfigFileName) 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 @@ int InstallService(const char* pConfigFileName) 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 @@ int InstallService(const char* pConfigFileName) { 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 @@ int InstallService(const char* pConfigFileName) 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 @@ int InstallService(const char* pConfigFileName) 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 @@ int RemoveService(void) 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 @@ int RemoveService(void) 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 @@ int RemoveService(void) 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 @@ int RemoveService(void) 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; diff --git a/bin/bbackupquery/BackupQueries.cpp b/bin/bbackupquery/BackupQueries.cpp index 7f511b74..0c5f9c15 100644 --- a/bin/bbackupquery/BackupQueries.cpp +++ b/bin/bbackupquery/BackupQueries.cpp @@ -2009,19 +2009,14 @@ void BackupQueries::CommandRestore(const std::vector &args, const b 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; } diff --git a/bin/bbstored/BBStoreDHousekeeping.cpp b/bin/bbstored/BBStoreDHousekeeping.cpp index a4b26a93..16a1432a 100644 --- a/bin/bbstored/BBStoreDHousekeeping.cpp +++ b/bin/bbstored/BBStoreDHousekeeping.cpp @@ -11,10 +11,6 @@ #include -#ifdef HAVE_SYSLOG_H - #include -#endif - #include "BackupStoreDaemon.h" #include "BackupStoreAccountDatabase.h" #include "BackupStoreAccounts.h" @@ -82,7 +78,7 @@ void BackupStoreDaemon::RunHousekeepingIfNeeded() // Store the time mLastHousekeepingRun = timeNow; - ::syslog(LOG_INFO, "Starting housekeeping"); + BOX_INFO("Starting housekeeping"); // Get the list of accounts std::vector accounts; @@ -112,18 +108,25 @@ void BackupStoreDaemon::RunHousekeepingIfNeeded() } 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 @@ void BackupStoreDaemon::RunHousekeepingIfNeeded() } } - ::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 @@ bool BackupStoreDaemon::CheckForInterProcessMsg(int AccountNum, int MaximumWaitT 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 @@ bool BackupStoreDaemon::CheckForInterProcessMsg(int AccountNum, int MaximumWaitT 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; } } diff --git a/bin/bbstored/BackupCommands.cpp b/bin/bbstored/BackupCommands.cpp index fd19713d..bca52c04 100644 --- a/bin/bbstored/BackupCommands.cpp +++ b/bin/bbstored/BackupCommands.cpp @@ -9,10 +9,6 @@ #include "Box.h" -#ifdef HAVE_SYSLOG_H -#include -#endif - #include #include @@ -88,11 +84,26 @@ std::auto_ptr BackupProtocolServerLogin::DoCommand(BackupProtoco // 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(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( + 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( + new BackupProtocolServerError( + BackupProtocolServerError::ErrorType, + BackupProtocolServerError::Err_BadLogin)); } // If we need to write, check that nothing else has got a write lock @@ -101,9 +112,12 @@ std::auto_ptr BackupProtocolServerLogin::DoCommand(BackupProtoco // 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(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( + new BackupProtocolServerError( + BackupProtocolServerError::ErrorType, + BackupProtocolServerError::Err_CannotLockStoreForWriting)); } // Debug: check we got the lock @@ -120,7 +134,11 @@ std::auto_ptr BackupProtocolServerLogin::DoCommand(BackupProtoco 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 BackupProtocolServerLogin::DoCommand(BackupProtoco // -------------------------------------------------------------------------- std::auto_ptr 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 @@ std::auto_ptr BackupProtocolServerGetFile::DoCommand(BackupProto 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(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( + 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 diff --git a/bin/bbstored/BackupStoreDaemon.cpp b/bin/bbstored/BackupStoreDaemon.cpp index 049c0ae4..c5d5fe40 100644 --- a/bin/bbstored/BackupStoreDaemon.cpp +++ b/bin/bbstored/BackupStoreDaemon.cpp @@ -208,7 +208,7 @@ void BackupStoreDaemon::Run() // 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 @@ void BackupStoreDaemon::Connection(SocketStreamTLS &rStream) } 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 @@ void BackupStoreDaemon::Connection2(SocketStreamTLS &rStream) 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 @@ void BackupStoreDaemon::LogConnectionStats(const char *commonName, 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())); } diff --git a/bin/bbstored/HousekeepStoreAccount.cpp b/bin/bbstored/HousekeepStoreAccount.cpp index 8d2d9e4c..9f4239e7 100644 --- a/bin/bbstored/HousekeepStoreAccount.cpp +++ b/bin/bbstored/HousekeepStoreAccount.cpp @@ -9,9 +9,10 @@ #include "Box.h" -#include #include +#include + #include "HousekeepStoreAccount.h" #include "BackupStoreDaemon.h" #include "StoreStructure.h" @@ -137,11 +138,18 @@ void HousekeepStoreAccount::DoHousekeeping() || (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 @@ void HousekeepStoreAccount::DoHousekeeping() // 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 @@ void HousekeepStoreAccount::DeleteFile(int64_t InDirectory, int64_t ObjectID, Ba 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 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 fix"); return; } diff --git a/lib/backupclient/BackupClientFileAttributes.cpp b/lib/backupclient/BackupClientFileAttributes.cpp index 9918c0d6..925d1620 100644 --- a/lib/backupclient/BackupClientFileAttributes.cpp +++ b/lib/backupclient/BackupClientFileAttributes.cpp @@ -344,8 +344,8 @@ void BackupClientFileAttributes::ReadAttributes(const char *Filename, bool ZeroM // 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 @@ void BackupClientFileAttributes::ReadAttributes(const char *Filename, bool ZeroM 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 @@ void BackupClientFileAttributes::WriteAttributes(const char *Filename, } #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); diff --git a/lib/backupclient/BackupClientRestore.cpp b/lib/backupclient/BackupClientRestore.cpp index 9b3a3edc..92853624 100644 --- a/lib/backupclient/BackupClientRestore.cpp +++ b/lib/backupclient/BackupClientRestore.cpp @@ -235,20 +235,20 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir } 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 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir ::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 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir } 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 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir 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 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir 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 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir { 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 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir { 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 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir // 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 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir 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 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir 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 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir { 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 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir 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 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir { 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; } diff --git a/lib/backupclient/BackupStoreFile.cpp b/lib/backupclient/BackupStoreFile.cpp index 75095fa4..7e93d59d 100644 --- a/lib/backupclient/BackupStoreFile.cpp +++ b/lib/backupclient/BackupStoreFile.cpp @@ -17,10 +17,8 @@ #include #include #include + #ifndef BOX_DISABLE_BACKWARDS_COMPATIBILITY_BACKUPSTOREFILE - #ifndef WIN32 - #include - #endif #include #endif @@ -758,8 +756,7 @@ int BackupStoreFile::DecodedStream::Read(void *pBuffer, int NBytes, int Timeout) // 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; } } diff --git a/lib/common/BoxTime.cpp b/lib/common/BoxTime.cpp index eafb244f..1ddcffd4 100644 --- a/lib/common/BoxTime.cpp +++ b/lib/common/BoxTime.cpp @@ -12,12 +12,11 @@ #ifdef HAVE_SYS_TIME_H #include #endif + #ifdef HAVE_TIME_H #include #endif -#ifdef HAVE_SYSLOG_H - #include -#endif + #include #include @@ -40,8 +39,8 @@ box_time_t GetCurrentBoxTime() 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 { diff --git a/lib/common/DebugPrintf.cpp b/lib/common/DebugPrintf.cpp index 8d75f458..14cd3534 100644 --- a/lib/common/DebugPrintf.cpp +++ b/lib/common/DebugPrintf.cpp @@ -14,12 +14,6 @@ #include #include -#ifdef WIN32 - #include "emu.h" -#else - #include -#endif - #include "MemLeakFindOn.h" // Use this apparently superflous printf function to avoid having to diff --git a/lib/common/Logging.h b/lib/common/Logging.h index aea488a5..e87d1d4f 100644 --- a/lib/common/Logging.h +++ b/lib/common/Logging.h @@ -10,6 +10,7 @@ #ifndef LOGGING__H #define LOGGING__H +#include #include #include @@ -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 diff --git a/lib/raidfile/RaidFileRead.cpp b/lib/raidfile/RaidFileRead.cpp index 58aecfb1..187270f9 100644 --- a/lib/raidfile/RaidFileRead.cpp +++ b/lib/raidfile/RaidFileRead.cpp @@ -21,10 +21,6 @@ #include #endif -#ifdef HAVE_SYSLOG_H - #include -#endif - #ifdef HAVE_DIRENT_H #include #endif @@ -548,8 +544,8 @@ void RaidFileRead_Raid::MoveDamagedFileAlertDaemon(int SetNumber, const std::str // -------------------------------------------------------------------------- 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 @@ void RaidFileRead_Raid::SetPosition(pos_type FilePosition) { 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 @@ void RaidFileRead_Raid::SetPosition(pos_type FilePosition) { 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 @@ std::auto_ptr RaidFileRead::Open(int SetNumber, const std::string { 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 @@ std::auto_ptr RaidFileRead::Open(int SetNumber, const std::string 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 @@ std::auto_ptr RaidFileRead::Open(int SetNumber, const std::string 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 @@ std::auto_ptr RaidFileRead::Open(int SetNumber, const std::string 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)); diff --git a/lib/server/Daemon.cpp b/lib/server/Daemon.cpp index 147eeb24..a9eb5bf5 100644 --- a/lib/server/Daemon.cpp +++ b/lib/server/Daemon.cpp @@ -19,10 +19,6 @@ #include #include -#ifdef HAVE_SYSLOG_H - #include -#endif - #ifdef WIN32 #include #endif @@ -353,7 +349,8 @@ int Daemon::Main(const std::string &rConfigFileName) // Set new session if(::setsid() == -1) { - ::syslog(LOG_ERR, "can't setsid"); + BOX_ERROR("Failed to setsid(): " << + strerror(errno)); THROW_EXCEPTION(ServerException, DaemoniseFailed) } diff --git a/lib/server/LocalProcessStream.cpp b/lib/server/LocalProcessStream.cpp index fef7166b..9750aca1 100644 --- a/lib/server/LocalProcessStream.cpp +++ b/lib/server/LocalProcessStream.cpp @@ -120,8 +120,8 @@ std::auto_ptr LocalProcessStream(const char *CommandLine, pid_t &rPidO 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 @@ std::auto_ptr LocalProcessStream(const char *CommandLine, pid_t &rPidO 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) diff --git a/lib/server/SSLLib.cpp b/lib/server/SSLLib.cpp index 2a5bdbde..6082a9f4 100644 --- a/lib/server/SSLLib.cpp +++ b/lib/server/SSLLib.cpp @@ -14,10 +14,6 @@ #include #include -#ifndef WIN32 -#include -#endif - #include "SSLLib.h" #include "ServerException.h" @@ -73,13 +69,8 @@ void SSLLib::LogError(const char *ErrorDuringAction) 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); } } diff --git a/lib/server/ServerStream.h b/lib/server/ServerStream.h index 7eb99d13..5f615336 100644 --- a/lib/server/ServerStream.h +++ b/lib/server/ServerStream.h @@ -14,7 +14,6 @@ #include #ifndef WIN32 - #include #include #endif @@ -73,7 +72,10 @@ public: { 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 @@ public: { 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 @@ public: { 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 @@ public: } // Log it - ::syslog(LOG_INFO, "%s (handling in child %d)", logMessage.c_str(), pid); + BOX_WARNING("Error message from child process " << pid << ": " << logMessage); } else { diff --git a/lib/server/Socket.cpp b/lib/server/Socket.cpp index afed4888..28dae69f 100644 --- a/lib/server/Socket.cpp +++ b/lib/server/Socket.cpp @@ -17,7 +17,6 @@ #ifndef WIN32 #include #include -#include #include #include #endif @@ -124,18 +123,20 @@ void Socket::LogIncomingConnection(const struct sockaddr *addr, socklen_t addrle 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; } } diff --git a/lib/server/WinNamedPipeStream.cpp b/lib/server/WinNamedPipeStream.cpp index 32ae42f2..d7e90793 100644 --- a/lib/server/WinNamedPipeStream.cpp +++ b/lib/server/WinNamedPipeStream.cpp @@ -63,8 +63,8 @@ WinNamedPipeStream::~WinNamedPipeStream() } 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 @@ void WinNamedPipeStream::Accept(const wchar_t* pName) 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 @@ void WinNamedPipeStream::Accept(const wchar_t* pName) 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 @@ void WinNamedPipeStream::Accept(const wchar_t* pName) 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 @@ void WinNamedPipeStream::Accept(const wchar_t* pName) 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 @@ void WinNamedPipeStream::Connect(const wchar_t* pName) 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 @@ int WinNamedPipeStream::Read(void *pBuffer, int NBytes, int Timeout) { 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 @@ int WinNamedPipeStream::Read(void *pBuffer, int NBytes, int Timeout) } 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 @@ int WinNamedPipeStream::Read(void *pBuffer, int NBytes, int Timeout) } 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 @@ void WinNamedPipeStream::Write(const void *pBuffer, int NBytes) 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 @@ void WinNamedPipeStream::Close() { 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 @@ void WinNamedPipeStream::Close() { 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 @@ void WinNamedPipeStream::Close() 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 @@ void WinNamedPipeStream::Close() 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 @@ void WinNamedPipeStream::WriteAllBuffered() if (!FlushFileBuffers(mSocketHandle)) { - ::syslog(LOG_WARNING, "FlushFileBuffers failed: %s", - GetErrorMessage(GetLastError()).c_str()); + BOX_ERROR("Failed to FlushFileBuffers: " << + GetErrorMessage(GetLastError())); } } -- cgit v1.2.3