Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/main/cpp/exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion src/main/cpp/gzcompressaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,21 @@ 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)
{
throw IOException(stat);
}

if (exitCode != 0)
{
throw SubProcessFailure(LOG4CXX_STR("gzip"), exitCode, reason);
}

priv->destination.setAutoDelete(false);

if (priv->deleteSource)
Expand Down
7 changes: 4 additions & 3 deletions src/main/cpp/zipcompressaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions src/main/include/log4cxx/helpers/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 2 additions & 5 deletions src/test/cpp/fileappendertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -200,11 +201,7 @@ LOGUNIT_CLASS(FileAppenderTest)
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);

Expand Down
7 changes: 2 additions & 5 deletions src/test/cpp/net/telnetappendertestcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 2 additions & 4 deletions src/test/cpp/rolling/multiprocessrollingtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -214,10 +215,7 @@ LOGUNIT_CLASS(MultiprocessRollingTest)
{
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);
Expand Down