diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/backupclient/BackupClientFileAttributes.cpp | 13 | ||||
-rw-r--r-- | lib/backupclient/BackupClientRestore.cpp | 184 | ||||
-rw-r--r-- | lib/backupclient/BackupStoreFile.cpp | 7 | ||||
-rw-r--r-- | lib/common/BoxTime.cpp | 9 | ||||
-rw-r--r-- | lib/common/DebugPrintf.cpp | 6 | ||||
-rw-r--r-- | lib/common/Logging.h | 14 | ||||
-rw-r--r-- | lib/raidfile/RaidFileRead.cpp | 41 | ||||
-rw-r--r-- | lib/server/Daemon.cpp | 7 | ||||
-rw-r--r-- | lib/server/LocalProcessStream.cpp | 8 | ||||
-rw-r--r-- | lib/server/SSLLib.cpp | 13 | ||||
-rw-r--r-- | lib/server/ServerStream.h | 16 | ||||
-rw-r--r-- | lib/server/Socket.cpp | 9 | ||||
-rw-r--r-- | lib/server/WinNamedPipeStream.cpp | 89 |
13 files changed, 180 insertions, 236 deletions
diff --git a/lib/backupclient/BackupClientFileAttributes.cpp b/lib/backupclient/BackupClientFileAttributes.cpp index 9918c0d6..925d1620 100644 --- a/lib/backupclient/BackupClientFileAttributes.cpp +++ b/lib/backupclient/BackupClientFileAttributes.cpp @@ -344,8 +344,8 @@ void BackupClientFileAttributes::ReadAttributes(const char *Filename, bool ZeroM // to be true (still aborts), but it can at least hold 2^32. if (winTime >= 0x100000000LL || _gmtime64(&winTime) == 0) { - ::syslog(LOG_ERR, "Invalid Modification Time " - "caught for file: %s", Filename); + BOX_ERROR("Invalid Modification Time caught for " + "file: '" << Filename << "'"); pattr->ModificationTime = 0; } @@ -355,8 +355,8 @@ void BackupClientFileAttributes::ReadAttributes(const char *Filename, bool ZeroM if (winTime > 0x100000000LL || _gmtime64(&winTime) == 0) { - ::syslog(LOG_ERR, "Invalid Attribute Modification " - "Time caught for file: %s", Filename); + BOX_ERROR("Invalid Attribute Modification Time " + "caught for file: '" << Filename << "'"); pattr->AttrModificationTime = 0; } #endif @@ -627,9 +627,8 @@ void BackupClientFileAttributes::WriteAttributes(const char *Filename, } #ifdef WIN32 - ::syslog(LOG_WARNING, - "Cannot create symbolic links on Windows: %s", - Filename); + BOX_WARNING("Cannot create symbolic links on Windows: '" << + Filename << "'"); #else // Make a symlink, first deleting anything in the way ::unlink(Filename); diff --git a/lib/backupclient/BackupClientRestore.cpp b/lib/backupclient/BackupClientRestore.cpp index 9b3a3edc..92853624 100644 --- a/lib/backupclient/BackupClientRestore.cpp +++ b/lib/backupclient/BackupClientRestore.cpp @@ -235,20 +235,20 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir } catch (BoxException &e) { - ::syslog(LOG_ERR, "Failed to check existence for %s: %s", - rLocalDirectoryName.c_str(), e.what()); + BOX_ERROR("Failed to check existence for " << + rLocalDirectoryName << ": " << e.what()); return Restore_UnknownError; } catch(std::exception &e) { - ::syslog(LOG_ERR, "Failed to check existence for %s: %s", - rLocalDirectoryName.c_str(), e.what()); + BOX_ERROR("Failed to check existence for " << + rLocalDirectoryName << ": " << e.what()); return Restore_UnknownError; } catch(...) { - ::syslog(LOG_ERR, "Failed to check existence for %s: " - "unknown error", rLocalDirectoryName.c_str()); + BOX_ERROR("Failed to check existence for " << + rLocalDirectoryName << ": unknown error"); return Restore_UnknownError; } @@ -263,13 +263,14 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir ::printf("WARNING: File present with name '%s', removing out of the way of restored directory. Use specific restore with ID to restore this object.", rLocalDirectoryName.c_str()); if(::unlink(rLocalDirectoryName.c_str()) != 0) { - ::syslog(LOG_ERR, "Failed to delete " - "file %s: %s", - rLocalDirectoryName.c_str(), + BOX_ERROR("Failed to delete file " << + rLocalDirectoryName << ": " << strerror(errno)); return Restore_UnknownError; } - TRACE1("In restore, directory name collision with file %s", rLocalDirectoryName.c_str()); + BOX_TRACE("In restore, directory name " + "collision with file " << + rLocalDirectoryName); } break; case ObjectExists_NoObject: @@ -325,20 +326,20 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir } catch (BoxException &e) { - ::syslog(LOG_ERR, "Failed to check existence for %s: " - "%s", parentDirectoryName.c_str(), e.what()); + BOX_ERROR("Failed to check existence for " << + parentDirectoryName << ": " << e.what()); return Restore_UnknownError; } catch(std::exception &e) { - ::syslog(LOG_ERR, "Failed to check existence for %s: " - "%s", parentDirectoryName.c_str(), e.what()); + BOX_ERROR("Failed to check existence for " << + parentDirectoryName << ": " << e.what()); return Restore_UnknownError; } catch(...) { - ::syslog(LOG_ERR, "Failed to check existence for %s: " - "unknown error", parentDirectoryName.c_str()); + BOX_ERROR("Failed to check existence for " << + parentDirectoryName << ": unknown error"); return Restore_UnknownError; } @@ -349,24 +350,22 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir break; case ObjectExists_File: - fprintf(stderr, "Failed to restore: '%s' " + BOX_ERROR("Failed to restore: '" << + parentDirectoryName << "' " "is a file, but should be a " - "directory.\n", - parentDirectoryName.c_str()); + "directory."); return Restore_TargetPathNotFound; case ObjectExists_NoObject: - fprintf(stderr, "Failed to restore: " - "parent '%s' of target directory " - "does not exist.\n", - parentDirectoryName.c_str()); + BOX_ERROR("Failed to restore: parent '" << + parentDirectoryName << "' of target " + "directory does not exist."); return Restore_TargetPathNotFound; default: - fprintf(stderr, "Failed to restore: " - "unknown result from " - "ObjectExists('%s').\n", - parentDirectoryName.c_str()); + BOX_ERROR("Failed to restore: unknown " + "result from ObjectExists('" << + parentDirectoryName << "')"); return Restore_UnknownError; } } @@ -375,8 +374,8 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir exists == ObjectExists_File) && ::mkdir(rLocalDirectoryName.c_str(), S_IRWXU) != 0) { - ::syslog(LOG_ERR, "Failed to create directory %s: %s", - rLocalDirectoryName.c_str(), + BOX_ERROR("Failed to create directory '" << + rLocalDirectoryName << "': " << strerror(errno)); return Restore_UnknownError; } @@ -386,23 +385,18 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir { Params.mResumeInfo.Save(Params.mRestoreResumeInfoFilename); } - catch (BoxException &e) - { - ::syslog(LOG_ERR, "Failed to save resume info file %s: %s", - Params.mRestoreResumeInfoFilename.c_str(), e.what()); - return Restore_UnknownError; - } catch(std::exception &e) { - ::syslog(LOG_ERR, "Failed to save resume info file %s: %s", - Params.mRestoreResumeInfoFilename.c_str(), e.what()); + BOX_ERROR("Failed to save resume info file '" << + Params.mRestoreResumeInfoFilename << "': " << + e.what()); return Restore_UnknownError; } catch(...) { - ::syslog(LOG_ERR, "Failed to save resume info file %s: " - "unknown error", - Params.mRestoreResumeInfoFilename.c_str()); + BOX_ERROR("Failed to save resume info file '" << + Params.mRestoreResumeInfoFilename << + "': unknown error"); return Restore_UnknownError; } @@ -427,22 +421,16 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir { dirAttr.WriteAttributes(rLocalDirectoryName.c_str(), true); } - catch (BoxException &e) - { - ::syslog(LOG_ERR, "Failed to restore attributes for %s: %s", - rLocalDirectoryName.c_str(), e.what()); - return Restore_UnknownError; - } catch(std::exception &e) { - ::syslog(LOG_ERR, "Failed to restore attributes for %s: %s", - rLocalDirectoryName.c_str(), e.what()); + BOX_ERROR("Failed to restore attributes for '" << + rLocalDirectoryName << "': " << e.what()); return Restore_UnknownError; } catch(...) { - ::syslog(LOG_ERR, "Failed to restore attributes for %s: " - "unknown error", rLocalDirectoryName.c_str()); + BOX_ERROR("Failed to restore attributes for '" << + rLocalDirectoryName << "': unknown error"); return Restore_UnknownError; } @@ -464,9 +452,8 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir // Unlink anything which already exists -- for resuming restores, we can't overwrite files already there. if(::unlink(localFilename.c_str()) == 0) { - ::syslog(LOG_ERR, "Failed to delete " - "file %s: %s", - localFilename.c_str(), + BOX_ERROR("Failed to delete file '" << + localFilename << "': " << strerror(errno)); return Restore_UnknownError; } @@ -494,27 +481,18 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir BackupStoreFile::DecodeFile(*objectStream, localFilename.c_str(), rConnection.GetTimeout()); } } - catch (BoxException &e) - { - ::syslog(LOG_ERR, "Failed to restore " - "file %s: %s", - localFilename.c_str(), - e.what()); - return Restore_UnknownError; - } catch(std::exception &e) { - ::syslog(LOG_ERR, "Failed to restore " - "file %s: %s", - localFilename.c_str(), + BOX_ERROR("Failed to restore file '" << + localFilename << "': " << e.what()); return Restore_UnknownError; } catch(...) { - ::syslog(LOG_ERR, "Failed to restore " - "file %s: unknown error", - localFilename.c_str()); + BOX_ERROR("Failed to restore file '" << + localFilename << + "': unknown error"); return Restore_UnknownError; } @@ -540,28 +518,20 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir true /* treat links as not existing */); } - catch (BoxException &e) - { - ::syslog(LOG_ERR, "Failed to determine " - "whether file exists: %s: %s", - localFilename.c_str(), - e.what()); - return Restore_UnknownError; - } catch(std::exception &e) { - ::syslog(LOG_ERR, "Failed to determine " - "whether file exists: %s: %s", - localFilename.c_str(), + BOX_ERROR("Failed to determine " + "whether file exists: '" << + localFilename << "': " << e.what()); return Restore_UnknownError; } catch(...) { - ::syslog(LOG_ERR, "Failed to determine " - "whether file exists: %s: " - "unknown error", - localFilename.c_str()); + BOX_ERROR("Failed to determine " + "whether file exists: '" << + localFilename << "': " + "unknown error"); return Restore_UnknownError; } @@ -577,23 +547,18 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir { Params.mResumeInfo.Save(Params.mRestoreResumeInfoFilename); } - catch (BoxException &e) - { - ::syslog(LOG_ERR, "Failed to save resume info file %s: %s", - Params.mRestoreResumeInfoFilename.c_str(), e.what()); - return Restore_UnknownError; - } catch(std::exception &e) { - ::syslog(LOG_ERR, "Failed to save resume info file %s: %s", - Params.mRestoreResumeInfoFilename.c_str(), e.what()); + BOX_ERROR("Failed to save resume info file '" << + Params.mRestoreResumeInfoFilename << + "': " << e.what()); return Restore_UnknownError; } catch(...) { - ::syslog(LOG_ERR, "Failed to save resume info file %s: " - "unknown error", - Params.mRestoreResumeInfoFilename.c_str()); + BOX_ERROR("Failed to save resume info file '" << + Params.mRestoreResumeInfoFilename << + "': unknown error"); return Restore_UnknownError; } @@ -613,27 +578,18 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir Params.mResumeInfo.Save( Params.mRestoreResumeInfoFilename); } - catch (BoxException &e) - { - ::syslog(LOG_ERR, "Failed to save resume info file " - "%s: %s", - Params.mRestoreResumeInfoFilename.c_str(), - e.what()); - return Restore_UnknownError; - } catch(std::exception &e) { - ::syslog(LOG_ERR, "Failed to save resume info file " - "%s: %s", - Params.mRestoreResumeInfoFilename.c_str(), + BOX_ERROR("Failed to save resume info file '" << + Params.mRestoreResumeInfoFilename << "': " << e.what()); return Restore_UnknownError; } catch(...) { - ::syslog(LOG_ERR, "Failed to save resume info file " - "%s: unknown error", - Params.mRestoreResumeInfoFilename.c_str()); + BOX_ERROR("Failed to save resume info file '" << + Params.mRestoreResumeInfoFilename << + "': unknown error"); return Restore_UnknownError; } @@ -681,22 +637,16 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir { dirAttr.WriteAttributes(rLocalDirectoryName.c_str(), false); } - catch (BoxException &e) - { - ::syslog(LOG_ERR, "Failed to restore attributes for %s: %s", - rLocalDirectoryName.c_str(), e.what()); - return Restore_UnknownError; - } catch(std::exception &e) { - ::syslog(LOG_ERR, "Failed to restore attributes for %s: %s", - rLocalDirectoryName.c_str(), e.what()); + BOX_ERROR("Failed to restore attributes for '" << + rLocalDirectoryName << "': " << e.what()); return Restore_UnknownError; } catch(...) { - ::syslog(LOG_ERR, "Failed to restore attributes for %s: " - "unknown error", rLocalDirectoryName.c_str()); + BOX_ERROR("Failed to restore attributes for '" << + rLocalDirectoryName << "': unknown error"); return Restore_UnknownError; } diff --git a/lib/backupclient/BackupStoreFile.cpp b/lib/backupclient/BackupStoreFile.cpp index 75095fa4..7e93d59d 100644 --- a/lib/backupclient/BackupStoreFile.cpp +++ b/lib/backupclient/BackupStoreFile.cpp @@ -17,10 +17,8 @@ #include <string.h> #include <new> #include <string.h> + #ifndef BOX_DISABLE_BACKWARDS_COMPATIBILITY_BACKUPSTOREFILE - #ifndef WIN32 - #include <syslog.h> - #endif #include <stdio.h> #endif @@ -758,8 +756,7 @@ int BackupStoreFile::DecodedStream::Read(void *pBuffer, int NBytes, int Timeout) // Warn and log this issue if(!sWarnedAboutBackwardsCompatiblity) { - ::printf("WARNING: Decoded one or more files using backwards compatibility mode for block index.\n"); - ::syslog(LOG_ERR, "WARNING: Decoded one or more files using backwards compatibility mode for block index.\n"); + BOX_WARNING("WARNING: Decoded one or more files using backwards compatibility mode for block index."); sWarnedAboutBackwardsCompatiblity = true; } } diff --git a/lib/common/BoxTime.cpp b/lib/common/BoxTime.cpp index eafb244f..1ddcffd4 100644 --- a/lib/common/BoxTime.cpp +++ b/lib/common/BoxTime.cpp @@ -12,12 +12,11 @@ #ifdef HAVE_SYS_TIME_H #include <sys/time.h> #endif + #ifdef HAVE_TIME_H #include <time.h> #endif -#ifdef HAVE_SYSLOG_H - #include <syslog.h> -#endif + #include <errno.h> #include <string.h> @@ -40,8 +39,8 @@ box_time_t GetCurrentBoxTime() struct timeval tv; if (gettimeofday(&tv, NULL) != 0) { - ::syslog(LOG_ERR, "gettimeofday() failed (%s), " - "dropping precision", strerror(errno)); + BOX_ERROR("Failed to gettimeofday(), dropping " + "precision: " << strerror(errno)); } else { diff --git a/lib/common/DebugPrintf.cpp b/lib/common/DebugPrintf.cpp index 8d75f458..14cd3534 100644 --- a/lib/common/DebugPrintf.cpp +++ b/lib/common/DebugPrintf.cpp @@ -14,12 +14,6 @@ #include <stdio.h> #include <stdarg.h> -#ifdef WIN32 - #include "emu.h" -#else - #include <syslog.h> -#endif - #include "MemLeakFindOn.h" // Use this apparently superflous printf function to avoid having to diff --git a/lib/common/Logging.h b/lib/common/Logging.h index aea488a5..e87d1d4f 100644 --- a/lib/common/Logging.h +++ b/lib/common/Logging.h @@ -10,6 +10,7 @@ #ifndef LOGGING__H #define LOGGING__H +#include <iomanip> #include <sstream> #include <vector> @@ -42,6 +43,19 @@ #define BOX_TRACE(stuff) BOX_LOG(Log::TRACE, stuff) #endif +#define BOX_FORMAT_ACCOUNT(accno) \ + std::hex << \ + std::showbase << \ + std::internal << \ + std::setw(8) << \ + std::setfill('0') << \ + (accno) + +#define BOX_FORMAT_OBJECTID(objectid) \ + std::hex << \ + std::showbase << \ + (objectid) + #undef ERROR namespace Log diff --git a/lib/raidfile/RaidFileRead.cpp b/lib/raidfile/RaidFileRead.cpp index 58aecfb1..187270f9 100644 --- a/lib/raidfile/RaidFileRead.cpp +++ b/lib/raidfile/RaidFileRead.cpp @@ -21,10 +21,6 @@ #include <sys/uio.h> #endif -#ifdef HAVE_SYSLOG_H - #include <syslog.h> -#endif - #ifdef HAVE_DIRENT_H #include <dirent.h> #endif @@ -548,8 +544,8 @@ void RaidFileRead_Raid::MoveDamagedFileAlertDaemon(int SetNumber, const std::str // -------------------------------------------------------------------------- void RaidFileRead_Raid::AttemptToRecoverFromIOError(bool Stripe1) { - TRACE3("Attempting to recover from I/O error: %d %s, on stripe %d\n", mSetNumber, mFilename.c_str(), Stripe1?1:2); - ::syslog(LOG_ERR | LOG_LOCAL5, "Attempting to recover from I/O error: %d %s, on stripe %d\n", mSetNumber, mFilename.c_str(), Stripe1?1:2); + BOX_WARNING("Attempting to recover from I/O error: " << mSetNumber << + " " << mFilename << ", on stripe " << (Stripe1?1:2)); // Close offending file if(Stripe1) @@ -861,8 +857,10 @@ void RaidFileRead_Raid::SetPosition(pos_type FilePosition) { if(errno == EIO) { - TRACE3("I/O error when seeking in %d %s (to %d), stripe 1\n", mSetNumber, mFilename.c_str(), (int)FilePosition); - ::syslog(LOG_ERR | LOG_LOCAL5, "I/O error when seeking in %d %s (to %d), stripe 1\n", mSetNumber, mFilename.c_str(), (int)FilePosition); + BOX_ERROR("I/O error when seeking in " << + mSetNumber << " " << mFilename << + " (to " << FilePosition << "), " << + "stripe 1"); // Attempt to recover AttemptToRecoverFromIOError(true /* is stripe 1 */); ASSERT(mStripe1Handle == -1); @@ -879,8 +877,10 @@ void RaidFileRead_Raid::SetPosition(pos_type FilePosition) { if(errno == EIO) { - TRACE3("I/O error when seeking in %d %s (to %d), stripe 2\n", mSetNumber, mFilename.c_str(), (int)FilePosition); - ::syslog(LOG_ERR | LOG_LOCAL5, "I/O error when seeking in %d %s (to %d), stripe 2\n", mSetNumber, mFilename.c_str(), (int)FilePosition); + BOX_ERROR("I/O error when seeking in " << + mSetNumber << " " << mFilename << + " (to " << FilePosition << "), " << + "stripe 2"); // Attempt to recover AttemptToRecoverFromIOError(false /* is stripe 2 */); ASSERT(mStripe2Handle == -1); @@ -1054,8 +1054,9 @@ std::auto_ptr<RaidFileRead> RaidFileRead::Open(int SetNumber, const std::string { if(existance != RaidFileUtil::AsRaid) { - TRACE2("Opening %d %s in normal mode, but parity file doesn't exist\n", SetNumber, Filename.c_str()); - ::syslog(LOG_ERR | LOG_LOCAL5, "Opening %d %s in normal mode, but parity file doesn't exist\n", SetNumber, Filename.c_str()); + BOX_ERROR("Opening " << SetNumber << " " << + Filename << " in normal mode, but " + "parity file doesn't exist"); // TODO: Alert recovery daemon } @@ -1130,8 +1131,9 @@ std::auto_ptr<RaidFileRead> RaidFileRead::Open(int SetNumber, const std::string bool oktotryagain = true; if(stripe1errno == EIO) { - TRACE2("I/O error on opening %d %s stripe 1, trying recovery mode\n", SetNumber, Filename.c_str()); - ::syslog(LOG_ERR | LOG_LOCAL5, "I/O error on opening %d %s stripe 1, trying recovery mode\n", SetNumber, Filename.c_str()); + BOX_ERROR("I/O error on opening " << + SetNumber << " " << Filename << + " stripe 1, trying recovery mode"); RaidFileRead_Raid::MoveDamagedFileAlertDaemon(SetNumber, Filename, true /* is stripe 1 */); existingFiles = existingFiles & ~RaidFileUtil::Stripe1Exists; @@ -1146,8 +1148,9 @@ std::auto_ptr<RaidFileRead> RaidFileRead::Open(int SetNumber, const std::string if(stripe2errno == EIO) { - TRACE2("I/O error on opening %d %s stripe 2, trying recovery mode\n", SetNumber, Filename.c_str()); - ::syslog(LOG_ERR | LOG_LOCAL5, "I/O error on opening %d %s stripe 2, trying recovery mode\n", SetNumber, Filename.c_str()); + BOX_ERROR("I/O error on opening " << + SetNumber << " " << Filename << + " stripe 2, trying recovery mode"); RaidFileRead_Raid::MoveDamagedFileAlertDaemon(SetNumber, Filename, false /* is stripe 2 */); existingFiles = existingFiles & ~RaidFileUtil::Stripe2Exists; @@ -1169,8 +1172,10 @@ std::auto_ptr<RaidFileRead> RaidFileRead::Open(int SetNumber, const std::string if(existance == RaidFileUtil::AsRaidWithMissingReadable) { - TRACE3("Attempting to open RAID file %d %s in recovery mode (stripe %d present)\n", SetNumber, Filename.c_str(), (existingFiles & RaidFileUtil::Stripe1Exists)?1:2); - ::syslog(LOG_ERR | LOG_LOCAL5, "Attempting to open RAID file %d %s in recovery mode (stripe %d present)\n", SetNumber, Filename.c_str(), (existingFiles & RaidFileUtil::Stripe1Exists)?1:2); + BOX_ERROR("Attempting to open RAID file " << SetNumber << + " " << Filename << " in recovery mode (stripe " << + ((existingFiles & RaidFileUtil::Stripe1Exists)?1:2) << + " present)"); // Generate the filenames of all the lovely files std::string stripe1Filename(RaidFileUtil::MakeRaidComponentName(rdiscSet, Filename, (0 + startDisc) % READ_NUMBER_DISCS_REQUIRED)); diff --git a/lib/server/Daemon.cpp b/lib/server/Daemon.cpp index 147eeb24..a9eb5bf5 100644 --- a/lib/server/Daemon.cpp +++ b/lib/server/Daemon.cpp @@ -19,10 +19,6 @@ #include <string.h> #include <stdarg.h> -#ifdef HAVE_SYSLOG_H - #include <syslog.h> -#endif - #ifdef WIN32 #include <ws2tcpip.h> #endif @@ -353,7 +349,8 @@ int Daemon::Main(const std::string &rConfigFileName) // Set new session if(::setsid() == -1) { - ::syslog(LOG_ERR, "can't setsid"); + BOX_ERROR("Failed to setsid(): " << + strerror(errno)); THROW_EXCEPTION(ServerException, DaemoniseFailed) } diff --git a/lib/server/LocalProcessStream.cpp b/lib/server/LocalProcessStream.cpp index fef7166b..9750aca1 100644 --- a/lib/server/LocalProcessStream.cpp +++ b/lib/server/LocalProcessStream.cpp @@ -120,8 +120,8 @@ std::auto_ptr<IOStream> LocalProcessStream(const char *CommandLine, pid_t &rPidO HANDLE writeInChild, readFromChild; if(!CreatePipe(&readFromChild, &writeInChild, &secAttr, 0)) { - ::syslog(LOG_ERR, "Failed to CreatePipe for child process: " - "error %d", GetLastError()); + BOX_ERROR("Failed to CreatePipe for child process: " + GetErrorMessage(GetLastError())); THROW_EXCEPTION(ServerException, SocketPairFailed) } SetHandleInformation(readFromChild, HANDLE_FLAG_INHERIT, 0); @@ -155,8 +155,8 @@ std::auto_ptr<IOStream> LocalProcessStream(const char *CommandLine, pid_t &rPidO if(!result) { - ::syslog(LOG_ERR, "Failed to CreateProcess: '%s': " - "error %d", CommandLine, GetLastError()); + BOX_ERROR("Failed to CreateProcess: '" << CommandLine << + "': " << GetErrorMessage(GetLastError())); CloseHandle(writeInChild); CloseHandle(readFromChild); THROW_EXCEPTION(ServerException, ServerForkError) diff --git a/lib/server/SSLLib.cpp b/lib/server/SSLLib.cpp index 2a5bdbde..6082a9f4 100644 --- a/lib/server/SSLLib.cpp +++ b/lib/server/SSLLib.cpp @@ -14,10 +14,6 @@ #include <openssl/err.h> #include <openssl/rand.h> -#ifndef WIN32 -#include <syslog.h> -#endif - #include "SSLLib.h" #include "ServerException.h" @@ -73,13 +69,8 @@ void SSLLib::LogError(const char *ErrorDuringAction) while((errcode = ERR_get_error()) != 0) { ::ERR_error_string_n(errcode, errname, sizeof(errname)); - #ifndef NDEBUG - if(SSLLib__TraceErrors) - { - TRACE2("SSL err during %s: %s\n", ErrorDuringAction, errname); - } - #endif - ::syslog(LOG_ERR, "SSL err during %s: %s", ErrorDuringAction, errname); + BOX_ERROR("SSL error during " << ErrorDuringAction << ": " << + errname); } } diff --git a/lib/server/ServerStream.h b/lib/server/ServerStream.h index 7eb99d13..5f615336 100644 --- a/lib/server/ServerStream.h +++ b/lib/server/ServerStream.h @@ -14,7 +14,6 @@ #include <errno.h> #ifndef WIN32 - #include <syslog.h> #include <sys/wait.h> #endif @@ -73,7 +72,10 @@ public: { if(childExit) { - ::syslog(LOG_ERR, "in server child, exception %s (%d/%d) -- terminating child", e.what(), e.GetType(), e.GetSubType()); + BOX_ERROR("Error in child process, " + "terminating connection: exception " << + e.what() << "(" << e.GetType() << + "/" << e.GetSubType() << ")"); _exit(1); } else throw; @@ -82,7 +84,9 @@ public: { if(childExit) { - ::syslog(LOG_ERR, "in server child, exception %s -- terminating child", e.what()); + BOX_ERROR("Error in child process, " + "terminating connection: exception " << + e.what()); _exit(1); } else throw; @@ -91,7 +95,9 @@ public: { if(childExit) { - ::syslog(LOG_ERR, "in server child, unknown exception -- terminating child"); + BOX_ERROR("Error in child process, " + "terminating connection: " + "unknown exception"); _exit(1); } else throw; @@ -266,7 +272,7 @@ public: } // Log it - ::syslog(LOG_INFO, "%s (handling in child %d)", logMessage.c_str(), pid); + BOX_WARNING("Error message from child process " << pid << ": " << logMessage); } else { diff --git a/lib/server/Socket.cpp b/lib/server/Socket.cpp index afed4888..28dae69f 100644 --- a/lib/server/Socket.cpp +++ b/lib/server/Socket.cpp @@ -17,7 +17,6 @@ #ifndef WIN32 #include <sys/socket.h> #include <netdb.h> -#include <syslog.h> #include <netinet/in.h> #include <arpa/inet.h> #endif @@ -124,18 +123,20 @@ void Socket::LogIncomingConnection(const struct sockaddr *addr, socklen_t addrle switch(addr->sa_family) { case AF_UNIX: - ::syslog(LOG_INFO, "Incoming connection from local (UNIX socket)"); + BOX_INFO("Incoming connection from local (UNIX socket)"); break; case AF_INET: { sockaddr_in *a = (sockaddr_in*)addr; - ::syslog(LOG_INFO, "Incoming connection from %s port %d", inet_ntoa(a->sin_addr), ntohs(a->sin_port)); + BOX_INFO("Incoming connection from " << + inet_ntoa(a->sin_addr) << " port " << + ntohs(a->sin_port)); } break; default: - ::syslog(LOG_INFO, "Incoming connection of unknown type"); + BOX_WARNING("Incoming connection of unknown type"); break; } } diff --git a/lib/server/WinNamedPipeStream.cpp b/lib/server/WinNamedPipeStream.cpp index 32ae42f2..d7e90793 100644 --- a/lib/server/WinNamedPipeStream.cpp +++ b/lib/server/WinNamedPipeStream.cpp @@ -63,8 +63,8 @@ WinNamedPipeStream::~WinNamedPipeStream() } catch (std::exception &e) { - ::syslog(LOG_ERR, "Caught exception while destroying " - "named pipe, ignored."); + BOX_ERROR("Caught exception while destroying " + "named pipe, ignored: " << e.what()); } } } @@ -100,8 +100,8 @@ void WinNamedPipeStream::Accept(const wchar_t* pName) if (mSocketHandle == INVALID_HANDLE_VALUE) { - ::syslog(LOG_ERR, "CreateNamedPipeW failed: %s", - GetErrorMessage(GetLastError()).c_str()); + BOX_ERROR("Failed to CreateNamedPipeW(" << pName << "): " << + GetErrorMessage(GetLastError())); THROW_EXCEPTION(ServerException, SocketOpenError) } @@ -109,8 +109,8 @@ void WinNamedPipeStream::Accept(const wchar_t* pName) if (!connected) { - ::syslog(LOG_ERR, "ConnectNamedPipe failed: %s", - GetErrorMessage(GetLastError()).c_str()); + BOX_ERROR("Failed to ConnectNamedPipe(" << pName << "): " << + GetErrorMessage(GetLastError())); Close(); THROW_EXCEPTION(ServerException, SocketOpenError) } @@ -126,8 +126,8 @@ void WinNamedPipeStream::Accept(const wchar_t* pName) if (mReadableEvent == INVALID_HANDLE_VALUE) { - ::syslog(LOG_ERR, "Failed to create the Readable event: %s", - GetErrorMessage(GetLastError()).c_str()); + BOX_ERROR("Failed to create the Readable event: " << + GetErrorMessage(GetLastError())); Close(); THROW_EXCEPTION(CommonException, Internal) } @@ -144,8 +144,8 @@ void WinNamedPipeStream::Accept(const wchar_t* pName) if (err != ERROR_IO_PENDING) { - ::syslog(LOG_ERR, "Failed to start overlapped read: " - "%s", GetErrorMessage(err).c_str()); + BOX_ERROR("Failed to start overlapped read: " << + GetErrorMessage(err)); Close(); THROW_EXCEPTION(ConnectionException, Conn_SocketReadError) @@ -183,13 +183,13 @@ void WinNamedPipeStream::Connect(const wchar_t* pName) DWORD err = GetLastError(); if (err == ERROR_PIPE_BUSY) { - ::syslog(LOG_ERR, "Failed to connect to backup " - "daemon: it is busy with another connection"); + BOX_ERROR("Failed to connect to backup daemon: " + "it is busy with another connection"); } else { - ::syslog(LOG_ERR, "Failed to connect to backup " - "daemon: %s", GetErrorMessage(err).c_str()); + BOX_ERROR("Failed to connect to backup daemon: " << + GetErrorMessage(err)); } THROW_EXCEPTION(ServerException, SocketOpenError) } @@ -261,16 +261,14 @@ int WinNamedPipeStream::Read(void *pBuffer, int NBytes, int Timeout) { if (err == ERROR_BROKEN_PIPE) { - ::syslog(LOG_ERR, "Control " - "client disconnected"); + BOX_ERROR("Control client " + "disconnected"); } else { - ::syslog(LOG_ERR, - "Failed to wait for " + BOX_ERROR("Failed to wait for " "ReadFile to complete: " - "%s", - GetErrorMessage(err).c_str()); + << GetErrorMessage(err)); } Close(); @@ -326,15 +324,13 @@ int WinNamedPipeStream::Read(void *pBuffer, int NBytes, int Timeout) } else if (err == ERROR_BROKEN_PIPE) { - ::syslog(LOG_ERR, - "Control client disconnected"); + BOX_ERROR("Control client disconnected"); mReadClosed = true; } else { - ::syslog(LOG_ERR, "Failed to start " - "overlapped read: %s", - GetErrorMessage(err).c_str()); + BOX_ERROR("Failed to start overlapped read: " + << GetErrorMessage(err)); Close(); THROW_EXCEPTION(ConnectionException, Conn_SocketReadError) @@ -387,9 +383,8 @@ int WinNamedPipeStream::Read(void *pBuffer, int NBytes, int Timeout) } else { - ::syslog(LOG_ERR, "Failed to read from " - "control socket: %s", - GetErrorMessage(err).c_str()); + BOX_ERROR("Failed to read from control socket: " + << GetErrorMessage(err)); THROW_EXCEPTION(ConnectionException, Conn_SocketReadError) } @@ -440,8 +435,8 @@ void WinNamedPipeStream::Write(const void *pBuffer, int NBytes) if (!Success) { DWORD err = GetLastError(); - ::syslog(LOG_ERR, "Failed to write to control socket: " - "%s", GetErrorMessage(err).c_str()); + BOX_ERROR("Failed to write to control socket: " << + GetErrorMessage(err)); Close(); // ERROR_NO_DATA is a strange name for @@ -474,8 +469,7 @@ void WinNamedPipeStream::Close() { if (mSocketHandle == INVALID_HANDLE_VALUE && mIsConnected) { - fprintf(stderr, "Inconsistent connected state\n"); - ::syslog(LOG_ERR, "Inconsistent connected state"); + BOX_ERROR("Named pipe: inconsistent connected state"); mIsConnected = false; } @@ -488,29 +482,27 @@ void WinNamedPipeStream::Close() { if (!CancelIo(mSocketHandle)) { - ::syslog(LOG_ERR, "Failed to cancel outstanding " - "I/O: %s", - GetErrorMessage(GetLastError()).c_str()); + BOX_ERROR("Failed to cancel outstanding I/O: " << + GetErrorMessage(GetLastError())); } if (mReadableEvent == INVALID_HANDLE_VALUE) { - ::syslog(LOG_ERR, "Failed to destroy Readable " - "event: invalid handle"); + BOX_ERROR("Failed to destroy Readable event: " + "invalid handle"); } else if (!CloseHandle(mReadableEvent)) { - ::syslog(LOG_ERR, "Failed to destroy Readable " - "event: %s", - GetErrorMessage(GetLastError()).c_str()); + BOX_ERROR("Failed to destroy Readable event: " << + GetErrorMessage(GetLastError())); } mReadableEvent = INVALID_HANDLE_VALUE; if (!FlushFileBuffers(mSocketHandle)) { - ::syslog(LOG_INFO, "FlushFileBuffers failed: %s", - GetErrorMessage(GetLastError()).c_str()); + BOX_ERROR("Failed to FlushFileBuffers: " << + GetErrorMessage(GetLastError())); } if (!DisconnectNamedPipe(mSocketHandle)) @@ -518,9 +510,8 @@ void WinNamedPipeStream::Close() DWORD err = GetLastError(); if (err != ERROR_PIPE_NOT_CONNECTED) { - ::syslog(LOG_ERR, "DisconnectNamedPipe " - "failed: %s", - GetErrorMessage(err).c_str()); + BOX_ERROR("Failed to DisconnectNamedPipe: " << + GetErrorMessage(err)); } } @@ -536,8 +527,8 @@ void WinNamedPipeStream::Close() if (!result) { - ::syslog(LOG_ERR, "CloseHandle failed: %s", - GetErrorMessage(GetLastError()).c_str()); + BOX_ERROR("Failed to CloseHandle: " << + GetErrorMessage(GetLastError())); THROW_EXCEPTION(ServerException, SocketCloseError) } } @@ -585,8 +576,8 @@ void WinNamedPipeStream::WriteAllBuffered() if (!FlushFileBuffers(mSocketHandle)) { - ::syslog(LOG_WARNING, "FlushFileBuffers failed: %s", - GetErrorMessage(GetLastError()).c_str()); + BOX_ERROR("Failed to FlushFileBuffers: " << + GetErrorMessage(GetLastError())); } } |