Author: carnold
Date: Wed Sep 19 22:55:51 2007
New Revision: 577560

URL: http://svn.apache.org/viewvc?rev=577560&view=rev
Log:
LOGCXX-191: Application cores when syslog appender is given unreachable host

Added:
    logging/log4cxx/trunk/src/test/cpp/helpers/syslogwritertest.cpp
Modified:
    logging/log4cxx/trunk/src/main/cpp/syslogwriter.cpp
    logging/log4cxx/trunk/src/main/include/log4cxx/helpers/syslogwriter.h
    logging/log4cxx/trunk/src/test/cpp/Makefile.am

Modified: logging/log4cxx/trunk/src/main/cpp/syslogwriter.cpp
URL: 
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/syslogwriter.cpp?rev=577560&r1=577559&r2=577560&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/syslogwriter.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/syslogwriter.cpp Wed Sep 19 22:55:51 2007
@@ -54,13 +54,13 @@
 }
 
 void SyslogWriter::write(const LogString& source) {
-   LOG4CXX_ENCODE_CHAR(data, source);
+  if (this->ds != 0 && this->address != 0) {
+      LOG4CXX_ENCODE_CHAR(data, source);
 
-   DatagramPacketPtr packet = 
+      DatagramPacketPtr packet( 
           new DatagramPacket((void*) data.c_str(), data.length() + 1,
-                             address, SYSLOG_PORT);
+                             address, SYSLOG_PORT));
 
-   if(this->ds != 0) {
       ds->send(packet);
    }
 }

Modified: logging/log4cxx/trunk/src/main/include/log4cxx/helpers/syslogwriter.h
URL: 
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/include/log4cxx/helpers/syslogwriter.h?rev=577560&r1=577559&r2=577560&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/include/log4cxx/helpers/syslogwriter.h 
(original)
+++ logging/log4cxx/trunk/src/main/include/log4cxx/helpers/syslogwriter.h Wed 
Sep 19 22:55:51 2007
@@ -21,14 +21,12 @@
 
 #include <log4cxx/helpers/objectptr.h>
 #include <log4cxx/helpers/inetaddress.h>
+#include <log4cxx/helpers/datagramsocket.h>
 
  namespace log4cxx
 {
         namespace helpers
         {
-                class DatagramSocket;
-                typedef helpers::ObjectPtrT<DatagramSocket> DatagramSocketPtr;
-
                 /**
                 SyslogWriter is a wrapper around the DatagramSocket class
                 it writes text to the specified host on the port 514 (UNIX 
syslog)

Modified: logging/log4cxx/trunk/src/test/cpp/Makefile.am
URL: 
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/test/cpp/Makefile.am?rev=577560&r1=577559&r2=577560&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/test/cpp/Makefile.am (original)
+++ logging/log4cxx/trunk/src/test/cpp/Makefile.am Wed Sep 19 22:55:51 2007
@@ -53,6 +53,7 @@
         helpers/relativetimedateformattestcase.cpp \
         helpers/stringtokenizertestcase.cpp \
         helpers/stringhelpertestcase.cpp \
+        helpers/syslogwritertest.cpp \
         helpers/timezonetestcase.cpp \
         helpers/transcodertestcase.cpp \
         helpers/unicodehelpertestcase.cpp

Added: logging/log4cxx/trunk/src/test/cpp/helpers/syslogwritertest.cpp
URL: 
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/test/cpp/helpers/syslogwritertest.cpp?rev=577560&view=auto
==============================================================================
--- logging/log4cxx/trunk/src/test/cpp/helpers/syslogwritertest.cpp (added)
+++ logging/log4cxx/trunk/src/test/cpp/helpers/syslogwritertest.cpp Wed Sep 19 
22:55:51 2007
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <log4cxx/helpers/syslogwriter.h>
+
+using namespace log4cxx;
+using namespace log4cxx::helpers;
+
+
+class SyslogWriterTest : public CppUnit::TestFixture
+{
+        CPPUNIT_TEST_SUITE(SyslogWriterTest);
+                CPPUNIT_TEST(testUnknownHost);
+        CPPUNIT_TEST_SUITE_END();
+
+public:
+        /**
+         * Tests writing to an unknown host.
+         */
+        void testUnknownHost() {
+           SyslogWriter writer(LOG4CXX_STR("unknown.invalid"));
+           writer.write(LOG4CXX_STR("Hello, Unknown World."));
+        }
+      
+};
+
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SyslogWriterTest);
+


Reply via email to