diff options
-rw-r--r-- | bin/bbstored/BackupStoreDaemon.cpp | 2 | ||||
-rw-r--r-- | lib/backupstore/BackupCommands.cpp | 3 | ||||
-rw-r--r-- | lib/backupstore/BackupStoreContext.cpp | 5 | ||||
-rw-r--r-- | lib/backupstore/BackupStoreContext.h | 5 | ||||
-rw-r--r-- | lib/server/ServerStream.h | 23 | ||||
-rw-r--r-- | lib/server/Socket.cpp | 38 |
6 files changed, 42 insertions, 34 deletions
diff --git a/bin/bbstored/BackupStoreDaemon.cpp b/bin/bbstored/BackupStoreDaemon.cpp index 71976e6e..70ca1d67 100644 --- a/bin/bbstored/BackupStoreDaemon.cpp +++ b/bin/bbstored/BackupStoreDaemon.cpp @@ -329,7 +329,7 @@ void BackupStoreDaemon::Connection2(SocketStreamTLS &rStream) Logging::Tagger tagWithClientID(tag.str()); // Create a context, using this ID - BackupStoreContext context(id, *this); + BackupStoreContext context(id, *this, GetConnectionDetails()); if (mpTestHook) { diff --git a/lib/backupstore/BackupCommands.cpp b/lib/backupstore/BackupCommands.cpp index b2a42eb7..66764a3b 100644 --- a/lib/backupstore/BackupCommands.cpp +++ b/lib/backupstore/BackupCommands.cpp @@ -131,7 +131,8 @@ std::auto_ptr<BackupProtocolMessage> BackupProtocolLogin::DoCommand(BackupProtoc BOX_FORMAT_ACCOUNT(mClientID) << " " "(name=" << rContext.GetAccountName() << "): " << (((mFlags & Flags_ReadOnly) != Flags_ReadOnly) - ?"Read/Write":"Read-only")); + ?"Read/Write":"Read-only") << " from " << + rContext.GetConnectionDetails()); // Get the usage info for reporting to the client int64_t blocksUsed = 0, blocksSoftLimit = 0, blocksHardLimit = 0; diff --git a/lib/backupstore/BackupStoreContext.cpp b/lib/backupstore/BackupStoreContext.cpp index e44fa29d..2c98b1d7 100644 --- a/lib/backupstore/BackupStoreContext.cpp +++ b/lib/backupstore/BackupStoreContext.cpp @@ -54,8 +54,9 @@ // // -------------------------------------------------------------------------- BackupStoreContext::BackupStoreContext(int32_t ClientID, - HousekeepingInterface &rDaemon) - : mClientID(ClientID), + HousekeepingInterface &rDaemon, const std::string& rConnectionDetails) + : mConnectionDetails(rConnectionDetails), + mClientID(ClientID), mrDaemon(rDaemon), mProtocolPhase(Phase_START), mClientHasAccount(false), diff --git a/lib/backupstore/BackupStoreContext.h b/lib/backupstore/BackupStoreContext.h index 7388f753..c2fe14ff 100644 --- a/lib/backupstore/BackupStoreContext.h +++ b/lib/backupstore/BackupStoreContext.h @@ -45,7 +45,8 @@ class HousekeepingInterface class BackupStoreContext { public: - BackupStoreContext(int32_t ClientID, HousekeepingInterface &rDaemon); + BackupStoreContext(int32_t ClientID, HousekeepingInterface &rDaemon, + const std::string& rConnectionDetails); ~BackupStoreContext(); private: BackupStoreContext(const BackupStoreContext &rToCopy); @@ -137,6 +138,7 @@ public: // Info int32_t GetClientID() const {return mClientID;} + const std::string& GetConnectionDetails() { return mConnectionDetails; } private: void MakeObjectFilename(int64_t ObjectID, std::string &rOutput, bool EnsureDirectoryExists = false); @@ -146,6 +148,7 @@ private: void DeleteDirectoryRecurse(int64_t ObjectID, int64_t &rBlocksDeletedOut, bool Undelete); int64_t AllocateObjectID(); + std::string mConnectionDetails; int32_t mClientID; HousekeepingInterface &mrDaemon; int mProtocolPhase; diff --git a/lib/server/ServerStream.h b/lib/server/ServerStream.h index e49dbcbe..0adee6f2 100644 --- a/lib/server/ServerStream.h +++ b/lib/server/ServerStream.h @@ -48,6 +48,15 @@ private: ServerStream(const ServerStream &rToCopy) { } + + std::string mConnectionDetails; + +protected: + const std::string& GetConnectionDetails() + { + return mConnectionDetails; + } + public: virtual const char *DaemonName() const @@ -122,6 +131,10 @@ public: protected: virtual void NotifyListenerIsReady() { } + virtual void LogConnectionDetails(std::string details) + { + BOX_NOTICE("Handling incoming connection from " << details); + } public: virtual void Run2(bool &rChildExit) @@ -237,8 +250,9 @@ public: { // Get the incoming connection // (with zero wait time) - std::string logMessage; - std::auto_ptr<StreamType> connection(psocket->Accept(0, &logMessage)); + std::auto_ptr<StreamType> connection( + psocket->Accept(0, + &mConnectionDetails)); // Was there one (there should be...) if(connection.get()) @@ -264,6 +278,7 @@ public: // Set up daemon EnterChild(); SetProcessTitle("transaction"); + LogConnectionDetails(mConnectionDetails); // Memory leak test the forked process #ifdef BOX_MEMORY_LEAK_TESTING @@ -281,7 +296,9 @@ public: } // Log it - BOX_NOTICE("Message from child process " << pid << ": " << logMessage); + BOX_TRACE("Forked child process " << pid << + "to handle connection from " << + mConnectionDetails); } else { diff --git a/lib/server/Socket.cpp b/lib/server/Socket.cpp index 4a83bdb0..f2a4996b 100644 --- a/lib/server/Socket.cpp +++ b/lib/server/Socket.cpp @@ -123,27 +123,8 @@ void Socket::NameLookupToSockAddr(SocketAllAddr &addr, int &sockDomain, // -------------------------------------------------------------------------- void Socket::LogIncomingConnection(const struct sockaddr *addr, socklen_t addrlen) { - if(addr == NULL) {THROW_EXCEPTION(CommonException, BadArguments)} - - switch(addr->sa_family) - { - case AF_UNIX: - BOX_INFO("Incoming connection from local (UNIX socket)"); - break; - - case AF_INET: - { - sockaddr_in *a = (sockaddr_in*)addr; - BOX_INFO("Incoming connection from " << - inet_ntoa(a->sin_addr) << " port " << - ntohs(a->sin_port)); - } - break; - - default: - BOX_WARNING("Incoming connection of unknown type"); - break; - } + BOX_INFO("Incoming connection from " << + IncomingConnectionLogMessage(addr, addrlen)); } // -------------------------------------------------------------------------- @@ -161,20 +142,25 @@ std::string Socket::IncomingConnectionLogMessage(const struct sockaddr *addr, so switch(addr->sa_family) { case AF_UNIX: - return std::string("Incoming connection from local (UNIX socket)"); + return std::string("local (UNIX socket)"); break; case AF_INET: { - char msg[256]; // more than enough sockaddr_in *a = (sockaddr_in*)addr; - sprintf(msg, "Incoming connection from %s port %d", inet_ntoa(a->sin_addr), ntohs(a->sin_port)); - return std::string(msg); + std::ostringstream oss; + oss << inet_ntoa(a->sin_addr) << " port " << + ntohs(a->sin_port); + return oss.str(); } break; default: - return std::string("Incoming connection of unknown type"); + { + std::ostringstream oss; + oss << "unknown socket type " << addr->sa_family; + return oss.str(); + } break; } |