From 2e7ce385525cae267693d4b0c6efca989b8aaeee Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 4 Feb 2016 12:36:54 -0500 Subject: [PATCH 1/4] compatibility with gcc 4.6 --- Garlic.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Garlic.h b/Garlic.h index 67e9b027..73231d10 100644 --- a/Garlic.h +++ b/Garlic.h @@ -119,7 +119,8 @@ namespace garlic // for HTTP only size_t GetNumOutgoingTags () const { return m_SessionTags.size (); }; }; - using GarlicRoutingSessionPtr = std::shared_ptr; + //using GarlicRoutingSessionPtr = std::shared_ptr; + typedef std::shared_ptr GarlicRoutingSessionPtr; // TODO: replace to using after switch to 4.8 class GarlicDestination: public i2p::data::LocalDestination { From 7ca1cfab1a3b1731dcda9c10c2e1aba941bdff96 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 4 Feb 2016 12:36:58 -0500 Subject: [PATCH 2/4] use shared_ptr for log's stream --- Log.cpp | 12 +++++------- Log.h | 13 +++++++------ api.cpp | 2 +- api.h | 2 +- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Log.cpp b/Log.cpp index 837abac8..d507b7dc 100644 --- a/Log.cpp +++ b/Log.cpp @@ -13,7 +13,8 @@ static const char * g_LogLevelStr[eNumLogLevels] = void LogMsg::Process() { - auto& output = (log && log->GetLogStream ()) ? *log->GetLogStream () : std::cerr; + auto stream = log ? log->GetLogStream () : nullptr; + auto& output = stream ? *stream : std::cout; if (log) output << log->GetTimestamp (); else @@ -45,14 +46,12 @@ void Log::Flush () void Log::SetLogFile (const std::string& fullFilePath) { - auto logFile = new std::ofstream (fullFilePath, std::ofstream::out | std::ofstream::binary | std::ofstream::trunc); + auto logFile = std::make_shared (fullFilePath, std::ofstream::out | std::ofstream::binary | std::ofstream::trunc); if (logFile->is_open ()) { SetLogStream (logFile); LogPrint(eLogInfo, "Log: will send messages to ", fullFilePath); } - else - delete logFile; } void Log::SetLogLevel (const std::string& level) @@ -65,11 +64,10 @@ void Log::SetLogLevel (const std::string& level) LogPrint(eLogError, "Log: Unknown loglevel: ", level); return; } - LogPrint(eLogInfo, "Log: min messages level set to ", level); + LogPrint(eLogInfo, "Log: min msg level set to ", level); } -void Log::SetLogStream (std::ostream * logStream) +void Log::SetLogStream (std::shared_ptr logStream) { - if (m_LogStream) delete m_LogStream; m_LogStream = logStream; } diff --git a/Log.h b/Log.h index f941e6a7..ec1dc015 100644 --- a/Log.h +++ b/Log.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "Queue.h" enum LogLevel @@ -34,13 +35,13 @@ class Log: public i2p::util::MsgQueue { public: - Log (): m_LogStream (nullptr) { SetOnEmpty (std::bind (&Log::Flush, this)); }; - ~Log () { delete m_LogStream; }; + Log () { SetOnEmpty (std::bind (&Log::Flush, this)); }; + ~Log () {}; void SetLogFile (const std::string& fullFilePath); void SetLogLevel (const std::string& level); - void SetLogStream (std::ostream * logStream); - std::ostream * GetLogStream () const { return m_LogStream; }; + void SetLogStream (std::shared_ptr logStream); + std::shared_ptr GetLogStream () const { return m_LogStream; }; const std::string& GetTimestamp (); LogLevel GetLogLevel () { return m_MinLevel; }; @@ -50,7 +51,7 @@ class Log: public i2p::util::MsgQueue private: - std::ostream * m_LogStream; + std::shared_ptr m_LogStream; enum LogLevel m_MinLevel; std::string m_Timestamp; #if (__GNUC__ == 4) && (__GNUC_MINOR__ <= 6) && !defined(__clang__) // gcc 4.6 @@ -73,7 +74,7 @@ inline void StartLog (const std::string& fullFilePath) } } -inline void StartLog (std::ostream * s) +inline void StartLog (std::shared_ptr s) { if (!g_Log) { diff --git a/api.cpp b/api.cpp index cd527550..0f4e1799 100644 --- a/api.cpp +++ b/api.cpp @@ -31,7 +31,7 @@ namespace api i2p::crypto::TerminateCrypto (); } - void StartI2P (std::ostream * logStream) + void StartI2P (std::shared_ptr logStream) { if (logStream) StartLog (logStream); diff --git a/api.h b/api.h index 05552249..c010d82f 100644 --- a/api.h +++ b/api.h @@ -14,7 +14,7 @@ namespace api // initialization start and stop void InitI2P (int argc, char* argv[], const char * appName); void TerminateI2P (); - void StartI2P (std::ostream * logStream = nullptr); + void StartI2P (std::shared_ptr logStream = nullptr); // write system log to logStream, if not specified to .log in application's folder void StopI2P (); void RunPeerTest (); // should be called after UPnP From 98d5e0b56d321b72340212564a662aa2e6d6a06e Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 4 Feb 2016 13:53:38 -0500 Subject: [PATCH 3/4] #355. reopen log file by SIGHUP --- DaemonLinux.cpp | 6 +++--- Log.cpp | 11 +++++++++++ Log.h | 8 ++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/DaemonLinux.cpp b/DaemonLinux.cpp index 89df5306..9382a878 100644 --- a/DaemonLinux.cpp +++ b/DaemonLinux.cpp @@ -17,9 +17,9 @@ void handle_signal(int sig) switch (sig) { case SIGHUP: - LogPrint(eLogInfo, "Daemon: Got SIGHUP, doing nothing"); - // TODO: - break; + LogPrint(eLogInfo, "Daemon: Got SIGHUP, reopening log..."); + ReopenLogFile (); + break; case SIGABRT: case SIGTERM: case SIGINT: diff --git a/Log.cpp b/Log.cpp index d507b7dc..6391bcae 100644 --- a/Log.cpp +++ b/Log.cpp @@ -46,6 +46,7 @@ void Log::Flush () void Log::SetLogFile (const std::string& fullFilePath) { + m_FullFilePath = fullFilePath; auto logFile = std::make_shared (fullFilePath, std::ofstream::out | std::ofstream::binary | std::ofstream::trunc); if (logFile->is_open ()) { @@ -54,6 +55,16 @@ void Log::SetLogFile (const std::string& fullFilePath) } } +void Log::ReopenLogFile () +{ + if (m_FullFilePath.length () > 0) + { + SetLogFile (m_FullFilePath); + LogPrint(eLogInfo, "Log: file ", m_FullFilePath, " reopen"); + } +} + + void Log::SetLogLevel (const std::string& level) { if (level == "error") { m_MinLevel = eLogError; } diff --git a/Log.h b/Log.h index ec1dc015..05bae7d9 100644 --- a/Log.h +++ b/Log.h @@ -39,6 +39,7 @@ class Log: public i2p::util::MsgQueue ~Log () {}; void SetLogFile (const std::string& fullFilePath); + void ReopenLogFile (); void SetLogLevel (const std::string& level); void SetLogStream (std::shared_ptr logStream); std::shared_ptr GetLogStream () const { return m_LogStream; }; @@ -51,6 +52,7 @@ class Log: public i2p::util::MsgQueue private: + std::string m_FullFilePath; // empty if stream std::shared_ptr m_LogStream; enum LogLevel m_MinLevel; std::string m_Timestamp; @@ -102,6 +104,12 @@ inline void SetLogLevel (const std::string& level) g_Log->SetLogLevel(level); } +inline void ReopenLogFile () +{ + if (g_Log) + g_Log->ReopenLogFile (); +} + template void LogPrint (std::stringstream& s, TValue arg) { From a292bc77ba3bd3d649c4faf3a03fa7902555627a Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 5 Feb 2016 07:55:28 -0500 Subject: [PATCH 4/4] fix issue #362 , add bounds check to su3 fileNameLength --- Reseed.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Reseed.cpp b/Reseed.cpp index 6d7c7901..80cc6a45 100644 --- a/Reseed.cpp +++ b/Reseed.cpp @@ -208,6 +208,11 @@ namespace data uint16_t fileNameLength, extraFieldLength; s.read ((char *)&fileNameLength, 2); fileNameLength = le16toh (fileNameLength); + if ( fileNameLength > 255 ) { + // too big + LogPrint(eLogError, "Reseed: SU3 fileNameLength too large: ", fileNameLength); + return numFiles; + } s.read ((char *)&extraFieldLength, 2); extraFieldLength = le16toh (extraFieldLength); char localFileName[255];