From 3661f3624acc46590d5504fda4f8714255fb2c8e Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 4 Apr 2008 21:59:29 +0000 Subject: Tailorization Import of the upstream sources from Repository: http://localhost:8000/ Kind: hg Revision: 7807b7768163f1c2537756abe5416063989cebb1 Original author: tailor@rocio.int.aidworld.org Date: 2008-03-16 19:44:36+00:00 --- lib/backupclient/BackupClientRestore.cpp | 36 ++--- lib/backupclient/BackupDaemonConfigVerify.cpp | 89 +++++------ lib/backupclient/BackupStoreFileDiff.cpp | 36 ++--- lib/backupclient/BackupStoreFilenameClear.cpp | 6 +- lib/backupclient/BackupStoreObjectDump.cpp | 10 +- lib/backupstore/BackupStoreCheck.cpp | 3 +- lib/backupstore/BackupStoreCheck2.cpp | 35 +---- lib/backupstore/BackupStoreCheckData.cpp | 13 +- lib/backupstore/BackupStoreConfigVerify.cpp | 17 +-- lib/common/Box.h | 19 +++ lib/common/BoxTime.cpp | 4 +- lib/common/Configuration.cpp | 208 +++++++------------------- lib/common/Configuration.h | 55 ++----- lib/common/DebugMemLeakFinder.cpp | 19 +-- lib/common/EventWatchFilesystemObject.cpp | 43 +++--- lib/common/FileStream.cpp | 25 ++-- lib/common/FileStream.h | 4 +- lib/common/Guards.h | 4 +- lib/common/Logging.h | 33 +--- lib/common/PartialReadStream.cpp | 3 +- lib/common/Utils.cpp | 63 +------- lib/common/Utils.h | 3 - lib/compress/Compress.h | 8 +- lib/compress/CompressStream.cpp | 2 +- lib/crypto/CipherContext.cpp | 12 +- lib/intercept/intercept.cpp | 10 +- lib/raidfile/RaidFileController.cpp | 13 +- lib/raidfile/RaidFileWrite.cpp | 8 +- lib/server/Daemon.cpp | 16 +- lib/server/Daemon.h | 5 +- lib/server/ProtocolUncertainStream.cpp | 3 +- lib/server/ServerControl.h | 3 +- lib/server/ServerStream.h | 6 +- lib/server/ServerTLS.h | 9 +- lib/server/SocketListen.h | 83 ++++------ lib/server/SocketStream.cpp | 56 +++---- 36 files changed, 321 insertions(+), 641 deletions(-) (limited to 'lib') diff --git a/lib/backupclient/BackupClientRestore.cpp b/lib/backupclient/BackupClientRestore.cpp index aab514ad..b5a54964 100644 --- a/lib/backupclient/BackupClientRestore.cpp +++ b/lib/backupclient/BackupClientRestore.cpp @@ -267,14 +267,14 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir "restore this object."); if(::unlink(rLocalDirectoryName.c_str()) != 0) { - BOX_LOG_SYS_ERROR("Failed to delete " - "file '" << - rLocalDirectoryName << "'"); + BOX_ERROR("Failed to delete file " << + rLocalDirectoryName << ": " << + strerror(errno)); return Restore_UnknownError; } BOX_TRACE("In restore, directory name " - "collision with file '" << - rLocalDirectoryName << "'"); + "collision with file " << + rLocalDirectoryName); } break; case ObjectExists_NoObject: @@ -378,8 +378,9 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir exists == ObjectExists_File) && ::mkdir(rLocalDirectoryName.c_str(), S_IRWXU) != 0) { - BOX_LOG_SYS_ERROR("Failed to create directory '" << - rLocalDirectoryName << "'"); + BOX_ERROR("Failed to create directory '" << + rLocalDirectoryName << "': " << + strerror(errno)); return Restore_UnknownError; } @@ -450,9 +451,7 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir { // Local name BackupStoreFilenameClear nm(en->GetName()); - std::string localFilename(rLocalDirectoryName + - DIRECTORY_SEPARATOR_ASCHAR + - nm.GetClearFilename()); + std::string localFilename(rLocalDirectoryName + DIRECTORY_SEPARATOR_ASCHAR + nm.GetClearFilename()); // Unlink anything which already exists: // For resuming restores, we can't overwrite @@ -460,23 +459,20 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir if(ObjectExists(localFilename) != ObjectExists_NoObject && ::unlink(localFilename.c_str()) != 0) { - BOX_LOG_SYS_ERROR("Failed to delete " - "file '" << localFilename << - "'"); + BOX_ERROR("Failed to delete file '" << + localFilename << "': " << + strerror(errno)); return Restore_UnknownError; } // Request it from the store - rConnection.QueryGetFile(DirectoryID, - en->GetObjectID()); + rConnection.QueryGetFile(DirectoryID, en->GetObjectID()); // Stream containing encoded file - std::auto_ptr objectStream( - rConnection.ReceiveStream()); + std::auto_ptr objectStream(rConnection.ReceiveStream()); - // Decode the file -- need to do different - // things depending on whether the directory - // entry has additional attributes + // Decode the file -- need to do different things depending on whether + // the directory entry has additional attributes try { if(en->HasAttributes()) diff --git a/lib/backupclient/BackupDaemonConfigVerify.cpp b/lib/backupclient/BackupDaemonConfigVerify.cpp index db1de4fa..61033b5b 100644 --- a/lib/backupclient/BackupDaemonConfigVerify.cpp +++ b/lib/backupclient/BackupDaemonConfigVerify.cpp @@ -17,15 +17,15 @@ static const ConfigurationVerifyKey backuplocationkeys[] = { - ConfigurationVerifyKey("ExcludeFile", ConfigTest_MultiValueAllowed), - ConfigurationVerifyKey("ExcludeFilesRegex", ConfigTest_MultiValueAllowed), - ConfigurationVerifyKey("ExcludeDir", ConfigTest_MultiValueAllowed), - ConfigurationVerifyKey("ExcludeDirsRegex", ConfigTest_MultiValueAllowed), - ConfigurationVerifyKey("AlwaysIncludeFile", ConfigTest_MultiValueAllowed), - ConfigurationVerifyKey("AlwaysIncludeFilesRegex", ConfigTest_MultiValueAllowed), - ConfigurationVerifyKey("AlwaysIncludeDir", ConfigTest_MultiValueAllowed), - ConfigurationVerifyKey("AlwaysIncludeDirsRegex", ConfigTest_MultiValueAllowed), - ConfigurationVerifyKey("Path", ConfigTest_Exists | ConfigTest_LastEntry) + {"ExcludeFile", 0, ConfigTest_MultiValueAllowed, 0}, + {"ExcludeFilesRegex", 0, ConfigTest_MultiValueAllowed, 0}, + {"ExcludeDir", 0, ConfigTest_MultiValueAllowed, 0}, + {"ExcludeDirsRegex", 0, ConfigTest_MultiValueAllowed, 0}, + {"AlwaysIncludeFile", 0, ConfigTest_MultiValueAllowed, 0}, + {"AlwaysIncludeFilesRegex", 0, ConfigTest_MultiValueAllowed, 0}, + {"AlwaysIncludeDir", 0, ConfigTest_MultiValueAllowed, 0}, + {"AlwaysIncludeDirsRegex", 0, ConfigTest_MultiValueAllowed, 0}, + {"Path", 0, ConfigTest_Exists | ConfigTest_LastEntry, 0} }; static const ConfigurationVerify backuplocations[] = @@ -64,54 +64,39 @@ static const ConfigurationVerify verifyserver[] = static const ConfigurationVerifyKey verifyrootkeys[] = { - ConfigurationVerifyKey("AccountNumber", - ConfigTest_Exists | ConfigTest_IsInt), - ConfigurationVerifyKey("UpdateStoreInterval", - ConfigTest_Exists | ConfigTest_IsInt), - ConfigurationVerifyKey("MinimumFileAge", - ConfigTest_Exists | ConfigTest_IsInt), - ConfigurationVerifyKey("MaxUploadWait", - ConfigTest_Exists | ConfigTest_IsInt), - ConfigurationVerifyKey("MaxFileTimeInFuture", ConfigTest_IsInt, 172800), - // file is uploaded if the file is this much in the future - // (2 days default) - ConfigurationVerifyKey("AutomaticBackup", ConfigTest_IsBool, true), + {"AccountNumber", 0, ConfigTest_Exists | ConfigTest_IsInt, 0}, + + {"UpdateStoreInterval", 0, ConfigTest_Exists | ConfigTest_IsInt, 0}, + {"MinimumFileAge", 0, ConfigTest_Exists | ConfigTest_IsInt, 0}, + {"MaxUploadWait", 0, ConfigTest_Exists | ConfigTest_IsInt, 0}, + {"MaxFileTimeInFuture", "172800", ConfigTest_IsInt, 0}, // file is uploaded if the file is this much in the future (2 days default) + + {"AutomaticBackup", "yes", ConfigTest_IsBool, 0}, - ConfigurationVerifyKey("SyncAllowScript", 0), - // script that returns "now" if backup is allowed now, or a number - // of seconds to wait before trying again if not + {"SyncAllowScript", 0, 0, 0}, // optional script to run to see if the sync should be started now + // return "now" if it's allowed, or a number of seconds if it's not + + {"MaximumDiffingTime", 0, ConfigTest_IsInt, 0}, + {"DeleteRedundantLocationsAfter", "172800", ConfigTest_IsInt, 0}, - ConfigurationVerifyKey("MaximumDiffingTime", ConfigTest_IsInt), - ConfigurationVerifyKey("DeleteRedundantLocationsAfter", - ConfigTest_IsInt, 172800), + {"FileTrackingSizeThreshold", 0, ConfigTest_Exists | ConfigTest_IsInt, 0}, + {"DiffingUploadSizeThreshold", 0, ConfigTest_Exists | ConfigTest_IsInt, 0}, + {"StoreHostname", 0, ConfigTest_Exists, 0}, + {"ExtendedLogging", "no", ConfigTest_IsBool, 0}, // extended log to syslog + {"ExtendedLogFile", NULL, 0, 0}, // extended log to a file + {"LogAllFileAccess", "no", ConfigTest_IsBool, 0}, - ConfigurationVerifyKey("FileTrackingSizeThreshold", - ConfigTest_Exists | ConfigTest_IsInt), - ConfigurationVerifyKey("DiffingUploadSizeThreshold", - ConfigTest_Exists | ConfigTest_IsInt), - ConfigurationVerifyKey("StoreHostname", ConfigTest_Exists), - ConfigurationVerifyKey("StorePort", ConfigTest_IsInt, - BOX_PORT_BBSTORED), - ConfigurationVerifyKey("ExtendedLogging", ConfigTest_IsBool, false), - // extended log to syslog - ConfigurationVerifyKey("ExtendedLogFile", 0), - // extended log to a file - ConfigurationVerifyKey("LogAllFileAccess", ConfigTest_IsBool, false), - ConfigurationVerifyKey("CommandSocket", 0), - // not compulsory to have this - ConfigurationVerifyKey("KeepAliveTime", ConfigTest_IsInt), - ConfigurationVerifyKey("StoreObjectInfoFile", 0), - // optional + {"CommandSocket", 0, 0, 0}, // not compulsory to have this + {"KeepAliveTime", 0, ConfigTest_IsInt, 0}, // optional + {"StoreObjectInfoFile", 0, 0, 0}, // optional - ConfigurationVerifyKey("NotifyScript", 0), - // optional script to run when backup needs attention, eg store full + {"NotifyScript", 0, 0, 0}, // optional script to run when backup needs attention, eg store full - ConfigurationVerifyKey("CertificateFile", ConfigTest_Exists), - ConfigurationVerifyKey("PrivateKeyFile", ConfigTest_Exists), - ConfigurationVerifyKey("TrustedCAsFile", ConfigTest_Exists), - ConfigurationVerifyKey("KeysFile", ConfigTest_Exists), - ConfigurationVerifyKey("DataDirectory", - ConfigTest_Exists | ConfigTest_LastEntry), + {"CertificateFile", 0, ConfigTest_Exists, 0}, + {"PrivateKeyFile", 0, ConfigTest_Exists, 0}, + {"TrustedCAsFile", 0, ConfigTest_Exists, 0}, + {"KeysFile", 0, ConfigTest_Exists, 0}, + {"DataDirectory", 0, ConfigTest_Exists | ConfigTest_LastEntry, 0} }; const ConfigurationVerify BackupDaemonConfigVerify = diff --git a/lib/backupclient/BackupStoreFileDiff.cpp b/lib/backupclient/BackupStoreFileDiff.cpp index d550e2ba..f7842a0b 100644 --- a/lib/backupclient/BackupStoreFileDiff.cpp +++ b/lib/backupclient/BackupStoreFileDiff.cpp @@ -149,7 +149,7 @@ std::auto_ptr BackupStoreFile::EncodeFileDiff int64_t blocksInIndex = 0; bool canDiffFromThis = false; LoadIndex(rDiffFromBlockIndex, DiffFromObjectID, &pindex, blocksInIndex, Timeout, canDiffFromThis); - // BOX_TRACE("Diff: Blocks in index: " << blocksInIndex); + //TRACE1("Diff: Blocks in index: %lld\n", blocksInIndex); if(!canDiffFromThis) { @@ -439,9 +439,7 @@ static void FindMostUsedSizes(BlocksAvailableEntry *pIndex, int64_t NumBlocks, i { for(int t = 0; t < BACKUP_FILE_DIFF_MAX_BLOCK_SIZES; ++t) { - BOX_TRACE("Diff block size " << t << ": " << - Sizes[t] << " (count = " << - sizeCounts[t] << ")"); + TRACE3("Diff block size %d: %d (count = %lld)\n", t, Sizes[t], sizeCounts[t]); } } #endif @@ -776,7 +774,7 @@ static void SetupHashTable(BlocksAvailableEntry *pIndex, int64_t NumBlocks, int3 // Already present in table? if(pHashTable[hash] != 0) { - //BOX_TRACE("Another hash entry for " << hash << " found"); + //TRACE1("Another hash entry for %d found\n", hash); // Yes -- need to set the pointer in this entry to the current entry to build the linked list pIndex[b].mpNextInHashList = pHashTable[hash]; } @@ -842,19 +840,17 @@ static bool SecondStageMatch(BlocksAvailableEntry *pFirstInHashList, RollingChec // Then go through the entries in the hash list, comparing with the strong digest calculated scan = pFirstInHashList; - //BOX_TRACE("second stage match"); + //TRACE0("second stage match\n"); while(scan != 0) { - //BOX_TRACE("scan size " << scan->mSize << - // ", block size " << BlockSize << - // ", hash " << Hash); + //TRACE3("scan size %d, block size %d, hash %d\n", scan->mSize, BlockSize, Hash); ASSERT(scan->mSize == BlockSize); ASSERT(RollingChecksum::ExtractHashingComponent(scan->mWeakChecksum) == DEBUG_Hash); // Compare? if(strong.DigestMatches(scan->mStrongChecksum)) { - //BOX_TRACE("Match!\n"); + //TRACE0("Match!\n"); // Found! Add to list of found blocks... int64_t fileOffset = (FileBlockNumber * BlockSize) + Offset; int64_t blockIndex = (scan - pIndex); // pointer arthmitic is frowned upon. But most efficient way of doing it here -- alternative is to use more memory @@ -916,8 +912,7 @@ static void GenerateRecipe(BackupStoreFileEncodeStream::Recipe &rRecipe, BlocksA #ifndef NDEBUG if(BackupStoreFile::TraceDetailsOfDiffProcess) { - BOX_TRACE("Diff: Default recipe generated, " << - SizeOfInputFile << " bytes of file"); + TRACE1("Diff: Default recipe generated, %lld bytes of file\n", SizeOfInputFile); } #endif @@ -1010,14 +1005,10 @@ static void GenerateRecipe(BackupStoreFileEncodeStream::Recipe &rRecipe, BlocksA // dump out the recipe #ifndef NDEBUG - BOX_TRACE("Diff: " << - debug_NewBytesFound << " new bytes found, " << - debug_OldBlocksUsed << " old blocks used"); + TRACE2("Diff: %lld new bytes found, %lld old blocks used\n", debug_NewBytesFound, debug_OldBlocksUsed); if(BackupStoreFile::TraceDetailsOfDiffProcess) { - BOX_TRACE("Diff: Recipe generated (size " << rRecipe.size()); - BOX_TRACE("======== ========= ========"); - BOX_TRACE("Space b4 FirstBlk NumBlks"); + TRACE1("Diff: Recipe generated (size %d)\n======== ========= ========\nSpace b4 FirstBlk NumBlks\n", rRecipe.size()); { for(unsigned int e = 0; e < rRecipe.size(); ++e) { @@ -1027,15 +1018,10 @@ static void GenerateRecipe(BackupStoreFileEncodeStream::Recipe &rRecipe, BlocksA #else sprintf(b, "%8lld", (int64_t)(rRecipe[e].mpStartBlock - pIndex)); #endif - BOX_TRACE(std::setw(8) << - rRecipe[e].mSpaceBefore << - " " << - ((rRecipe[e].mpStartBlock == 0)?" -":b) << - " " << std::setw(8) << - rRecipe[e].mBlocks); + TRACE3("%8lld %s %8lld\n", rRecipe[e].mSpaceBefore, (rRecipe[e].mpStartBlock == 0)?" -":b, (int64_t)rRecipe[e].mBlocks); } } - BOX_TRACE("======== ========= ========"); + TRACE0("======== ========= ========\n"); } #endif } diff --git a/lib/backupclient/BackupStoreFilenameClear.cpp b/lib/backupclient/BackupStoreFilenameClear.cpp index cf168bfc..9114fdd1 100644 --- a/lib/backupclient/BackupStoreFilenameClear.cpp +++ b/lib/backupclient/BackupStoreFilenameClear.cpp @@ -167,8 +167,7 @@ void BackupStoreFilenameClear::MakeClearAvailable() const switch(encoding) { case Encoding_Clear: - BOX_TRACE("**** BackupStoreFilename encoded with " - "Clear encoding ****"); + TRACE0("**** BackupStoreFilename encoded with Clear encoding ****\n"); mClearFilename.assign(c_str() + 2, size - 2); break; @@ -194,8 +193,7 @@ static void EnsureEncDecBufferSize(int BufSize) if(spEncDecBuffer == 0) { #ifndef WIN32 - BOX_TRACE("Allocating filename encoding/decoding buffer " - "with size " << BufSize); + TRACE1("Allocating filename encoding/decoding buffer with size %d\n", BufSize); #endif spEncDecBuffer = new MemoryBlockGuard(BufSize); MEMLEAKFINDER_NOT_A_LEAK(spEncDecBuffer); diff --git a/lib/backupclient/BackupStoreObjectDump.cpp b/lib/backupclient/BackupStoreObjectDump.cpp index 0ad044bb..d3d9cc17 100644 --- a/lib/backupclient/BackupStoreObjectDump.cpp +++ b/lib/backupclient/BackupStoreObjectDump.cpp @@ -47,7 +47,7 @@ static void OutputLine(FILE *file, bool ToTrace, const char *format, ...) } if(ToTrace) { - BOX_TRACE(text); + TRACE1("%s", text); } } @@ -211,16 +211,14 @@ void BackupStoreFile::DumpFile(void *clibFileHandle, bool ToTrace, IOStream &rFi if(s > 0) { nnew++; - BOX_TRACE(std::setw(8) << b << " this s=" << - std::setw(8) << s); + TRACE2("%8lld this s=%8lld\n", b, s); } else { nold++; - BOX_TRACE(std::setw(8) << b << " other i=" << - std::setw(8) << 0 - s); + TRACE2("%8lld other i=%8lld\n", b, 0 - s); } } - BOX_TRACE("======== ===== =========="); + TRACE0("======== ===== ==========\n"); } diff --git a/lib/backupstore/BackupStoreCheck.cpp b/lib/backupstore/BackupStoreCheck.cpp index 7598094e..176ece8f 100644 --- a/lib/backupstore/BackupStoreCheck.cpp +++ b/lib/backupstore/BackupStoreCheck.cpp @@ -268,8 +268,7 @@ void BackupStoreCheck::CheckObjects() } maxDir = CheckObjectsScanDir(0, 1, mStoreRoot); - BOX_TRACE("Max dir starting ID is " << - BOX_FORMAT_OBJECTID(maxDir)); + TRACE1("Max dir starting ID is %llx\n", maxDir); } // Then go through and scan all the objects within those directories diff --git a/lib/backupstore/BackupStoreCheck2.cpp b/lib/backupstore/BackupStoreCheck2.cpp index 40d34a5b..9c6f2452 100644 --- a/lib/backupstore/BackupStoreCheck2.cpp +++ b/lib/backupstore/BackupStoreCheck2.cpp @@ -594,8 +594,6 @@ void BackupStoreCheck::WriteNewStoreInfo() } } -#define FMT_OID(x) BOX_FORMAT_OBJECTID(x) -#define FMT_i BOX_FORMAT_OBJECTID((*i)->GetObjectID()) // -------------------------------------------------------------------------- // @@ -622,11 +620,7 @@ bool BackupStoreDirectory::CheckAndFix() if(newerEn == 0) { // Depends on something, but it isn't there. - BOX_TRACE("Entry id " << FMT_i << - " removed because depends " - "on newer version " << - FMT_OID(dependsNewer) << - " which doesn't exist"); + TRACE2("Entry id %llx removed because depends on newer version %llx which doesn't exist\n", (*i)->GetObjectID(), dependsNewer); // Remove delete *i; @@ -644,12 +638,7 @@ bool BackupStoreDirectory::CheckAndFix() if(newerEn->GetDependsOlder() != (*i)->GetObjectID()) { // Wrong entry - BOX_TRACE("Entry id " << - FMT_OID(dependsNewer) << - ", correcting DependsOlder to " << - FMT_i << - ", was " << - FMT_OID(newerEn->GetDependsOlder())); + TRACE3("Entry id %llx, correcting DependsOlder to %llx, was %llx\n", dependsNewer, (*i)->GetObjectID(), newerEn->GetDependsOlder()); newerEn->SetDependsOlder((*i)->GetObjectID()); // Mark as changed changed = true; @@ -668,11 +657,7 @@ bool BackupStoreDirectory::CheckAndFix() if(dependsOlder != 0 && FindEntryByID(dependsOlder) == 0) { // Has an older version marked, but this doesn't exist. Remove this mark - BOX_TRACE("Entry id " << FMT_i << - " was marked as depended on by " << - FMT_OID(dependsOlder) << ", " - "which doesn't exist, dependency " - "info cleared"); + TRACE2("Entry id %llx was marked that %llx depended on it, which doesn't exist, dependency info cleared\n", (*i)->GetObjectID(), dependsOlder); (*i)->SetDependsOlder(0); @@ -708,7 +693,7 @@ bool BackupStoreDirectory::CheckAndFix() bool removeEntry = false; if((*i) == 0) { - BOX_TRACE("Remove because null pointer found"); + TRACE0("Remove because null pointer found\n"); removeEntry = true; } else @@ -719,8 +704,7 @@ bool BackupStoreDirectory::CheckAndFix() if(isDir && (((*i)->GetFlags() & Entry::Flags_File) == Entry::Flags_File)) { // Bad! Unset the file flag - BOX_TRACE("Entry " << FMT_i << - ": File flag and dir flag both set"); + TRACE1("Entry %llx: File flag set when dir flag set\n", (*i)->GetObjectID()); (*i)->RemoveFlags(Entry::Flags_File); changed = true; } @@ -729,8 +713,7 @@ bool BackupStoreDirectory::CheckAndFix() if(idsEncountered.find((*i)->GetObjectID()) != idsEncountered.end()) { // ID already seen, or type doesn't match - BOX_TRACE("Entry " << FMT_i << - ": Remove because ID already seen"); + TRACE1("Entry %llx: Remove because ID already seen\n", (*i)->GetObjectID()); removeEntry = true; } else @@ -747,8 +730,7 @@ bool BackupStoreDirectory::CheckAndFix() && ((*i)->GetFlags() & Entry::Flags_Deleted) == 0) { // Not set, set it - BOX_TRACE("Entry " << FMT_i << - ": Set old flag"); + TRACE1("Entry %llx: Set old flag\n", (*i)->GetObjectID()); (*i)->AddFlags(Entry::Flags_OldVersion); changed = true; } @@ -759,8 +741,7 @@ bool BackupStoreDirectory::CheckAndFix() if(((*i)->GetFlags() & Entry::Flags_OldVersion) == Entry::Flags_OldVersion) { // Set, unset it - BOX_TRACE("Entry " << FMT_i << - ": Old flag unset"); + TRACE1("Entry %llx: Old flag unset\n", (*i)->GetObjectID()); (*i)->RemoveFlags(Entry::Flags_OldVersion); changed = true; } diff --git a/lib/backupstore/BackupStoreCheckData.cpp b/lib/backupstore/BackupStoreCheckData.cpp index aeb96173..f22c8339 100644 --- a/lib/backupstore/BackupStoreCheckData.cpp +++ b/lib/backupstore/BackupStoreCheckData.cpp @@ -189,18 +189,15 @@ void BackupStoreCheck::DumpObjectInfo() { IDBlock *pblock = i->second; int32_t bentries = (pblock == mpInfoLastBlock)?mInfoLastBlockEntries:BACKUPSTORECHECK_BLOCK_SIZE; - BOX_TRACE("BLOCK @ " << BOX_FORMAT_HEX32(pblock) << - ", " << bentries << " entries"); + TRACE2("BLOCK @ 0x%08x, %d entries\n", pblock, bentries); for(int e = 0; e < bentries; ++e) { uint8_t flags = GetFlags(pblock, e); - BOX_TRACE(std::hex << - "id " << pblock->mID[e] << - ", c " << pblock->mContainer[e] << - ", " << ((flags & Flags_IsDir)?"dir":"file") << - ", " << ((flags & Flags_IsContained) ? - "contained":"unattached")); + TRACE4("id %llx, c %llx, %s, %s\n", + pblock->mID[e], pblock->mContainer[e], + (flags & Flags_IsDir)?"dir":"file", + (flags & Flags_IsContained)?"contained":"unattached"); } } } diff --git a/lib/backupstore/BackupStoreConfigVerify.cpp b/lib/backupstore/BackupStoreConfigVerify.cpp index cc6efcf5..784adfb8 100644 --- a/lib/backupstore/BackupStoreConfigVerify.cpp +++ b/lib/backupstore/BackupStoreConfigVerify.cpp @@ -16,8 +16,7 @@ static const ConfigurationVerifyKey verifyserverkeys[] = { - SERVERTLS_VERIFY_SERVER_KEYS(ConfigurationVerifyKey::NoDefaultValue) - // no default listen addresses + SERVERTLS_VERIFY_SERVER_KEYS(0) // no default listen addresses }; static const ConfigurationVerify verifyserver[] = @@ -33,18 +32,16 @@ static const ConfigurationVerify verifyserver[] = static const ConfigurationVerifyKey verifyrootkeys[] = { - ConfigurationVerifyKey("AccountDatabase", ConfigTest_Exists), - ConfigurationVerifyKey("TimeBetweenHousekeeping", - ConfigTest_Exists | ConfigTest_IsInt), - ConfigurationVerifyKey("ExtendedLogging", ConfigTest_IsBool, false), - // make value "yes" to enable in config file + {"AccountDatabase", 0, ConfigTest_Exists, 0}, + {"TimeBetweenHousekeeping", 0, ConfigTest_Exists | ConfigTest_IsInt, 0}, + {"ExtendedLogging", "no", ConfigTest_IsBool, 0}, // make value "yes" to enable in config file #ifdef WIN32 - ConfigurationVerifyKey("RaidFileConf", ConfigTest_LastEntry) + {"RaidFileConf", "", ConfigTest_LastEntry, 0} #else - ConfigurationVerifyKey("RaidFileConf", ConfigTest_LastEntry, - BOX_FILE_RAIDFILE_DEFAULT_CONFIG) + {"RaidFileConf", BOX_FILE_RAIDFILE_DEFAULT_CONFIG, ConfigTest_LastEntry, 0} #endif + }; const ConfigurationVerify BackupConfigFileVerify = diff --git a/lib/common/Box.h b/lib/common/Box.h index dd91dfe2..d0e7ab1e 100644 --- a/lib/common/Box.h +++ b/lib/common/Box.h @@ -52,6 +52,15 @@ extern bool BoxDebugTraceOn; int BoxDebug_printf(const char *format, ...); int BoxDebugTrace(const char *format, ...); + #define TRACE0(msg) {BoxDebugTrace("%s", msg);} + #define TRACE1(msg, a0) {BoxDebugTrace(msg, a0);} + #define TRACE2(msg, a0, a1) {BoxDebugTrace(msg, a0, a1);} + #define TRACE3(msg, a0, a1, a2) {BoxDebugTrace(msg, a0, a1, a2);} + #define TRACE4(msg, a0, a1, a2, a3) {BoxDebugTrace(msg, a0, a1, a2, a3);} + #define TRACE5(msg, a0, a1, a2, a3, a4) {BoxDebugTrace(msg, a0, a1, a2, a3, a4);} + #define TRACE6(msg, a0, a1, a2, a3, a4, a5) {BoxDebugTrace(msg, a0, a1, a2, a3, a4, a5);} + #define TRACE7(msg, a0, a1, a2, a3, a4, a5, a6) {BoxDebugTrace(msg, a0, a1, a2, a3, a4, a5, a6);} + #define TRACE8(msg, a0, a1, a2, a3, a4, a5, a6, a7) {BoxDebugTrace(msg, a0, a1, a2, a3, a4, a5, a6, a7);} #ifndef PLATFORM_DISABLE_MEM_LEAK_TESTING #define BOX_MEMORY_LEAK_TESTING @@ -67,6 +76,16 @@ #define TRACE_TO_SYSLOG(x) {} #define TRACE_TO_STDOUT(x) {} + #define TRACE0(msg) + #define TRACE1(msg, a0) + #define TRACE2(msg, a0, a1) + #define TRACE3(msg, a0, a1, a2) + #define TRACE4(msg, a0, a1, a2, a3) + #define TRACE5(msg, a0, a1, a2, a3, a4) + #define TRACE6(msg, a0, a1, a2, a3, a4, a5) + #define TRACE7(msg, a0, a1, a2, a3, a4, a5, a6) + #define TRACE8(msg, a0, a1, a2, a3, a4, a5, a6, a7) + // Box Backup builds release get extra information for exception logging #define EXCEPTION_CODENAMES_EXTENDED #define EXCEPTION_CODENAMES_EXTENDED_WITH_DESCRIPTION diff --git a/lib/common/BoxTime.cpp b/lib/common/BoxTime.cpp index 7d7b1b40..1ddcffd4 100644 --- a/lib/common/BoxTime.cpp +++ b/lib/common/BoxTime.cpp @@ -39,8 +39,8 @@ box_time_t GetCurrentBoxTime() struct timeval tv; if (gettimeofday(&tv, NULL) != 0) { - BOX_LOG_SYS_ERROR("Failed to gettimeofday(), " - "dropping precision"); + BOX_ERROR("Failed to gettimeofday(), dropping " + "precision: " << strerror(errno)); } else { diff --git a/lib/common/Configuration.cpp b/lib/common/Configuration.cpp index 10e06680..4d76e0e0 100644 --- a/lib/common/Configuration.cpp +++ b/lib/common/Configuration.cpp @@ -12,8 +12,6 @@ #include #include -#include - #include "Configuration.h" #include "CommonException.h" #include "Guards.h" @@ -31,105 +29,7 @@ inline bool iw(int c) static const char *sValueBooleanStrings[] = {"yes", "true", "no", "false", 0}; static const bool sValueBooleanValue[] = {true, true, false, false}; -ConfigurationVerifyKey::ConfigurationVerifyKey -( - std::string name, - int flags, - void *testFunction -) -: mName(name), - mHasDefaultValue(false), - mFlags(flags), - mTestFunction(testFunction) -{ } - -// to allow passing NULL for default ListenAddresses - -ConfigurationVerifyKey::ConfigurationVerifyKey -( - std::string name, - int flags, - NoDefaultValue_t t, - void *testFunction -) -: mName(name), - mHasDefaultValue(false), - mFlags(flags), - mTestFunction(testFunction) -{ } - -ConfigurationVerifyKey::ConfigurationVerifyKey -( - std::string name, - int flags, - std::string defaultValue, - void *testFunction -) -: mName(name), - mDefaultValue(defaultValue), - mHasDefaultValue(true), - mFlags(flags), - mTestFunction(testFunction) -{ } - -ConfigurationVerifyKey::ConfigurationVerifyKey -( - std::string name, - int flags, - const char *defaultValue, - void *testFunction -) -: mName(name), - mDefaultValue(defaultValue), - mHasDefaultValue(true), - mFlags(flags), - mTestFunction(testFunction) -{ } - -ConfigurationVerifyKey::ConfigurationVerifyKey -( - std::string name, - int flags, - int defaultValue, - void *testFunction -) -: mName(name), - mHasDefaultValue(true), - mFlags(flags), - mTestFunction(testFunction) -{ - ASSERT(flags & ConfigTest_IsInt); - std::ostringstream val; - val << defaultValue; - mDefaultValue = val.str(); -} -ConfigurationVerifyKey::ConfigurationVerifyKey -( - std::string name, - int flags, - bool defaultValue, - void *testFunction -) -: mName(name), - mHasDefaultValue(true), - mFlags(flags), - mTestFunction(testFunction) -{ - ASSERT(flags & ConfigTest_IsBool); - mDefaultValue = defaultValue ? "yes" : "no"; -} - -ConfigurationVerifyKey::ConfigurationVerifyKey -( - const ConfigurationVerifyKey& rToCopy -) -: mName(rToCopy.mName), - mDefaultValue(rToCopy.mDefaultValue), - mHasDefaultValue(rToCopy.mHasDefaultValue), - mFlags(rToCopy.mFlags), - mTestFunction(rToCopy.mTestFunction) -{ } // -------------------------------------------------------------------------- // @@ -208,8 +108,8 @@ std::auto_ptr Configuration::LoadAndVerify( if(!rErrorMsg.empty()) { // An error occured, return now - BOX_ERROR("Error in Configuration::LoadInfo: " << - rErrorMsg); + //TRACE1("Error message from LoadInto: %s", rErrorMsg.c_str()); + TRACE0("Error at Configuration::LoadInfo\n"); delete pconfig; pconfig = 0; return std::auto_ptr(0); @@ -220,8 +120,8 @@ std::auto_ptr Configuration::LoadAndVerify( { if(!Verify(*pconfig, *pVerify, std::string(), rErrorMsg)) { - BOX_ERROR("Error verifying configuration: " << - rErrorMsg); + //TRACE1("Error message from Verify: %s", rErrorMsg.c_str()); + TRACE0("Error at Configuration::Verify\n"); delete pconfig; pconfig = 0; return std::auto_ptr(0); @@ -289,8 +189,7 @@ bool Configuration::LoadInto(Configuration &rConfig, FdGetLine &rGetLine, std::s } else { - rErrorMsg += "Unexpected start block in " + - rConfig.mName + "\n"; + rErrorMsg += "Unexpected start block in " + rConfig.mName + "\n"; } } else @@ -391,32 +290,36 @@ bool Configuration::LoadInto(Configuration &rConfig, FdGetLine &rGetLine, std::s // -------------------------------------------------------------------------- // // Function -// Name: Configuration::KeyExists(const std::string&) +// Name: Configuration::KeyExists(const char *) // Purpose: Checks to see if a key exists // Created: 2003/07/23 // // -------------------------------------------------------------------------- -bool Configuration::KeyExists(const std::string& rKeyName) const +bool Configuration::KeyExists(const char *pKeyName) const { - return mKeys.find(rKeyName) != mKeys.end(); + if(pKeyName == 0) {THROW_EXCEPTION(CommonException, BadArguments)} + + return mKeys.find(pKeyName) != mKeys.end(); } // -------------------------------------------------------------------------- // // Function -// Name: Configuration::GetKeyValue(const std::string&) +// Name: Configuration::GetKeyValue(const char *) // Purpose: Returns the value of a configuration variable // Created: 2003/07/23 // // -------------------------------------------------------------------------- -const std::string &Configuration::GetKeyValue(const std::string& rKeyName) const +const std::string &Configuration::GetKeyValue(const char *pKeyName) const { - std::map::const_iterator i(mKeys.find(rKeyName)); + if(pKeyName == 0) {THROW_EXCEPTION(CommonException, BadArguments)} + + std::map::const_iterator i(mKeys.find(pKeyName)); if(i == mKeys.end()) { - BOX_ERROR("Missing configuration key: " << rKeyName); + BOX_ERROR("Missing configuration key: " << pKeyName); THROW_EXCEPTION(CommonException, ConfigNoKey) } else @@ -429,14 +332,16 @@ const std::string &Configuration::GetKeyValue(const std::string& rKeyName) const // -------------------------------------------------------------------------- // // Function -// Name: Configuration::GetKeyValueInt(const std::string& rKeyName) +// Name: Configuration::GetKeyValueInt(const char *) // Purpose: Gets a key value as an integer // Created: 2003/07/23 // // -------------------------------------------------------------------------- -int Configuration::GetKeyValueInt(const std::string& rKeyName) const +int Configuration::GetKeyValueInt(const char *pKeyName) const { - std::map::const_iterator i(mKeys.find(rKeyName)); + if(pKeyName == 0) {THROW_EXCEPTION(CommonException, BadArguments)} + + std::map::const_iterator i(mKeys.find(pKeyName)); if(i == mKeys.end()) { @@ -457,14 +362,16 @@ int Configuration::GetKeyValueInt(const std::string& rKeyName) const // -------------------------------------------------------------------------- // // Function -// Name: Configuration::GetKeyValueBool(const std::string&) +// Name: Configuration::GetKeyValueBool(const char *) const // Purpose: Gets a key value as a boolean // Created: 17/2/04 // // -------------------------------------------------------------------------- -bool Configuration::GetKeyValueBool(const std::string& rKeyName) const +bool Configuration::GetKeyValueBool(const char *pKeyName) const { - std::map::const_iterator i(mKeys.find(rKeyName)); + if(pKeyName == 0) {THROW_EXCEPTION(CommonException, BadArguments)} + + std::map::const_iterator i(mKeys.find(pKeyName)); if(i == mKeys.end()) { @@ -521,21 +428,22 @@ std::vector Configuration::GetKeyNames() const // -------------------------------------------------------------------------- // // Function -// Name: Configuration::SubConfigurationExists(const -// std::string&) +// Name: Configuration::SubConfigurationExists(const char *) // Purpose: Checks to see if a sub configuration exists // Created: 2003/07/23 // // -------------------------------------------------------------------------- -bool Configuration::SubConfigurationExists(const std::string& rSubName) const +bool Configuration::SubConfigurationExists(const char *pSubName) const { + if(pSubName == 0) {THROW_EXCEPTION(CommonException, BadArguments)} + // Attempt to find it... std::list >::const_iterator i(mSubConfigurations.begin()); for(; i != mSubConfigurations.end(); ++i) { // This the one? - if(i->first == rSubName) + if(i->first == pSubName) { // Yes. return true; @@ -550,22 +458,22 @@ bool Configuration::SubConfigurationExists(const std::string& rSubName) const // -------------------------------------------------------------------------- // // Function -// Name: Configuration::GetSubConfiguration(const -// std::string&) +// Name: Configuration::GetSubConfiguration(const char *) // Purpose: Gets a sub configuration // Created: 2003/07/23 // // -------------------------------------------------------------------------- -const Configuration &Configuration::GetSubConfiguration(const std::string& - rSubName) const +const Configuration &Configuration::GetSubConfiguration(const char *pSubName) const { + if(pSubName == 0) {THROW_EXCEPTION(CommonException, BadArguments)} + // Attempt to find it... std::list >::const_iterator i(mSubConfigurations.begin()); for(; i != mSubConfigurations.end(); ++i) { // This the one? - if(i->first == rSubName) + if(i->first == pSubName) { // Yes. return i->second; @@ -620,14 +528,15 @@ bool Configuration::Verify(Configuration &rConfig, const ConfigurationVerify &rV do { // Can the key be found? - if(rConfig.KeyExists(pvkey->Name())) + ASSERT(pvkey->mpName); + if(rConfig.KeyExists(pvkey->mpName)) { // Get value - const std::string &rval = rConfig.GetKeyValue(pvkey->Name()); + const std::string &rval = rConfig.GetKeyValue(pvkey->mpName); const char *val = rval.c_str(); // Check it's a number? - if((pvkey->Flags() & ConfigTest_IsInt) == ConfigTest_IsInt) + if((pvkey->Tests & ConfigTest_IsInt) == ConfigTest_IsInt) { // Test it... char *end; @@ -636,12 +545,12 @@ bool Configuration::Verify(Configuration &rConfig, const ConfigurationVerify &rV { // not a good value ok = false; - rErrorMsg += rLevel + rConfig.mName + "." + pvkey->Name() + " (key) is not a valid integer.\n"; + rErrorMsg += rLevel + rConfig.mName +"." + pvkey->mpName + " (key) is not a valid integer.\n"; } } // Check it's a bool? - if((pvkey->Flags() & ConfigTest_IsBool) == ConfigTest_IsBool) + if((pvkey->Tests & ConfigTest_IsBool) == ConfigTest_IsBool) { // See if it's one of the allowed strings. bool found = false; @@ -659,38 +568,37 @@ bool Configuration::Verify(Configuration &rConfig, const ConfigurationVerify &rV if(!found) { ok = false; - rErrorMsg += rLevel + rConfig.mName + "." + pvkey->Name() + " (key) is not a valid boolean value.\n"; + rErrorMsg += rLevel + rConfig.mName +"." + pvkey->mpName + " (key) is not a valid boolean value.\n"; } } // Check for multi valued statments where they're not allowed - if((pvkey->Flags() & ConfigTest_MultiValueAllowed) == 0) + if((pvkey->Tests & ConfigTest_MultiValueAllowed) == 0) { // Check to see if this key is a multi-value -- it shouldn't be if(rval.find(MultiValueSeparator) != rval.npos) { ok = false; - rErrorMsg += rLevel + rConfig.mName +"." + pvkey->Name() + " (key) multi value not allowed (duplicated key?).\n"; + rErrorMsg += rLevel + rConfig.mName +"." + pvkey->mpName + " (key) multi value not allowed (duplicated key?).\n"; } } } else { // Is it required to exist? - if((pvkey->Flags() & ConfigTest_Exists) == ConfigTest_Exists) + if((pvkey->Tests & ConfigTest_Exists) == ConfigTest_Exists) { // Should exist, but doesn't. ok = false; - rErrorMsg += rLevel + rConfig.mName + "." + pvkey->Name() + " (key) is missing.\n"; + rErrorMsg += rLevel + rConfig.mName + "." + pvkey->mpName + " (key) is missing.\n"; } - else if(pvkey->HasDefaultValue()) + else if(pvkey->mpDefaultValue) { - rConfig.mKeys[pvkey->Name()] = - pvkey->DefaultValue(); + rConfig.mKeys[std::string(pvkey->mpName)] = std::string(pvkey->mpDefaultValue); } } - if((pvkey->Flags() & ConfigTest_LastEntry) == ConfigTest_LastEntry) + if((pvkey->Tests & ConfigTest_LastEntry) == ConfigTest_LastEntry) { // No more! todo = false; @@ -710,14 +618,14 @@ bool Configuration::Verify(Configuration &rConfig, const ConfigurationVerify &rV bool found = false; while(scan) { - if(scan->Name() == i->first) + if(scan->mpName == i->first) { found = true; break; } // Next? - if((scan->Flags() & ConfigTest_LastEntry) == ConfigTest_LastEntry) + if((scan->Tests & ConfigTest_LastEntry) == ConfigTest_LastEntry) { break; } @@ -742,7 +650,8 @@ bool Configuration::Verify(Configuration &rConfig, const ConfigurationVerify &rV const ConfigurationVerify *scan = rVerify.mpSubConfigurations; while(scan) { - if(scan->mName.length() > 0 && scan->mName[0] == '*') + ASSERT(scan->mpName); + if(scan->mpName[0] == '*') { wildcardverify = scan; } @@ -750,8 +659,7 @@ bool Configuration::Verify(Configuration &rConfig, const ConfigurationVerify &rV // Required? if((scan->Tests & ConfigTest_Exists) == ConfigTest_Exists) { - if(scan->mName.length() > 0 && - scan->mName[0] == '*') + if(scan->mpName[0] == '*') { // Check something exists if(rConfig.mSubConfigurations.size() < 1) @@ -764,11 +672,11 @@ bool Configuration::Verify(Configuration &rConfig, const ConfigurationVerify &rV else { // Check real thing exists - if(!rConfig.SubConfigurationExists(scan->mName)) + if(!rConfig.SubConfigurationExists(scan->mpName)) { // Should exist, but doesn't. ok = false; - rErrorMsg += rLevel + rConfig.mName + "." + scan->mName + " (block) is missing.\n"; + rErrorMsg += rLevel + rConfig.mName + "." + scan->mpName + " (block) is missing.\n"; } } } @@ -793,7 +701,7 @@ bool Configuration::Verify(Configuration &rConfig, const ConfigurationVerify &rV ASSERT(name); while(scan) { - if(scan->mName == name) + if(strcmp(scan->mpName, name) == 0) { // found it! subverify = scan; diff --git a/lib/common/Configuration.h b/lib/common/Configuration.h index 80b3614b..64e7568e 100644 --- a/lib/common/Configuration.h +++ b/lib/common/Configuration.h @@ -29,51 +29,20 @@ enum class ConfigurationVerifyKey { public: - typedef enum - { - NoDefaultValue = 1 - } NoDefaultValue_t; - - ConfigurationVerifyKey(std::string name, int flags, - void *testFunction = NULL); - // to allow passing ConfigurationVerifyKey::NoDefaultValue - // for default ListenAddresses - ConfigurationVerifyKey(std::string name, int flags, - NoDefaultValue_t t, void *testFunction = NULL); - ConfigurationVerifyKey(std::string name, int flags, - std::string defaultValue, void *testFunction = NULL); - ConfigurationVerifyKey(std::string name, int flags, - const char* defaultValue, void *testFunction = NULL); - ConfigurationVerifyKey(std::string name, int flags, - int defaultValue, void *testFunction = NULL); - ConfigurationVerifyKey(std::string name, int flags, - bool defaultValue, void *testFunction = NULL); - const std::string& Name() const { return mName; } - const std::string& DefaultValue() const { return mDefaultValue; } - const bool HasDefaultValue() const { return mHasDefaultValue; } - const int Flags() const { return mFlags; } - const void* TestFunction() const { return mTestFunction; } - ConfigurationVerifyKey(const ConfigurationVerifyKey& rToCopy); - -private: - ConfigurationVerifyKey& operator=(const ConfigurationVerifyKey& - noAssign); - - std::string mName; // "*" for all other keys (not implemented yet) - std::string mDefaultValue; // default for when it's not present - bool mHasDefaultValue; - int mFlags; - void *mTestFunction; // set to zero for now, will implement later + const char *mpName; // "*" for all other keys (not implemented yet) + const char *mpDefaultValue; // default for when it's not present + int Tests; + void *TestFunction; // set to zero for now, will implement later }; class ConfigurationVerify { public: - std::string mName; // "*" for all other sub config names + const char *mpName; // "*" for all other sub config names const ConfigurationVerify *mpSubConfigurations; const ConfigurationVerifyKey *mpKeys; int Tests; - void *TestFunction; // set to zero for now, will implement later + void *TestFunction; // set to zero for now, will implement later }; class FdGetLine; @@ -110,14 +79,14 @@ public: std::string &rErrorMsg) { return LoadAndVerify(rFilename, 0, rErrorMsg); } - bool KeyExists(const std::string& rKeyName) const; - const std::string &GetKeyValue(const std::string& rKeyName) const; - int GetKeyValueInt(const std::string& rKeyName) const; - bool GetKeyValueBool(const std::string& rKeyName) const; + bool KeyExists(const char *pKeyName) const; + const std::string &GetKeyValue(const char *pKeyName) const; + int GetKeyValueInt(const char *pKeyName) const; + bool GetKeyValueBool(const char *pKeyName) const; std::vector GetKeyNames() const; - bool SubConfigurationExists(const std::string& rSubName) const; - const Configuration &GetSubConfiguration(const std::string& rSubName) const; + bool SubConfigurationExists(const char *pSubName) const; + const Configuration &GetSubConfiguration(const char *pSubName) const; std::vector GetSubConfigurationNames() const; std::string mName; diff --git a/lib/common/DebugMemLeakFinder.cpp b/lib/common/DebugMemLeakFinder.cpp index 094820b3..87cdf00d 100644 --- a/lib/common/DebugMemLeakFinder.cpp +++ b/lib/common/DebugMemLeakFinder.cpp @@ -146,9 +146,7 @@ void *memleakfinder_realloc(void *ptr, size_t size) std::map::iterator i(sMallocBlocks.find(ptr)); if(ptr && i == sMallocBlocks.end()) { - BOX_WARNING("Block " << ptr << " realloc()ated, but not " - "in list. Error? Or allocated in startup static " - "objects?"); + TRACE1("Block %x realloc(), but not in list. Error? Or allocated in startup static objects?\n", ptr); } void *b = ::realloc(ptr, size); @@ -195,9 +193,7 @@ void memleakfinder_free(void *ptr) } else { - BOX_WARNING("Block " << ptr << " freed, but not " - "known. Error? Or allocated in startup " - "static allocation?"); + TRACE1("Block %p freed, but not known. Error? Or allocated in startup static allocation?\n", ptr); } if(sTrackMallocInSection) @@ -297,21 +293,16 @@ void memleakfinder_traceblocksinsection() std::map::const_iterator i(sMallocBlocks.find(*s)); if(i == sMallocBlocks.end()) { - BOX_WARNING("Logical error in section block finding"); + TRACE0("Logical error in section block finding\n"); } else { - BOX_TRACE("Block " << i->first << " size " << - i->second.size << " allocated at " << - i->second.file << ":" << i->second.line); + TRACE4("Block %p size %d allocated at %s:%d\n", i->first, i->second.size, i->second.file, i->second.line); } } for(std::map::const_iterator i(sSectionObjectBlocks.begin()); i != sSectionObjectBlocks.end(); ++i) { - BOX_TRACE("Object" << (i->second.array?" []":"") << " " << - i->first << " size " << i->second.size << - " allocated at " << i->second.file << - ":" << i->second.line); + TRACE5("Object%s %p size %d allocated at %s:%d\n", i->second.array?" []":"", i->first, i->second.size, i->second.file, i->second.line); } } diff --git a/lib/common/EventWatchFilesystemObject.cpp b/lib/common/EventWatchFilesystemObject.cpp index 43533fc8..84781113 100644 --- a/lib/common/EventWatchFilesystemObject.cpp +++ b/lib/common/EventWatchFilesystemObject.cpp @@ -26,10 +26,9 @@ // -------------------------------------------------------------------------- // // Function -// Name: EventWatchFilesystemObject::EventWatchFilesystemObject -// (const char *) -// Purpose: Constructor -- opens the file object -// Created: 12/3/04 +// Name: EventWatchFilesystemObject::EventWatchFilesystemObject(const char *) +// Purpose: Constructor -- opens the file object +// Created: 12/3/04 // // -------------------------------------------------------------------------- EventWatchFilesystemObject::EventWatchFilesystemObject(const char *Filename) @@ -40,8 +39,9 @@ EventWatchFilesystemObject::EventWatchFilesystemObject(const char *Filename) #ifdef HAVE_KQUEUE if(mDescriptor == -1) { - BOX_LOG_SYS_ERROR("EventWatchFilesystemObject: " - "Failed to open file '" << Filename << "'"); + BOX_ERROR("EventWatchFilesystemObject: " + "Failed to open file '" << Filename << "': " << + strerror(errno)); THROW_EXCEPTION(CommonException, OSFileOpenError) } #else @@ -53,9 +53,9 @@ EventWatchFilesystemObject::EventWatchFilesystemObject(const char *Filename) // -------------------------------------------------------------------------- // // Function -// Name: EventWatchFilesystemObject::~EventWatchFilesystemObject() -// Purpose: Destructor -// Created: 12/3/04 +// Name: EventWatchFilesystemObject::~EventWatchFilesystemObject() +// Purpose: Destructor +// Created: 12/3/04 // // -------------------------------------------------------------------------- EventWatchFilesystemObject::~EventWatchFilesystemObject() @@ -70,14 +70,12 @@ EventWatchFilesystemObject::~EventWatchFilesystemObject() // -------------------------------------------------------------------------- // // Function -// Name: EventWatchFilesystemObject::EventWatchFilesystemObject -// (const EventWatchFilesystemObject &) -// Purpose: Copy constructor -// Created: 12/3/04 +// Name: EventWatchFilesystemObject::EventWatchFilesystemObject(const EventWatchFilesystemObject &) +// Purpose: Copy constructor +// Created: 12/3/04 // // -------------------------------------------------------------------------- -EventWatchFilesystemObject::EventWatchFilesystemObject( - const EventWatchFilesystemObject &rToCopy) +EventWatchFilesystemObject::EventWatchFilesystemObject(const EventWatchFilesystemObject &rToCopy) : mDescriptor(::dup(rToCopy.mDescriptor)) { if(mDescriptor == -1) @@ -91,20 +89,17 @@ EventWatchFilesystemObject::EventWatchFilesystemObject( // -------------------------------------------------------------------------- // // Function -// Name: EventWatchFilesystemObject::FillInKEvent(struct kevent &, int) -// Purpose: For WaitForEvent -// Created: 12/3/04 +// Name: EventWatchFilesystemObject::FillInKEvent(struct kevent &, int) +// Purpose: For WaitForEvent +// Created: 12/3/04 // // -------------------------------------------------------------------------- -void EventWatchFilesystemObject::FillInKEvent(struct kevent &rEvent, - int Flags) const +void EventWatchFilesystemObject::FillInKEvent(struct kevent &rEvent, int Flags) const { - EV_SET(&rEvent, mDescriptor, EVFILT_VNODE, EV_CLEAR, - NOTE_DELETE | NOTE_WRITE, 0, (void*)this); + EV_SET(&rEvent, mDescriptor, EVFILT_VNODE, EV_CLEAR, NOTE_DELETE | NOTE_WRITE, 0, (void*)this); } #else -void EventWatchFilesystemObject::FillInPoll(int &fd, short &events, - int Flags) const +void EventWatchFilesystemObject::FillInPoll(int &fd, short &events, int Flags) const { THROW_EXCEPTION(CommonException, KQueueNotSupportedOnThisPlatform) } diff --git a/lib/common/FileStream.cpp b/lib/common/FileStream.cpp index 57fb8274..e0806e10 100644 --- a/lib/common/FileStream.cpp +++ b/lib/common/FileStream.cpp @@ -30,8 +30,7 @@ FileStream::FileStream(const char *Filename, int flags, int mode) #else : mOSFileHandle(::open(Filename, flags, mode)), #endif - mIsEOF(false), - mFileName(Filename) + mIsEOF(false) { #ifdef WIN32 if(mOSFileHandle == INVALID_HANDLE_VALUE) @@ -50,6 +49,9 @@ FileStream::FileStream(const char *Filename, int flags, int mode) THROW_EXCEPTION(CommonException, OSFileOpenError) } } +#ifdef WIN32 + this->fileName = Filename; +#endif } @@ -63,8 +65,7 @@ FileStream::FileStream(const char *Filename, int flags, int mode) // -------------------------------------------------------------------------- FileStream::FileStream(tOSFileHandle FileDescriptor) : mOSFileHandle(FileDescriptor), - mIsEOF(false), - mFileName("HANDLE") + mIsEOF(false) { #ifdef WIN32 if(mOSFileHandle == INVALID_HANDLE_VALUE) @@ -76,6 +77,9 @@ FileStream::FileStream(tOSFileHandle FileDescriptor) BOX_ERROR("FileStream: called with invalid file handle"); THROW_EXCEPTION(CommonException, OSFileOpenError) } +#ifdef WIN32 + this->fileName = "HANDLE"; +#endif } #if 0 @@ -146,32 +150,27 @@ int FileStream::Read(void *pBuffer, int NBytes, int Timeout) NULL ); - if(valid) + if ( valid ) { r = numBytesRead; } - else if(GetLastError() == ERROR_BROKEN_PIPE) + else if (GetLastError() == ERROR_BROKEN_PIPE) { r = 0; } else { - BOX_LOG_WIN_ERROR("Failed to read from file: " << mFileName); + BOX_ERROR("Failed to read from file: " << + GetErrorMessage(GetLastError())); r = -1; } #else int r = ::read(mOSFileHandle, pBuffer, NBytes); - if(r == -1) - { - BOX_LOG_SYS_ERROR("Failed to read from file: " << mFileName); - } #endif - if(r == -1) { THROW_EXCEPTION(CommonException, OSFileReadError) } - if(r == 0) { mIsEOF = true; diff --git a/lib/common/FileStream.h b/lib/common/FileStream.h index 23cc8e75..721bf3dd 100644 --- a/lib/common/FileStream.h +++ b/lib/common/FileStream.h @@ -57,8 +57,10 @@ private: bool mIsEOF; FileStream(const FileStream &rToCopy) { /* do not call */ } +#ifdef WIN32 // for debugging.. - std::string mFileName; + std::string fileName; +#endif }; diff --git a/lib/common/Guards.h b/lib/common/Guards.h index cd2e4628..d2fb84e0 100644 --- a/lib/common/Guards.h +++ b/lib/common/Guards.h @@ -37,8 +37,8 @@ public: { if(mOSFileHandle < 0) { - BOX_LOG_SYS_ERROR("FileHandleGuard: failed to open " - "file '" << rFilename << "'"); + BOX_ERROR("FileHandleGuard: failed to open file '" << + rFilename << "': " << strerror(errno)); THROW_EXCEPTION(CommonException, OSFileOpenError) } } diff --git a/lib/common/Logging.h b/lib/common/Logging.h index 2c967c89..2d726627 100644 --- a/lib/common/Logging.h +++ b/lib/common/Logging.h @@ -27,16 +27,16 @@ #define BOX_LOG(level, stuff) \ { \ - std::ostringstream _box_log_line; \ - _box_log_line << stuff; \ - Logging::Log(level, __FILE__, __LINE__, _box_log_line.str()); \ + std::ostringstream line; \ + line << stuff; \ + Logging::Log(level, __FILE__, __LINE__, line.str()); \ } #define BOX_SYSLOG(level, stuff) \ { \ - std::ostringstream _box_log_line; \ - _box_log_line << stuff; \ - Logging::LogToSyslog(level, __FILE__, __LINE__, _box_log_line.str()); \ + std::ostringstream line; \ + line << stuff; \ + Logging::LogToSyslog(level, __FILE__, __LINE__, line.str()); \ } #define BOX_FATAL(stuff) BOX_LOG(Log::FATAL, stuff) @@ -48,32 +48,15 @@ if (Logging::IsEnabled(Log::TRACE)) \ { BOX_LOG(Log::TRACE, stuff) } -#define BOX_LOG_SYS_WARNING(stuff) \ - BOX_WARNING(stuff << ": " << strerror(errno) << " (" << errno << ")") -#define BOX_LOG_SYS_ERROR(stuff) \ - BOX_ERROR(stuff << ": " << strerror(errno) << " (" << errno << ")") -#define BOX_LOG_SYS_FATAL(stuff) \ - BOX_FATAL(stuff << ": " << strerror(errno) << " (" << errno << ")") - -#ifdef WIN32 - #define BOX_LOG_WIN_ERROR(stuff) \ - BOX_ERROR(stuff << ": " << GetErrorMessage(GetLastError())) - #define BOX_LOG_WIN_ERROR_NUMBER(stuff, number) \ - BOX_ERROR(stuff << ": " << GetErrorMessage(number)) -#endif - -#define BOX_FORMAT_HEX32(number) \ +#define BOX_FORMAT_ACCOUNT(accno) \ std::hex << \ std::showbase << \ std::internal << \ std::setw(10) << \ std::setfill('0') << \ - (number) << \ + (accno) << \ std::dec -#define BOX_FORMAT_ACCOUNT(accno) \ - BOX_FORMAT_HEX32(accno) - #define BOX_FORMAT_OBJECTID(objectid) \ std::hex << \ std::showbase << \ diff --git a/lib/common/PartialReadStream.cpp b/lib/common/PartialReadStream.cpp index f2f79715..76096738 100644 --- a/lib/common/PartialReadStream.cpp +++ b/lib/common/PartialReadStream.cpp @@ -44,8 +44,7 @@ PartialReadStream::~PartialReadStream() // Warn in debug mode if(mBytesLeft != 0) { - BOX_TRACE("PartialReadStream destroyed with " << mBytesLeft << - " bytes remaining"); + TRACE1("PartialReadStream::~PartialReadStream when mBytesLeft = %d\n", mBytesLeft); } } diff --git a/lib/common/Utils.cpp b/lib/common/Utils.cpp index 90421299..83a12ccf 100644 --- a/lib/common/Utils.cpp +++ b/lib/common/Utils.cpp @@ -53,10 +53,10 @@ void SplitString(const std::string &String, char SplitOn, std::vector 1024) - { - readableValue /= 1024; - units = "kB"; - } - - if (readableValue > 1024) - { - readableValue /= 1024; - units = "MB"; - } - - if (readableValue > 1024) - { - readableValue /= 1024; - units = "GB"; - } - - std::ostringstream result; - result << std::fixed << std::setprecision(2) << readableValue << - " " << units; - return result.str(); -} -std::string FormatUsageBar(int64_t Blocks, int64_t Bytes, int64_t Max) -{ - std::ostringstream result; - - // Bar graph - char bar[17]; - unsigned int b = (int)((Bytes * (sizeof(bar)-1)) / Max); - if(b > sizeof(bar)-1) {b = sizeof(bar)-1;} - for(unsigned int l = 0; l < b; l++) - { - bar[l] = '*'; - } - for(unsigned int l = b; l < sizeof(bar) - 1; l++) - { - bar[l] = ' '; - } - bar[sizeof(bar)-1] = '\0'; - - result << std::fixed << - std::setw(10) << Blocks << " blocks, " << - std::setw(10) << HumanReadableSize(Bytes) << ", " << - std::setw(3) << std::setprecision(0) << - ((Bytes*100)/Max) << "% |" << bar << "|"; - - return result.str(); -} -std::string FormatUsageLineStart(const std::string& rName) -{ - std::ostringstream result; - result << std::setw(20) << std::right << rName << ": "; - return result.str(); -} diff --git a/lib/common/Utils.h b/lib/common/Utils.h index 78bcbd6b..d0842b51 100644 --- a/lib/common/Utils.h +++ b/lib/common/Utils.h @@ -30,9 +30,6 @@ enum ObjectExists_Dir = 2 }; int ObjectExists(const std::string& rFilename); -std::string HumanReadableSize(int64_t Bytes); -std::string FormatUsageBar(int64_t Blocks, int64_t Bytes, int64_t Max); -std::string FormatUsageLineStart(const std::string& rName); #include "MemLeakFindOff.h" diff --git a/lib/compress/Compress.h b/lib/compress/Compress.h index de38af2c..4a98a59e 100644 --- a/lib/compress/Compress.h +++ b/lib/compress/Compress.h @@ -52,12 +52,10 @@ public: if((r = ((Compressing)?(deflateEnd(&mStream)) :(inflateEnd(&mStream)))) != Z_OK) { - BOX_WARNING("zlib error code = " << r); + TRACE1("zlib error code = %d\n", r); if(r == Z_DATA_ERROR) { - BOX_WARNING("End of compress/decompress " - "without all input being consumed, " - "possible corruption?"); + TRACE0("WARNING: End of compress/decompress without all input being consumed -- possible corruption?\n"); } else { @@ -150,7 +148,7 @@ public: // Check errors if(ret < 0) { - BOX_WARNING("zlib error code = " << ret); + TRACE1("zlib error code = %d\n", ret); THROW_EXCEPTION(CompressException, TransformFailed) } diff --git a/lib/compress/CompressStream.cpp b/lib/compress/CompressStream.cpp index 322b203b..2839b647 100644 --- a/lib/compress/CompressStream.cpp +++ b/lib/compress/CompressStream.cpp @@ -414,7 +414,7 @@ void CompressStream::CheckBuffer() { size *= 2; } - BOX_TRACE("Allocating CompressStream buffer, size " << size); + TRACE1("Allocating CompressStream buffer, size %d\n", size); mpBuffer = ::malloc(size); if(mpBuffer == 0) { diff --git a/lib/crypto/CipherContext.cpp b/lib/crypto/CipherContext.cpp index d68c4b5d..8c3b25b2 100644 --- a/lib/crypto/CipherContext.cpp +++ b/lib/crypto/CipherContext.cpp @@ -166,8 +166,7 @@ void CipherContext::Begin() // Warn if in a transformation (not an error, because a context might not have been finalised if an exception occured) if(mWithinTransform) { - BOX_WARNING("CipherContext::Begin called when context " - "flagged as within a transform"); + TRACE0("CipherContext::Begin called when context flagged as within a transform\n"); } // Initialise the cipher context again @@ -424,8 +423,7 @@ int CipherContext::TransformBlock(void *pOutBuffer, int OutLength, const void *p // Warn if in a transformation if(mWithinTransform) { - BOX_WARNING("CipherContext::TransformBlock called when " - "context flagged as within a transform"); + TRACE0("CipherContext::TransformBlock called when context flagged as within a transform\n"); } // Check output buffer size @@ -523,8 +521,7 @@ void CipherContext::SetIV(const void *pIV) // Warn if in a transformation if(mWithinTransform) { - BOX_WARNING("CipherContext::SetIV called when context " - "flagged as within a transform"); + TRACE0("CipherContext::SetIV called when context flagged as within a transform\n"); } // Set IV @@ -562,8 +559,7 @@ const void *CipherContext::SetRandomIV(int &rLengthOut) // Warn if in a transformation if(mWithinTransform) { - BOX_WARNING("CipherContext::SetRandomIV called when " - "context flagged as within a transform"); + TRACE0("CipherContext::SetRandomIV called when context flagged as within a transform\n"); } // Get length of IV diff --git a/lib/intercept/intercept.cpp b/lib/intercept/intercept.cpp index bbcb740e..65514ae2 100644 --- a/lib/intercept/intercept.cpp +++ b/lib/intercept/intercept.cpp @@ -375,12 +375,12 @@ void intercept_setup_readdir_hook(const char *dirname, readdir_t hookfn) if (hookfn != NULL) { - BOX_TRACE("readdir hooked to " << hookfn << " for " << dirname); + TRACE2("readdir hooked to %p for %s\n", hookfn, dirname); } else if (intercept_filename != NULL) { - BOX_TRACE("readdir unhooked from " << readdir_hook << - " for " << intercept_filename); + TRACE2("readdir unhooked from %p for %s\n", readdir_hook, + intercept_filename); } intercept_filename = dirname; @@ -392,11 +392,11 @@ void intercept_setup_lstat_hook(const char *filename, lstat_t hookfn) /* if (hookfn != NULL) { - BOX_TRACE("lstat hooked to " << hookfn << " for " << filename); + TRACE2("lstat hooked to %p for %s\n", hookfn, filename); } else { - BOX_TRACE("lstat unhooked from " << lstat_hook << " for " << + TRACE2("lstat unhooked from %p for %s\n", lstat_hook, lstat_file); } */ diff --git a/lib/raidfile/RaidFileController.cpp b/lib/raidfile/RaidFileController.cpp index 86fa9df1..0cc2ede7 100644 --- a/lib/raidfile/RaidFileController.cpp +++ b/lib/raidfile/RaidFileController.cpp @@ -70,14 +70,11 @@ void RaidFileController::Initialise(const std::string& rConfigFilename) static const ConfigurationVerifyKey verifykeys[] = { - ConfigurationVerifyKey("SetNumber", - ConfigTest_Exists | ConfigTest_IsInt), - ConfigurationVerifyKey("BlockSize", - ConfigTest_Exists | ConfigTest_IsInt), - ConfigurationVerifyKey("Dir0", ConfigTest_Exists), - ConfigurationVerifyKey("Dir1", ConfigTest_Exists), - ConfigurationVerifyKey("Dir2", - ConfigTest_Exists | ConfigTest_LastEntry) + {"SetNumber", 0, ConfigTest_Exists | ConfigTest_IsInt, 0}, + {"BlockSize", 0, ConfigTest_Exists | ConfigTest_IsInt, 0}, + {"Dir0", 0, ConfigTest_Exists, 0}, + {"Dir1", 0, ConfigTest_Exists, 0}, + {"Dir2", 0, ConfigTest_Exists | ConfigTest_LastEntry, 0} }; static const ConfigurationVerify subverify = diff --git a/lib/raidfile/RaidFileWrite.cpp b/lib/raidfile/RaidFileWrite.cpp index c8c39dc4..66ab81c8 100644 --- a/lib/raidfile/RaidFileWrite.cpp +++ b/lib/raidfile/RaidFileWrite.cpp @@ -96,8 +96,7 @@ void RaidFileWrite::Open(bool AllowOverwrite) RaidFileUtil::ExistType existance = RaidFileUtil::RaidFileExists(rdiscSet, mFilename); if(existance != RaidFileUtil::NoFile) { - BOX_ERROR("Attempted to overwrite raidfile " << - mSetNumber << " " << mFilename); + TRACE2("Trying to overwrite raidfile %d %s\n", mSetNumber, mFilename.c_str()); THROW_EXCEPTION(RaidFileException, CannotOverwriteExistingFile) } } @@ -179,8 +178,7 @@ void RaidFileWrite::Write(const void *pBuffer, int Length) int written = ::write(mOSFileHandle, pBuffer, Length); if(written != Length) { - BOX_LOG_SYS_ERROR("RaidFileWrite failed, Length = " << - Length << ", written = " << written); + TRACE3("RaidFileWrite::Write: Write failure, Length = %d, written = %d, errno = %d\n", Length, written, errno); THROW_EXCEPTION(RaidFileException, OSError) } } @@ -781,7 +779,7 @@ int RaidFileWrite::Read(void *pBuffer, int NBytes, int Timeout) // -------------------------------------------------------------------------- void RaidFileWrite::Close() { - BOX_WARNING("RaidFileWrite::Close() called, discarding file"); + TRACE0("Warning: RaidFileWrite::Close() called, discarding file\n"); if(mOSFileHandle != -1) { Discard(); diff --git a/lib/server/Daemon.cpp b/lib/server/Daemon.cpp index 292a628c..95f5c338 100644 --- a/lib/server/Daemon.cpp +++ b/lib/server/Daemon.cpp @@ -465,7 +465,8 @@ int Daemon::Main(const std::string &rConfigFileName) // Set new session if(::setsid() == -1) { - BOX_LOG_SYS_ERROR("Failed to setsid()"); + BOX_ERROR("Failed to setsid(): " << + strerror(errno)); THROW_EXCEPTION(ServerException, DaemoniseFailed) } @@ -474,7 +475,6 @@ int Daemon::Main(const std::string &rConfigFileName) { case -1: // error - BOX_LOG_SYS_ERROR("Failed to fork() a child"); THROW_EXCEPTION(ServerException, DaemoniseFailed) break; @@ -497,11 +497,9 @@ int Daemon::Main(const std::string &rConfigFileName) struct sigaction sa; sa.sa_handler = SignalHandler; sa.sa_flags = 0; - sigemptyset(&sa.sa_mask); // macro - if(::sigaction(SIGHUP, &sa, NULL) != 0 || - ::sigaction(SIGTERM, &sa, NULL) != 0) + sigemptyset(&sa.sa_mask); // macro + if(::sigaction(SIGHUP, &sa, NULL) != 0 || ::sigaction(SIGTERM, &sa, NULL) != 0) { - BOX_LOG_SYS_ERROR("Failed to set signal handlers"); THROW_EXCEPTION(ServerException, DaemoniseFailed) } #endif // !WIN32 @@ -517,8 +515,7 @@ int Daemon::Main(const std::string &rConfigFileName) if(::write(pidFile, pid, pidsize) != pidsize) { - BOX_LOG_SYS_FATAL("Failed to write PID file: " << - pidFileName); + BOX_FATAL("can't write pid file"); THROW_EXCEPTION(ServerException, DaemoniseFailed) } @@ -547,7 +544,6 @@ int Daemon::Main(const std::string &rConfigFileName) int devnull = ::open(PLATFORM_DEV_NULL, O_RDWR, 0); if(devnull == -1) { - BOX_LOG_SYS_ERROR("Failed to open /dev/null"); THROW_EXCEPTION(CommonException, OSFileError); } // Then duplicate them to all three handles @@ -894,8 +890,6 @@ box_time_t Daemon::GetConfigFileModifiedTime() const { return 0; } - BOX_LOG_SYS_ERROR("Failed to stat configuration file: " << - GetConfigFileName()); THROW_EXCEPTION(CommonException, OSFileError) } diff --git a/lib/server/Daemon.h b/lib/server/Daemon.h index ef5728ec..60444ab9 100644 --- a/lib/server/Daemon.h +++ b/lib/server/Daemon.h @@ -92,9 +92,8 @@ private: std::string mAppName; }; -#define DAEMON_VERIFY_SERVER_KEYS \ - ConfigurationVerifyKey("PidFile", ConfigTest_Exists), \ - ConfigurationVerifyKey("User", ConfigTest_LastEntry) +#define DAEMON_VERIFY_SERVER_KEYS {"PidFile", 0, ConfigTest_Exists, 0}, \ + {"User", 0, ConfigTest_LastEntry, 0} #endif // DAEMON__H diff --git a/lib/server/ProtocolUncertainStream.cpp b/lib/server/ProtocolUncertainStream.cpp index 9c15455d..60c1fa1d 100644 --- a/lib/server/ProtocolUncertainStream.cpp +++ b/lib/server/ProtocolUncertainStream.cpp @@ -41,8 +41,7 @@ ProtocolUncertainStream::~ProtocolUncertainStream() { if(!mFinished) { - BOX_WARNING("ProtocolUncertainStream destroyed before " - "stream finished"); + TRACE0("ProtocolUncertainStream::~ProtocolUncertainStream() destroyed when stream not complete\n"); } } diff --git a/lib/server/ServerControl.h b/lib/server/ServerControl.h index 771f88fb..ce5620c2 100644 --- a/lib/server/ServerControl.h +++ b/lib/server/ServerControl.h @@ -142,7 +142,8 @@ inline bool KillServerInternal(int pid) bool killed = (::kill(pid, SIGTERM) == 0); if (!killed) { - BOX_LOG_SYS_ERROR("Failed to kill process " << pid); + BOX_ERROR("Failed to kill process " << pid << ": " << + strerror(errno)); } TEST_THAT(killed); return killed; diff --git a/lib/server/ServerStream.h b/lib/server/ServerStream.h index 41899e78..32a57bac 100644 --- a/lib/server/ServerStream.h +++ b/lib/server/ServerStream.h @@ -273,7 +273,7 @@ public: } // Log it - BOX_NOTICE("Message from child process " << pid << ": " << logMessage); + BOX_WARNING("Message from child process " << pid << ": " << logMessage); } else { @@ -365,8 +365,8 @@ private: }; #define SERVERSTREAM_VERIFY_SERVER_KEYS(DEFAULT_ADDRESSES) \ - ConfigurationVerifyKey("ListenAddresses", 0, DEFAULT_ADDRESSES), \ - DAEMON_VERIFY_SERVER_KEYS + {"ListenAddresses", DEFAULT_ADDRESSES, 0, 0}, \ + DAEMON_VERIFY_SERVER_KEYS #include "MemLeakFindOff.h" diff --git a/lib/server/ServerTLS.h b/lib/server/ServerTLS.h index 1bfcb547..71d35380 100644 --- a/lib/server/ServerTLS.h +++ b/lib/server/ServerTLS.h @@ -70,10 +70,11 @@ private: }; #define SERVERTLS_VERIFY_SERVER_KEYS(DEFAULT_ADDRESSES) \ - ConfigurationVerifyKey("CertificateFile", ConfigTest_Exists), \ - ConfigurationVerifyKey("PrivateKeyFile", ConfigTest_Exists), \ - ConfigurationVerifyKey("TrustedCAsFile", ConfigTest_Exists), \ - SERVERSTREAM_VERIFY_SERVER_KEYS(DEFAULT_ADDRESSES) + {"CertificateFile", 0, ConfigTest_Exists, 0}, \ + {"PrivateKeyFile", 0, ConfigTest_Exists, 0}, \ + {"TrustedCAsFile", 0, ConfigTest_Exists, 0}, \ + SERVERSTREAM_VERIFY_SERVER_KEYS(DEFAULT_ADDRESSES) + #endif // SERVERTLS__H diff --git a/lib/server/SocketListen.h b/lib/server/SocketListen.h index 1cfce648..ff08fb8f 100644 --- a/lib/server/SocketListen.h +++ b/lib/server/SocketListen.h @@ -108,57 +108,45 @@ public: if(::close(mSocketHandle) == -1) #endif { - BOX_LOG_SYS_ERROR("Failed to close network " - "socket"); - THROW_EXCEPTION(ServerException, - SocketCloseError) + THROW_EXCEPTION(ServerException, SocketCloseError) } } mSocketHandle = -1; } - // ------------------------------------------------------------------ + // -------------------------------------------------------------------------- // // Function // Name: SocketListen::Listen(int, char*, int) // Purpose: Initialises, starts the socket listening. // Created: 2003/07/31 // - // ------------------------------------------------------------------ + // -------------------------------------------------------------------------- void Listen(int Type, const char *Name, int Port = 0) { - if(mSocketHandle != -1) - { - THROW_EXCEPTION(ServerException, SocketAlreadyOpen); - } + if(mSocketHandle != -1) {THROW_EXCEPTION(ServerException, SocketAlreadyOpen)} // Setup parameters based on type, looking up names if required int sockDomain = 0; SocketAllAddr addr; int addrLen = 0; - Socket::NameLookupToSockAddr(addr, sockDomain, Type, Name, - Port, addrLen); + Socket::NameLookupToSockAddr(addr, sockDomain, Type, Name, Port, addrLen); // Create the socket - mSocketHandle = ::socket(sockDomain, SOCK_STREAM, - 0 /* let OS choose protocol */); + mSocketHandle = ::socket(sockDomain, SOCK_STREAM, 0 /* let OS choose protocol */); if(mSocketHandle == -1) { - BOX_LOG_SYS_ERROR("Failed to create a network socket"); THROW_EXCEPTION(ServerException, SocketOpenError) } // Set an option to allow reuse (useful for -HUP situations!) #ifdef WIN32 - if(::setsockopt(mSocketHandle, SOL_SOCKET, SO_REUSEADDR, "", - 0) == -1) + if(::setsockopt(mSocketHandle, SOL_SOCKET, SO_REUSEADDR, "", 0) == -1) #else int option = true; - if(::setsockopt(mSocketHandle, SOL_SOCKET, SO_REUSEADDR, - &option, sizeof(option)) == -1) + if(::setsockopt(mSocketHandle, SOL_SOCKET, SO_REUSEADDR, &option, sizeof(option)) == -1) #endif { - BOX_LOG_SYS_ERROR("Failed to set socket options"); THROW_EXCEPTION(ServerException, SocketOpenError) } @@ -173,25 +161,19 @@ public: } } - // ------------------------------------------------------------------ + // -------------------------------------------------------------------------- // // Function // Name: SocketListen::Accept(int) - // Purpose: Accepts a connection, returning a pointer to - // a class of the specified type. May return a - // null pointer if a signal happens, or there's - // a timeout. Timeout specified in - // milliseconds, defaults to infinite time. + // Purpose: Accepts a connection, returning a pointer to a class of + // the specified type. May return a null pointer if a signal happens, + // or there's a timeout. Timeout specified in milliseconds, defaults to infinite time. // Created: 2003/07/31 // - // ------------------------------------------------------------------ - std::auto_ptr Accept(int Timeout = INFTIM, - std::string *pLogMsg = 0) + // -------------------------------------------------------------------------- + std::auto_ptr Accept(int Timeout = INFTIM, std::string *pLogMsg = 0) { - if(mSocketHandle == -1) - { - THROW_EXCEPTION(ServerException, BadSocketHandle); - } + if(mSocketHandle == -1) {THROW_EXCEPTION(ServerException, BadSocketHandle)} // Do the accept, using the supplied locking type int sock; @@ -203,10 +185,8 @@ public: if(!socklock.HaveLock()) { - // Didn't get the lock for some reason. - // Wait a while, then return nothing. - BOX_ERROR("Failed to get a lock on incoming " - "connection"); + // Didn't get the lock for some reason. Wait a while, then + // return nothing. ::sleep(1); return std::auto_ptr(); } @@ -222,18 +202,12 @@ public: // signal? if(errno == EINTR) { - BOX_ERROR("Failed to accept " - "connection: interrupted by " - "signal"); // return nothing return std::auto_ptr(); } else { - BOX_LOG_SYS_ERROR("Failed to poll " - "connection"); - THROW_EXCEPTION(ServerException, - SocketPollError) + THROW_EXCEPTION(ServerException, SocketPollError) } break; case 0: // timed out @@ -246,19 +220,16 @@ public: sock = ::accept(mSocketHandle, &addr, &addrlen); } - - // Got socket (or error), unlock (implicit in destruction) + // Got socket (or error), unlock (implcit in destruction) if(sock == -1) { - BOX_LOG_SYS_ERROR("Failed to accept connection"); THROW_EXCEPTION(ServerException, SocketAcceptError) } // Log it if(pLogMsg) { - *pLogMsg = Socket::IncomingConnectionLogMessage(&addr, - addrlen); + *pLogMsg = Socket::IncomingConnectionLogMessage(&addr, addrlen); } else { @@ -272,29 +243,27 @@ public: // Functions to allow adding to WaitForEvent class, for efficient waiting // on multiple sockets. #ifdef HAVE_KQUEUE - // ------------------------------------------------------------------ + // -------------------------------------------------------------------------- // // Function // Name: SocketListen::FillInKEevent // Purpose: Fills in a kevent structure for this socket // Created: 9/3/04 // - // ------------------------------------------------------------------ + // -------------------------------------------------------------------------- void FillInKEvent(struct kevent &rEvent, int Flags = 0) const { - EV_SET(&rEvent, mSocketHandle, EVFILT_READ, 0, 0, 0, - (void*)this); + EV_SET(&rEvent, mSocketHandle, EVFILT_READ, 0, 0, 0, (void*)this); } #else - // ------------------------------------------------------------------ + // -------------------------------------------------------------------------- // // Function // Name: SocketListen::FillInPoll - // Purpose: Fills in the data necessary for a poll - // operation + // Purpose: Fills in the data necessary for a poll operation // Created: 9/3/04 // - // ------------------------------------------------------------------ + // -------------------------------------------------------------------------- void FillInPoll(int &fd, short &events, int Flags = 0) const { fd = mSocketHandle; diff --git a/lib/server/SocketStream.cpp b/lib/server/SocketStream.cpp index 7faff8c3..5cb252bd 100644 --- a/lib/server/SocketStream.cpp +++ b/lib/server/SocketStream.cpp @@ -150,11 +150,9 @@ void SocketStream::Open(int Type, const char *Name, int Port) Socket::NameLookupToSockAddr(addr, sockDomain, Type, Name, Port, addrLen); // Create the socket - mSocketHandle = ::socket(sockDomain, SOCK_STREAM, - 0 /* let OS choose protocol */); + mSocketHandle = ::socket(sockDomain, SOCK_STREAM, 0 /* let OS choose protocol */); if(mSocketHandle == INVALID_SOCKET_VALUE) { - BOX_LOG_SYS_ERROR("Failed to create a network socket"); THROW_EXCEPTION(ServerException, SocketOpenError) } @@ -165,15 +163,22 @@ void SocketStream::Open(int Type, const char *Name, int Port) #ifdef WIN32 DWORD err = WSAGetLastError(); ::closesocket(mSocketHandle); - BOX_LOG_WIN_ERROR_NUMBER("Failed to connect to socket " - "(type " << Type << ", name " << Name << - ", port " << Port << ")", err); -#else // !WIN32 - BOX_LOG_SYS_ERROR("Failed to connect to socket (type " << - Type << ", name " << Name << ", port " << Port << - ")"); +#else + int err = errno; ::close(mSocketHandle); -#endif // WIN32 +#endif + +#ifdef WIN32 + BOX_ERROR("Failed to connect to socket (type " << Type << + ", name " << Name << ", port " << Port << "): " << + GetErrorMessage(err) + ); +#else + BOX_ERROR("Failed to connect to socket (type " << Type << + ", name " << Name << ", port " << Port << "): " << + strerror(err) << " (" << err << ")" + ); +#endif mSocketHandle = INVALID_SOCKET_VALUE; THROW_EXCEPTION(ConnectionException, Conn_SocketConnectError) @@ -215,9 +220,7 @@ int SocketStream::Read(void *pBuffer, int NBytes, int Timeout) else { // Bad! - BOX_LOG_SYS_ERROR("Failed to poll socket"); - THROW_EXCEPTION(ServerException, - SocketPollError) + THROW_EXCEPTION(ServerException, SocketPollError) } break; @@ -247,12 +250,9 @@ int SocketStream::Read(void *pBuffer, int NBytes, int Timeout) else { // Other error - BOX_LOG_SYS_ERROR("Failed to read from socket"); - THROW_EXCEPTION(ConnectionException, - Conn_SocketReadError); + THROW_EXCEPTION(ConnectionException, Conn_SocketReadError) } } - // Closed for reading? if(r == 0) { @@ -297,9 +297,7 @@ void SocketStream::Write(const void *pBuffer, int NBytes) { // Error. mWriteClosed = true; // assume can't write again - BOX_LOG_SYS_ERROR("Failed to write to socket"); - THROW_EXCEPTION(ConnectionException, - Conn_SocketWriteError); + THROW_EXCEPTION(ConnectionException, Conn_SocketWriteError) } // Knock off bytes sent @@ -312,9 +310,7 @@ void SocketStream::Write(const void *pBuffer, int NBytes) // Need to wait until it can send again? if(bytesLeft > 0) { - BOX_TRACE("Waiting to send data on socket " << - mSocketHandle << " (" << bytesLeft << - " of " << NBytes << " bytes left)"); + TRACE3("Waiting to send data on socket %d, (%d to send of %d)\n", mSocketHandle, bytesLeft, NBytes); // Wait for data to send. struct pollfd p; @@ -327,10 +323,7 @@ void SocketStream::Write(const void *pBuffer, int NBytes) // Don't exception if it's just a signal if(errno != EINTR) { - BOX_LOG_SYS_ERROR("Failed to poll " - "socket"); - THROW_EXCEPTION(ServerException, - SocketPollError) + THROW_EXCEPTION(ServerException, SocketPollError) } } } @@ -357,7 +350,6 @@ void SocketStream::Close() if(::close(mSocketHandle) == -1) #endif { - BOX_LOG_SYS_ERROR("Failed to close socket"); THROW_EXCEPTION(ServerException, SocketCloseError) } mSocketHandle = INVALID_SOCKET_VALUE; @@ -388,7 +380,6 @@ void SocketStream::Shutdown(bool Read, bool Write) // Shut it down! if(::shutdown(mSocketHandle, how) == -1) { - BOX_LOG_SYS_ERROR("Failed to shutdown socket"); THROW_EXCEPTION(ConnectionException, Conn_SocketShutdownError) } } @@ -467,15 +458,12 @@ bool SocketStream::GetPeerCredentials(uid_t &rUidOut, gid_t &rGidOut) struct ucred cred; socklen_t credLen = sizeof(cred); - if(::getsockopt(mSocketHandle, SOL_SOCKET, SO_PEERCRED, &cred, - &credLen) == 0) + if(::getsockopt(mSocketHandle, SOL_SOCKET, SO_PEERCRED, &cred, &credLen) == 0) { rUidOut = cred.uid; rGidOut = cred.gid; return true; } - - BOX_LOG_SYS_ERROR("Failed to get peer credentials on socket"); #endif // Not available -- cgit v1.2.3