From 9dd8a78341c51e21542d0f066506fc52e6343be8 Mon Sep 17 00:00:00 2001 From: Like Ma Date: Thu, 18 Jul 2024 22:46:23 +0800 Subject: [PATCH 1/4] Fix ACE_Logging_Strategy::handle_timeout returning -1 without releasing ACE_Log_Msg lock --- ACE/ace/Logging_Strategy.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/ACE/ace/Logging_Strategy.cpp b/ACE/ace/Logging_Strategy.cpp index 7b3335e39fa83..164c4d455ffe1 100644 --- a/ACE/ace/Logging_Strategy.cpp +++ b/ACE/ace/Logging_Strategy.cpp @@ -433,7 +433,8 @@ ACE_Logging_Strategy::handle_timeout (const ACE_Time_Value &, #endif /* ACE_LACKS_IOSTREAM_TOTALLY */ { // Lock out any other logging. - if (this->log_msg_->acquire ()) + ACE_Guard guard (*this->log_msg_); + if (!guard.locked ()) ACELIB_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Cannot acquire lock!\n")), -1); @@ -442,7 +443,7 @@ ACE_Logging_Strategy::handle_timeout (const ACE_Time_Value &, #if defined (ACE_LACKS_IOSTREAM_TOTALLY) FILE *output_file = (FILE *) this->log_msg_->msg_ostream (); ACE_OS::fclose (output_file); - // We'll call msg_ostream() modifier later. + this->log_msg_->msg_ostream (0); #else ofstream *output_file = (ofstream *) this->log_msg_->msg_ostream (); @@ -470,9 +471,6 @@ ACE_Logging_Strategy::handle_timeout (const ACE_Time_Value &, output_file->open (ACE_TEXT_ALWAYS_CHAR (this->filename_), ios::out); #endif /* ACE_LACKS_IOSTREAM_TOTALLY */ - - // Release the lock previously acquired. - this->log_msg_->release (); return 0; } } @@ -563,9 +561,6 @@ ACE_Logging_Strategy::handle_timeout (const ACE_Time_Value &, output_file->open (ACE_TEXT_ALWAYS_CHAR (this->filename_), ios::out); #endif /* ACE_LACKS_IOSTREAM_TOTALLY */ - - // Release the lock previously acquired. - this->log_msg_->release (); } return 0; From 47e7ac659810ff8eeda9f02e21b6d7563511302a Mon Sep 17 00:00:00 2001 From: Like Ma Date: Fri, 19 Jul 2024 23:43:59 +0800 Subject: [PATCH 2/4] Reset ACE_Log_Msg::msg_ostream after closing --- ACE/ace/Logging_Strategy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ACE/ace/Logging_Strategy.cpp b/ACE/ace/Logging_Strategy.cpp index 164c4d455ffe1..c4f65944204f9 100644 --- a/ACE/ace/Logging_Strategy.cpp +++ b/ACE/ace/Logging_Strategy.cpp @@ -443,7 +443,7 @@ ACE_Logging_Strategy::handle_timeout (const ACE_Time_Value &, #if defined (ACE_LACKS_IOSTREAM_TOTALLY) FILE *output_file = (FILE *) this->log_msg_->msg_ostream (); ACE_OS::fclose (output_file); - this->log_msg_->msg_ostream (0); + this->log_msg_->msg_ostream (nullptr); #else ofstream *output_file = (ofstream *) this->log_msg_->msg_ostream (); From f6af1f7e53fd7433a2f962bb11b4d735277b91b1 Mon Sep 17 00:00:00 2001 From: Like Ma Date: Wed, 24 Jul 2024 15:23:44 +0800 Subject: [PATCH 3/4] Close output_file if it is not null --- ACE/ace/Logging_Strategy.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ACE/ace/Logging_Strategy.cpp b/ACE/ace/Logging_Strategy.cpp index c4f65944204f9..1df3f769136d7 100644 --- a/ACE/ace/Logging_Strategy.cpp +++ b/ACE/ace/Logging_Strategy.cpp @@ -442,7 +442,8 @@ ACE_Logging_Strategy::handle_timeout (const ACE_Time_Value &, // Close the current ostream. #if defined (ACE_LACKS_IOSTREAM_TOTALLY) FILE *output_file = (FILE *) this->log_msg_->msg_ostream (); - ACE_OS::fclose (output_file); + if (output_file) + ACE_OS::fclose (output_file); this->log_msg_->msg_ostream (nullptr); #else ofstream *output_file = From 5e4cba4dae83090d6df486ca04876a11d5075970 Mon Sep 17 00:00:00 2001 From: Like Ma Date: Wed, 24 Jul 2024 18:38:17 +0800 Subject: [PATCH 4/4] Reset ACE_Log_Msg::msg_ostream if necessary --- ACE/ace/Logging_Strategy.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ACE/ace/Logging_Strategy.cpp b/ACE/ace/Logging_Strategy.cpp index 1df3f769136d7..40824bfcfa0e6 100644 --- a/ACE/ace/Logging_Strategy.cpp +++ b/ACE/ace/Logging_Strategy.cpp @@ -443,8 +443,10 @@ ACE_Logging_Strategy::handle_timeout (const ACE_Time_Value &, #if defined (ACE_LACKS_IOSTREAM_TOTALLY) FILE *output_file = (FILE *) this->log_msg_->msg_ostream (); if (output_file) - ACE_OS::fclose (output_file); - this->log_msg_->msg_ostream (nullptr); + { + ACE_OS::fclose (output_file); + this->log_msg_->msg_ostream (nullptr); + } #else ofstream *output_file = (ofstream *) this->log_msg_->msg_ostream ();