This is an automated email from the ASF dual-hosted git repository.
swebb2066 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
The following commit(s) were added to refs/heads/master by this push:
new cb42be77 Log gzip failure in GZCompressAction (#715)
cb42be77 is described below
commit cb42be773a60031956e8138ab83744a87d6184c6
Author: sahvx655-wq <[email protected]>
AuthorDate: Thu Jun 11 06:31:46 2026 +0530
Log gzip failure in GZCompressAction (#715)
---
src/main/cpp/exception.cpp | 38 ++++++++++++++++++++++++
src/main/cpp/gzcompressaction.cpp | 9 +++++-
src/main/cpp/zipcompressaction.cpp | 7 +++--
src/main/include/log4cxx/helpers/exception.h | 13 ++++++++
src/test/cpp/fileappendertest.cpp | 7 ++---
src/test/cpp/net/telnetappendertestcase.cpp | 7 ++---
src/test/cpp/rolling/multiprocessrollingtest.cpp | 6 ++--
7 files changed, 69 insertions(+), 18 deletions(-)
diff --git a/src/main/cpp/exception.cpp b/src/main/cpp/exception.cpp
index 264f96c2..4af8ded3 100644
--- a/src/main/cpp/exception.cpp
+++ b/src/main/cpp/exception.cpp
@@ -22,6 +22,7 @@
#include <log4cxx/helpers/stringhelper.h>
#include <log4cxx/helpers/transcoder.h>
#include <apr_errno.h>
+#include <apr_thread_proc.h>
using namespace LOG4CXX_NS;
using namespace LOG4CXX_NS::helpers;
@@ -162,6 +163,43 @@ LogString IOException::formatMessage(log4cxx_status_t stat)
return makeMessage(LOG4CXX_STR("IO Exception"), stat);
}
+SubProcessFailure::SubProcessFailure(const LogString& processName, int
exitCode, int exitWhy)
+ : Exception(makeMessage(processName, exitCode, exitWhy))
+{
+}
+
+#if !LOG4CXX_LOGCHAR_IS_UTF8
+SubProcessFailure::SubProcessFailure(const char* processName, int exitCode,
int exitWhy)
+ : Exception(makeMessage(Transcoder::decode(processName), exitCode,
exitWhy))
+{
+}
+#endif
+
+SubProcessFailure::SubProcessFailure(const SubProcessFailure& src)
+ : Exception(src)
+{
+}
+
+SubProcessFailure& SubProcessFailure::operator=(const SubProcessFailure& src)
+{
+ Exception::operator=(src);
+ return *this;
+}
+
+LogString SubProcessFailure::makeMessage(const LogString& processName, int
exitCode, int exitWhy)
+{
+ LogString msg = processName;
+ msg += LOG4CXX_STR(" exit code: ");
+ LogString codeStr;
+ StringHelper::toString(exitCode, codeStr);
+ msg += codeStr;
+ if (APR_PROC_SIGNAL == exitWhy || APR_PROC_SIGNAL_CORE == exitWhy)
+ {
+ msg += LOG4CXX_STR("; exited due to a signal");
+ }
+ return msg;
+}
+
LogString Exception::makeMessage(const LogString& type, log4cxx_status_t stat)
{
LogString s = type;
diff --git a/src/main/cpp/gzcompressaction.cpp
b/src/main/cpp/gzcompressaction.cpp
index e43c1b8b..8747cdce 100644
--- a/src/main/cpp/gzcompressaction.cpp
+++ b/src/main/cpp/gzcompressaction.cpp
@@ -153,7 +153,9 @@ bool GZCompressAction::execute(
LOG4CXX_EXECUTE_ACTION_FORMAL_PARAMETERS ) const
return true;
}
- apr_proc_wait(&pid, NULL, NULL, APR_WAIT);
+ int exitCode = 0;
+ apr_exit_why_e reason;
+ apr_proc_wait(&pid, &exitCode, &reason, APR_WAIT);
stat = apr_file_close(child_out);
if (stat != APR_SUCCESS)
@@ -161,6 +163,11 @@ bool GZCompressAction::execute(
LOG4CXX_EXECUTE_ACTION_FORMAL_PARAMETERS ) const
throw IOException(stat);
}
+ if (exitCode != 0)
+ {
+ throw SubProcessFailure(LOG4CXX_STR("gzip"), exitCode,
reason);
+ }
+
priv->destination.setAutoDelete(false);
if (priv->deleteSource)
diff --git a/src/main/cpp/zipcompressaction.cpp
b/src/main/cpp/zipcompressaction.cpp
index 2685ad21..02b33b62 100644
--- a/src/main/cpp/zipcompressaction.cpp
+++ b/src/main/cpp/zipcompressaction.cpp
@@ -138,11 +138,12 @@ bool ZipCompressAction::execute(
LOG4CXX_EXECUTE_ACTION_FORMAL_PARAMETERS ) cons
}
int exitCode;
- apr_proc_wait(&pid, &exitCode, NULL, APR_WAIT);
+ apr_exit_why_e reason;
+ apr_proc_wait(&pid, &exitCode, &reason, APR_WAIT);
- if (exitCode != APR_SUCCESS)
+ if (exitCode != 0)
{
- throw IOException(exitCode);
+ throw SubProcessFailure(LOG4CXX_STR("zip"), exitCode, reason);
}
if (priv->deleteSource)
diff --git a/src/main/include/log4cxx/helpers/exception.h
b/src/main/include/log4cxx/helpers/exception.h
index c5215ee7..f241201e 100644
--- a/src/main/include/log4cxx/helpers/exception.h
+++ b/src/main/include/log4cxx/helpers/exception.h
@@ -108,6 +108,19 @@ class LOG4CXX_EXPORT IOException : public Exception
static LogString formatMessage(log4cxx_status_t stat);
};
+class LOG4CXX_EXPORT SubProcessFailure : public Exception
+{
+ public:
+ SubProcessFailure(const LogString& processName, int exitCode,
int exitWhy);
+#if !LOG4CXX_LOGCHAR_IS_UTF8
+ SubProcessFailure(const char* processName, int exitCode, int
exitWhy);
+#endif
+ SubProcessFailure(const SubProcessFailure& src);
+ SubProcessFailure& operator=(const SubProcessFailure&);
+
+ static LogString makeMessage(const LogString& processName, int
exitCode, int exitWhy);
+};
+
class LOG4CXX_EXPORT MissingResourceException : public Exception
{
public:
diff --git a/src/test/cpp/fileappendertest.cpp
b/src/test/cpp/fileappendertest.cpp
index c91a7009..f6704479 100644
--- a/src/test/cpp/fileappendertest.cpp
+++ b/src/test/cpp/fileappendertest.cpp
@@ -21,6 +21,7 @@
#include <log4cxx/helpers/loglog.h>
#include <log4cxx/helpers/stringhelper.h>
#include <log4cxx/helpers/transcoder.h>
+#include <log4cxx/helpers/exception.h>
#include <log4cxx/helpers/fileoutputstream.h>
#include <log4cxx/rolling/rollingfileappender.h>
#include <log4cxx/rolling/timebasedrollingpolicy.h>
@@ -200,11 +201,7 @@ public:
apr_proc_wait(&pid, &exitCode, &reason, APR_WAIT);
if (exitCode != 0)
{
- LogString msg = LOG4CXX_STR("child exit code: ");
- helpers::StringHelper::toString(exitCode, msg);
- msg += LOG4CXX_STR("; reason: ");
- helpers::StringHelper::toString(reason, msg);
- helpers::LogLog::warn(msg);
+
helpers::LogLog::warn(helpers::SubProcessFailure::makeMessage(LOG4CXX_STR("child"),
exitCode, reason));
}
LOGUNIT_ASSERT_EQUAL(exitCode, 0);
diff --git a/src/test/cpp/net/telnetappendertestcase.cpp
b/src/test/cpp/net/telnetappendertestcase.cpp
index 52f70464..764074ff 100644
--- a/src/test/cpp/net/telnetappendertestcase.cpp
+++ b/src/test/cpp/net/telnetappendertestcase.cpp
@@ -27,6 +27,7 @@
#include <log4cxx/helpers/pool.h>
#include <log4cxx/config/propertysetter.h>
#include <log4cxx/helpers/transcoder.h>
+#include <log4cxx/helpers/exception.h>
#include <log4cxx/helpers/socket.h>
#include <log4cxx/spi/configurator.h>
#include <apr_thread_proc.h>
@@ -172,11 +173,7 @@ class TelnetAppenderTestCase : public
AppenderSkeletonTestCase
apr_proc_wait(&pid, &exitCode, &reason, APR_WAIT);
if (exitCode != 0 && helpers::LogLog::isDebugEnabled())
{
- LogString msg = LOG4CXX_STR("child exit code:
");
- helpers::StringHelper::toString(exitCode, msg);
- msg += LOG4CXX_STR("; reason: ");
- helpers::StringHelper::toString(reason, msg);
- helpers::LogLog::debug(msg);
+
helpers::LogLog::debug(helpers::SubProcessFailure::makeMessage(LOG4CXX_STR("child"),
exitCode, reason));
}
LOGUNIT_ASSERT_EQUAL(exitCode, 0);
}
diff --git a/src/test/cpp/rolling/multiprocessrollingtest.cpp
b/src/test/cpp/rolling/multiprocessrollingtest.cpp
index e1afa777..b141979c 100644
--- a/src/test/cpp/rolling/multiprocessrollingtest.cpp
+++ b/src/test/cpp/rolling/multiprocessrollingtest.cpp
@@ -28,6 +28,7 @@
#include <log4cxx/helpers/fileoutputstream.h>
#include <log4cxx/helpers/loglog.h>
#include <log4cxx/helpers/stringhelper.h>
+#include <log4cxx/helpers/exception.h>
#include <filesystem>
#include <fstream>
#include <apr_thread_proc.h>
@@ -214,10 +215,7 @@ public:
{
LogString msg = LOG4CXX_STR("child: ");
helpers::StringHelper::toString(i, msg);
- msg += LOG4CXX_STR("; exit code: ");
- helpers::StringHelper::toString(exitCode, msg);
- msg += LOG4CXX_STR("; reason: ");
- helpers::StringHelper::toString(reason, msg);
+ msg += LOG4CXX_STR("; ") +
helpers::SubProcessFailure::makeMessage(LOG4CXX_STR("child"), exitCode, reason);
helpers::LogLog::debug(msg);
}
LOGUNIT_ASSERT_EQUAL(exitCode, 0);