diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/backupclient/BackupClientRestore.cpp | 10 | ||||
-rw-r--r-- | lib/backupstore/BackupProtocol.h | 2 | ||||
-rw-r--r-- | lib/backupstore/BackupStoreContext.cpp | 5 | ||||
-rw-r--r-- | lib/backupstore/BackupStoreDirectory.cpp | 3 | ||||
-rw-r--r-- | lib/backupstore/BackupStoreFileDiff.cpp | 18 | ||||
-rw-r--r-- | lib/backupstore/BackupStoreFileEncodeStream.cpp | 11 | ||||
-rw-r--r-- | lib/common/BoxTime.h | 4 | ||||
-rw-r--r-- | lib/common/DebugMemLeakFinder.cpp | 3 | ||||
-rw-r--r-- | lib/common/FileStream.cpp | 2 | ||||
-rw-r--r-- | lib/common/IOStream.h | 5 | ||||
-rw-r--r-- | lib/common/ReadLoggingStream.h | 2 | ||||
-rw-r--r-- | lib/common/Test.cpp | 32 | ||||
-rw-r--r-- | lib/common/Test.h | 3 | ||||
-rw-r--r-- | lib/common/Timer.cpp | 2 | ||||
-rw-r--r-- | lib/intercept/intercept.cpp | 2 | ||||
-rw-r--r-- | lib/raidfile/RaidFileUtil.cpp | 2 | ||||
-rw-r--r-- | lib/server/ServerTLS.h | 3 | ||||
-rw-r--r-- | lib/server/SocketStream.cpp | 25 | ||||
-rw-r--r-- | lib/server/SocketStreamTLS.cpp | 15 | ||||
-rwxr-xr-x | lib/server/makeprotocol.pl.in | 2 |
20 files changed, 72 insertions, 79 deletions
diff --git a/lib/backupclient/BackupClientRestore.cpp b/lib/backupclient/BackupClientRestore.cpp index a586dc47..d3300604 100644 --- a/lib/backupclient/BackupClientRestore.cpp +++ b/lib/backupclient/BackupClientRestore.cpp @@ -224,7 +224,7 @@ static int BackupClientRestoreDir(BackupProtocolCallable &rConnection, DIRECTORY_SEPARATOR_ASCHAR + rLevel.mNextLevelLocalName); BackupClientRestoreDir(rConnection, rLevel.mNextLevelID, - rRemoteDirectoryName + '/' + + rRemoteDirectoryName + '/' + rLevel.mNextLevelLocalName, localDirname, Params, *rLevel.mpNextLevel); @@ -232,7 +232,7 @@ static int BackupClientRestoreDir(BackupProtocolCallable &rConnection, rLevel.mRestoredObjects.insert(rLevel.mNextLevelID); // Remove the level for the recursed directory - rLevel.RemoveLevel(); + rLevel.RemoveLevel(); } // Create the local directory, if not already done. @@ -299,7 +299,7 @@ static int BackupClientRestoreDir(BackupProtocolCallable &rConnection, } std::string parentDirectoryName(rLocalDirectoryName); - if(parentDirectoryName[parentDirectoryName.size() - 1] == + if(parentDirectoryName[parentDirectoryName.size() - 1] == DIRECTORY_SEPARATOR_ASCHAR) { parentDirectoryName.resize(parentDirectoryName.size() - 1); @@ -309,7 +309,7 @@ static int BackupClientRestoreDir(BackupProtocolCallable &rConnection, if(lastSlash == std::string::npos) { - // might be a forward slash separator, + // might be a forward slash separator, // especially in the unit tests! lastSlash = parentDirectoryName.rfind('/'); } @@ -889,7 +889,7 @@ int BackupClientRestore(BackupProtocolCallable &rConnection, } // Restore the directory - int result = BackupClientRestoreDir(rConnection, DirectoryID, + int result = BackupClientRestoreDir(rConnection, DirectoryID, RemoteDirectoryName, LocalDirectoryName, params, params.mResumeInfo); if (result != Restore_Complete) diff --git a/lib/backupstore/BackupProtocol.h b/lib/backupstore/BackupProtocol.h index 43f3e162..62244aae 100644 --- a/lib/backupstore/BackupProtocol.h +++ b/lib/backupstore/BackupProtocol.h @@ -31,7 +31,7 @@ private: public: BackupProtocolLocal2(int32_t AccountNumber, - const std::string& ConnectionDetails, + const std::string& ConnectionDetails, const std::string& AccountRootDir, int DiscSetNumber, bool ReadOnly) // This is rather ugly: the BackupProtocolLocal constructor must not diff --git a/lib/backupstore/BackupStoreContext.cpp b/lib/backupstore/BackupStoreContext.cpp index 5b94cd41..d9912510 100644 --- a/lib/backupstore/BackupStoreContext.cpp +++ b/lib/backupstore/BackupStoreContext.cpp @@ -350,12 +350,9 @@ BackupStoreDirectory &BackupStoreContext::GetDirectoryInternal(int64_t ObjectID) std::auto_ptr<RaidFileRead> objectFile(RaidFileRead::Open(mStoreDiscSet, filename, &revID)); ASSERT(revID != 0); - // New directory object - std::auto_ptr<BackupStoreDirectory> dir(new BackupStoreDirectory); - // Read it from the stream, then set it's revision ID BufferedStream buf(*objectFile); - dir->ReadFromStream(buf, IOStream::TimeOutInfinite); + std::auto_ptr<BackupStoreDirectory> dir(new BackupStoreDirectory(buf)); dir->SetRevisionID(revID); // Make sure the size of the directory is available for writing the dir back diff --git a/lib/backupstore/BackupStoreDirectory.cpp b/lib/backupstore/BackupStoreDirectory.cpp index 0c575c51..edef25bc 100644 --- a/lib/backupstore/BackupStoreDirectory.cpp +++ b/lib/backupstore/BackupStoreDirectory.cpp @@ -480,7 +480,8 @@ void BackupStoreDirectory::Entry::ReadFromStream(IOStream &rStream, int Timeout) { // Grab the raw bytes from the stream which compose the header en_StreamFormat entry; - if(!rStream.ReadFullBuffer(&entry, sizeof(entry), 0 /* not interested in bytes read if this fails */, Timeout)) + if(!rStream.ReadFullBuffer(&entry, sizeof(entry), + 0 /* not interested in bytes read if this fails */, Timeout)) { THROW_EXCEPTION(BackupStoreException, CouldntReadEntireStructureFromStream) } diff --git a/lib/backupstore/BackupStoreFileDiff.cpp b/lib/backupstore/BackupStoreFileDiff.cpp index f1036354..fd186e7c 100644 --- a/lib/backupstore/BackupStoreFileDiff.cpp +++ b/lib/backupstore/BackupStoreFileDiff.cpp @@ -114,20 +114,19 @@ void BackupStoreFile::MoveStreamPositionToBlockIndex(IOStream &rStream) // Function // Name: BackupStoreFile::EncodeFileDiff(const char *, int64_t, const BackupStoreFilename &, int64_t, IOStream &, int64_t *) // Purpose: Similar to EncodeFile, but takes the object ID of the file it's -// diffing from, and the index of the blocks in a stream. It'll then -// calculate which blocks can be reused from that old file. -// The timeout is the timeout value for reading the diff block index. -// If pIsCompletelyDifferent != 0, it will be set to true if the -// the two files are completely different (do not share any block), false otherwise. -// +// diffing from, and the index of the blocks in a stream. It'll then +// calculate which blocks can be reused from that old file. +// The timeout is the timeout value for reading the diff block index. +// If pIsCompletelyDifferent != 0, it will be set to true if the +// the two files are completely different (do not share any block), false otherwise. // Created: 12/1/04 // // -------------------------------------------------------------------------- std::auto_ptr<BackupStoreFileEncodeStream> BackupStoreFile::EncodeFileDiff ( const std::string& Filename, int64_t ContainerID, - const BackupStoreFilename &rStoreFilename, int64_t DiffFromObjectID, - IOStream &rDiffFromBlockIndex, int Timeout, DiffTimer *pDiffTimer, + const BackupStoreFilename &rStoreFilename, int64_t DiffFromObjectID, + IOStream &rDiffFromBlockIndex, int Timeout, DiffTimer *pDiffTimer, int64_t *pModificationTime, bool *pIsCompletelyDifferent, BackgroundTask* pBackgroundTask) { @@ -528,7 +527,7 @@ static void SearchForMatchingBlocks(IOStream &rFile, std::map<int64_t, int64_t> // Search for each block size in turn // NOTE: Do the smallest size first, so that the scheme for adding - // entries in the found list works as expected and replaces smallers block + // entries in the found list works as expected and replaces smaller blocks // with larger blocks when it finds matches at the same offset in the file. for(int s = BACKUP_FILE_DIFF_MAX_BLOCK_SIZES - 1; s >= 0; --s) { @@ -670,6 +669,7 @@ static void SearchForMatchingBlocks(IOStream &rFile, std::map<int64_t, int64_t> } else { + // Too many to log // BOX_TRACE("False alarm match of " << Sizes[s] << " bytes with hash " << hash << " at offset " << fileOffset); } diff --git a/lib/backupstore/BackupStoreFileEncodeStream.cpp b/lib/backupstore/BackupStoreFileEncodeStream.cpp index ccab8074..2b7d067a 100644 --- a/lib/backupstore/BackupStoreFileEncodeStream.cpp +++ b/lib/backupstore/BackupStoreFileEncodeStream.cpp @@ -709,11 +709,12 @@ bool BackupStoreFileEncodeStream::StreamClosed() // Created: 15/1/04 // // -------------------------------------------------------------------------- -BackupStoreFileEncodeStream::Recipe::Recipe(BackupStoreFileCreation::BlocksAvailableEntry *pBlockIndex, - int64_t NumBlocksInIndex, int64_t OtherFileID) - : mpBlockIndex(pBlockIndex), - mNumBlocksInIndex(NumBlocksInIndex), - mOtherFileID(OtherFileID) +BackupStoreFileEncodeStream::Recipe::Recipe( + BackupStoreFileCreation::BlocksAvailableEntry *pBlockIndex, + int64_t NumBlocksInIndex, int64_t OtherFileID) +: mpBlockIndex(pBlockIndex), + mNumBlocksInIndex(NumBlocksInIndex), + mOtherFileID(OtherFileID) { ASSERT((mpBlockIndex == 0) || (NumBlocksInIndex != 0)) } diff --git a/lib/common/BoxTime.h b/lib/common/BoxTime.h index 3108d809..6afaada3 100644 --- a/lib/common/BoxTime.h +++ b/lib/common/BoxTime.h @@ -10,8 +10,8 @@ #ifndef BOXTIME__H #define BOXTIME__H -// Time is presented as an unsigned 64 bit integer, in microseconds -typedef int64_t box_time_t; +// Time is presented as a signed 64 bit integer, in microseconds +typedef int64_t box_time_t; #define NANO_SEC_IN_SEC (1000000000LL) #define NANO_SEC_IN_USEC (1000) diff --git a/lib/common/DebugMemLeakFinder.cpp b/lib/common/DebugMemLeakFinder.cpp index 70026969..30b2f41f 100644 --- a/lib/common/DebugMemLeakFinder.cpp +++ b/lib/common/DebugMemLeakFinder.cpp @@ -599,9 +599,6 @@ void memleakfinder_setup_exit_report(const char *filename, const char *markertex } } - - - void add_object_block(void *block, size_t size, const char *file, int line, bool array) { InternalAllocGuard guard; diff --git a/lib/common/FileStream.cpp b/lib/common/FileStream.cpp index 6d5810dc..99b66666 100644 --- a/lib/common/FileStream.cpp +++ b/lib/common/FileStream.cpp @@ -248,7 +248,7 @@ IOStream::pos_type FileStream::BytesLeftToRead() // -------------------------------------------------------------------------- void FileStream::Write(const void *pBuffer, int NBytes, int Timeout) { - if(mOSFileHandle == INVALID_FILE) + if(mOSFileHandle == INVALID_FILE) { THROW_EXCEPTION(CommonException, FileClosed) } diff --git a/lib/common/IOStream.h b/lib/common/IOStream.h index 80915d71..65b66d71 100644 --- a/lib/common/IOStream.h +++ b/lib/common/IOStream.h @@ -54,7 +54,7 @@ public: virtual pos_type GetPosition() const; virtual void Seek(pos_type Offset, int SeekType); virtual void Close(); - + // Has all data that can be read been read? virtual bool StreamDataLeft() = 0; // Has the stream been closed (writing not possible) @@ -69,7 +69,4 @@ public: virtual std::string ToString() const; }; - #endif // IOSTREAM__H - - diff --git a/lib/common/ReadLoggingStream.h b/lib/common/ReadLoggingStream.h index 4a01a45c..bee7e1d6 100644 --- a/lib/common/ReadLoggingStream.h +++ b/lib/common/ReadLoggingStream.h @@ -49,7 +49,7 @@ public: virtual bool StreamClosed(); private: - ReadLoggingStream(const ReadLoggingStream &rToCopy) + ReadLoggingStream(const ReadLoggingStream &rToCopy) : mrSource(rToCopy.mrSource), mrLogger(rToCopy.mrLogger) { /* do not call */ } }; diff --git a/lib/common/Test.cpp b/lib/common/Test.cpp index bfa7bcb0..67c27cf3 100644 --- a/lib/common/Test.cpp +++ b/lib/common/Test.cpp @@ -136,7 +136,7 @@ int ReadPidFile(const char *pidFile) if(!TestFileNotEmpty(pidFile)) { TEST_FAIL_WITH_MESSAGE("Server didn't save PID file " - "(perhaps one was already running?)"); + "(perhaps one was already running?)"); return -1; } @@ -145,7 +145,7 @@ int ReadPidFile(const char *pidFile) FILE *f = fopen(pidFile, "r"); if(f == NULL || fscanf(f, "%d", &pid) != 1) { - TEST_FAIL_WITH_MESSAGE("Couldn't read PID file"); + TEST_FAIL_WITH_MESSAGE("Couldn't read PID file"); return -1; } fclose(f); @@ -155,7 +155,7 @@ int ReadPidFile(const char *pidFile) int LaunchServer(const std::string& rCommandLine, const char *pidFile) { - ::fprintf(stdout, "Starting server: %s\n", rCommandLine.c_str()); + BOX_INFO("Starting server: " << rCommandLine); #ifdef WIN32 @@ -189,14 +189,10 @@ int LaunchServer(const std::string& rCommandLine, const char *pidFile) free(tempCmd); - if (result == 0) - { - DWORD err = GetLastError(); - printf("Launch failed: %s: error %d\n", rCommandLine.c_str(), - (int)err); - TEST_FAIL_WITH_MESSAGE("Couldn't start server"); + TEST_THAT_OR(result != 0, + BOX_LOG_WIN_ERROR("Launch failed: " << rCommandLine); return -1; - } + ); CloseHandle(procInfo.hProcess); CloseHandle(procInfo.hThread); @@ -205,11 +201,10 @@ int LaunchServer(const std::string& rCommandLine, const char *pidFile) #else // !WIN32 - if(RunCommand(rCommandLine) != 0) - { - TEST_FAIL_WITH_MESSAGE("Couldn't start server"); + TEST_THAT_OR(RunCommand(rCommandLine) == 0, + TEST_FAIL_WITH_MESSAGE("Failed to start server: " << rCommandLine); return -1; - } + ) return WaitForServerStartup(pidFile, 0); @@ -234,7 +229,7 @@ int WaitForServerStartup(const char *pidFile, int pidIfKnown) for (int i = 0; i < 15; i++) { - if (TestFileNotEmpty(pidFile)) + if (TestFileNotEmpty(pidFile)) { break; } @@ -252,13 +247,13 @@ int WaitForServerStartup(const char *pidFile, int pidIfKnown) if (pidIfKnown && !ServerIsAlive(pidIfKnown)) { - TEST_FAIL_WITH_MESSAGE("Server died!"); + TEST_FAIL_WITH_MESSAGE("Server died!"); return -1; } if (!TestFileNotEmpty(pidFile)) { - TEST_FAIL_WITH_MESSAGE("Server didn't save PID file"); + TEST_FAIL_WITH_MESSAGE("Server didn't save PID file"); return -1; } @@ -381,7 +376,7 @@ void terminate_bbackupd(int pid) // Wait a given number of seconds for something to complete void wait_for_operation(int seconds, const char* message) { - BOX_TRACE("Waiting " << seconds << " seconds for " << message); + BOX_INFO("Waiting " << seconds << " seconds for " << message); for(int l = 0; l < seconds; ++l) { @@ -395,4 +390,3 @@ void safe_sleep(int seconds) { ShortSleep(SecondsToBoxTime(seconds), true); } - diff --git a/lib/common/Test.h b/lib/common/Test.h index dbe1e979..146fafae 100644 --- a/lib/common/Test.h +++ b/lib/common/Test.h @@ -157,6 +157,9 @@ extern std::list<std::string> run_only_named_tests; printf("Test failed on <%s>\n", _line_str.c_str()); \ } +#define TEST_STARTSWITH(expected, actual) \ + TEST_EQUAL_LINE(expected, actual.substr(0, std::string(expected).size()), actual); + bool TestFileExists(const char *Filename); bool TestDirExists(const char *Filename); diff --git a/lib/common/Timer.cpp b/lib/common/Timer.cpp index ad6b5e8d..68042db2 100644 --- a/lib/common/Timer.cpp +++ b/lib/common/Timer.cpp @@ -155,7 +155,7 @@ void Timers::Remove(Timer& rTimer) } } } - + Reschedule(); } diff --git a/lib/intercept/intercept.cpp b/lib/intercept/intercept.cpp index 7a33b610..ee79fe00 100644 --- a/lib/intercept/intercept.cpp +++ b/lib/intercept/intercept.cpp @@ -132,7 +132,7 @@ void intercept_setup_error(const char *filename, unsigned int errorafter, int er intercept_delay_ms = 0; } -void intercept_setup_delay(const char *filename, unsigned int delay_after, +void intercept_setup_delay(const char *filename, unsigned int delay_after, int delay_ms, int syscall_to_delay, int num_delays) { BOX_TRACE("Setup for delay: " << filename << diff --git a/lib/raidfile/RaidFileUtil.cpp b/lib/raidfile/RaidFileUtil.cpp index 7c6299ec..e826e7d0 100644 --- a/lib/raidfile/RaidFileUtil.cpp +++ b/lib/raidfile/RaidFileUtil.cpp @@ -14,7 +14,7 @@ #include "RaidFileUtil.h" #include "FileModificationTime.h" -#include "RaidFileRead.h" // for type definition +#include "RaidFileRead.h" // for type definition #include "MemLeakFindOn.h" diff --git a/lib/server/ServerTLS.h b/lib/server/ServerTLS.h index 20e55964..f748f4b2 100644 --- a/lib/server/ServerTLS.h +++ b/lib/server/ServerTLS.h @@ -52,7 +52,8 @@ public: std::string certFile(serverconf.GetKeyValue("CertificateFile")); std::string keyFile(serverconf.GetKeyValue("PrivateKeyFile")); std::string caFile(serverconf.GetKeyValue("TrustedCAsFile")); - mContext.Initialise(true /* as server */, certFile.c_str(), keyFile.c_str(), caFile.c_str()); + mContext.Initialise(true /* as server */, certFile.c_str(), + keyFile.c_str(), caFile.c_str()); // Then do normal stream server stuff ServerStream<SocketStreamTLS, Port, ListenBacklog, diff --git a/lib/server/SocketStream.cpp b/lib/server/SocketStream.cpp index db71227f..ab0a54ae 100644 --- a/lib/server/SocketStream.cpp +++ b/lib/server/SocketStream.cpp @@ -323,15 +323,15 @@ bool SocketStream::Poll(short Events, int Timeout) // -------------------------------------------------------------------------- void SocketStream::Write(const void *pBuffer, int NBytes, int Timeout) { - if(mSocketHandle == INVALID_SOCKET_VALUE) + if(mSocketHandle == INVALID_SOCKET_VALUE) { THROW_EXCEPTION(ServerException, BadSocketHandle) } - + // Buffer in byte sized type. ASSERT(sizeof(char) == 1); const char *buffer = (char *)pBuffer; - + // Bytes left to send int bytesLeft = NBytes; box_time_t start = GetCurrentBoxTime(); @@ -348,22 +348,21 @@ void SocketStream::Write(const void *pBuffer, int NBytes, int Timeout) { // Error. mWriteClosed = true; // assume can't write again - BOX_LOG_SYS_ERROR("Failed to write to socket"); - THROW_EXCEPTION(ConnectionException, - SocketWriteError); + THROW_SYS_ERROR("Failed to write to socket", + ConnectionException, SocketWriteError); } - + // Knock off bytes sent bytesLeft -= sent; // Move buffer pointer buffer += sent; mBytesWritten += sent; - + // Need to wait until it can send again? if(bytesLeft > 0) { - BOX_TRACE("Waiting to send data on socket " << + BOX_TRACE("Waiting to send data on socket " << mSocketHandle << " (" << bytesLeft << " of " << NBytes << " bytes left)"); @@ -388,7 +387,7 @@ void SocketStream::Write(const void *pBuffer, int NBytes, int Timeout) // -------------------------------------------------------------------------- void SocketStream::Close() { - if(mSocketHandle == INVALID_SOCKET_VALUE) + if(mSocketHandle == INVALID_SOCKET_VALUE) { THROW_EXCEPTION(ServerException, BadSocketHandle) } @@ -419,14 +418,14 @@ void SocketStream::Shutdown(bool Read, bool Write) { THROW_EXCEPTION(ServerException, BadSocketHandle) } - + // Do anything? if(!Read && !Write) return; - + int how = SHUT_RDWR; if(Read && !Write) how = SHUT_RD; if(!Read && Write) how = SHUT_WR; - + // Shut it down! if(::shutdown(mSocketHandle, how) == -1) { diff --git a/lib/server/SocketStreamTLS.cpp b/lib/server/SocketStreamTLS.cpp index e31ac13f..953012d1 100644 --- a/lib/server/SocketStreamTLS.cpp +++ b/lib/server/SocketStreamTLS.cpp @@ -132,7 +132,7 @@ void SocketStreamTLS::Handshake(const TLSContext &rContext, bool IsServer) tOSSocketHandle socket = GetSocketHandle(); BIO_set_fd(mpBIO, socket, BIO_NOCLOSE); - + // Then the SSL object mpSSL = ::SSL_new(rContext.GetRawContext()); if(mpSSL == 0) @@ -155,7 +155,7 @@ void SocketStreamTLS::Handshake(const TLSContext &rContext, bool IsServer) THROW_EXCEPTION(ServerException, SocketSetNonBlockingFailed) } #endif - + // FIXME: This is less portable than the above. However, it MAY be needed // for cygwin, which has/had bugs with fcntl // @@ -223,8 +223,9 @@ void SocketStreamTLS::Handshake(const TLSContext &rContext, bool IsServer) // // Function // Name: WaitWhenRetryRequired(int, int) -// Purpose: Waits until the condition required by the TLS layer is met. -// Returns true if the condition is met, false if timed out. +// Purpose: Waits until the condition required by the TLS layer +// is met. Returns true if the condition is met, false +// if timed out. // Created: 2003/08/15 // // -------------------------------------------------------------------------- @@ -320,20 +321,20 @@ int SocketStreamTLS::Read(void *pBuffer, int NBytes, int Timeout) void SocketStreamTLS::Write(const void *pBuffer, int NBytes, int Timeout) { if(!mpSSL) {THROW_EXCEPTION(ServerException, TLSNoSSLObject)} - + // Make sure zero byte writes work as expected if(NBytes == 0) { return; } - + // from man SSL_write // // SSL_write() will only return with success, when the // complete contents of buf of length num has been written. // // So no worries about partial writes and moving the buffer around - + while(true) { // try the write diff --git a/lib/server/makeprotocol.pl.in b/lib/server/makeprotocol.pl.in index 7dfab7b3..ed0f1ee6 100755 --- a/lib/server/makeprotocol.pl.in +++ b/lib/server/makeprotocol.pl.in @@ -811,10 +811,12 @@ foreach my $type ('Client', 'Server', 'Local') { push @base_classes, $replyable_base_class; } + if (not $writing_server) { push @base_classes, $callable_base_class; } + if (not $writing_local) { push @base_classes, $custom_protocol_subclass; |