You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-dev@logging.apache.org by ca...@apache.org on 2007/09/20 07:05:36 UTC

svn commit: r577550 - in /logging/log4cxx/trunk: ./ src/main/cpp/ src/test/cpp/helpers/ src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/logging/ src/test/java/org/apache/logging/log4cxx/ src/test/java/org/apache/log...

Author: carnold
Date: Wed Sep 19 22:05:35 2007
New Revision: 577550

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

Added:
    logging/log4cxx/trunk/src/test/java/
    logging/log4cxx/trunk/src/test/java/org/
    logging/log4cxx/trunk/src/test/java/org/apache/
    logging/log4cxx/trunk/src/test/java/org/apache/logging/
    logging/log4cxx/trunk/src/test/java/org/apache/logging/log4cxx/
    logging/log4cxx/trunk/src/test/java/org/apache/logging/log4cxx/helpers/
    logging/log4cxx/trunk/src/test/java/org/apache/logging/log4cxx/helpers/InetAddressTestCase.java
Modified:
    logging/log4cxx/trunk/pom.xml
    logging/log4cxx/trunk/src/main/cpp/inetaddress.cpp
    logging/log4cxx/trunk/src/test/cpp/helpers/inetaddresstestcase.cpp

Modified: logging/log4cxx/trunk/pom.xml
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/pom.xml?rev=577550&r1=577549&r2=577550&view=diff
==============================================================================
--- logging/log4cxx/trunk/pom.xml (original)
+++ logging/log4cxx/trunk/pom.xml Wed Sep 19 22:05:35 2007
@@ -29,28 +29,28 @@
     <url>http://issues.apache.org/jira/</url>
   </issueManagement>
 <mailingLists>
-	<mailingList>
-		<name>log4cxx-user : log4cxx usage</name>
-		<subscribe>log4cxx-user-subscribe@logging.apache.org</subscribe>
-		<unsubscribe>log4cxx-user-unsubscribe@logging.apache.org</unsubscribe>
-		<post>log4cxx-user@logging.apache.org</post>
-		<archive>http://mail-archives.apache.org/mod_mbox/logging-log4cxx-user/</archive>
-		<otherArchives>
-			<otherArchive>http://marc.info/?l=log4cxx-user</otherArchive>
-		    <otherArchive>http://dir.gmane.org/gmane.comp.apache.logging.log4cxx.user</otherArchive>
-		</otherArchives>
-	</mailingList>
-	<mailingList>
-		<name>log4cxx-dev : log4cxx development</name>
-		<subscribe>log4cxx-dev-subscribe@logging.apache.org</subscribe>
-		<unsubscribe>log4cxx-dev-unsubscribe@logging.apache.org</unsubscribe>
-		<post>log4cxx-dev@logging.apache.org</post>
-		<archive>http://mail-archives.apache.org/mod_mbox/logging-log4cxx-dev/</archive>
-		<otherArchives>
-		    <otherArchive>http://marc.info/?l=log4cxx-dev</otherArchive>
-		    <otherArchive>http://dir.gmane.org/gmane.comp.jakarta.log4j.devel</otherArchive>
-		</otherArchives>
-	</mailingList>
+   <mailingList>
+      <name>log4cxx-user : log4cxx usage</name>
+      <subscribe>log4cxx-user-subscribe@logging.apache.org</subscribe>
+      <unsubscribe>log4cxx-user-unsubscribe@logging.apache.org</unsubscribe>
+      <post>log4cxx-user@logging.apache.org</post>
+      <archive>http://mail-archives.apache.org/mod_mbox/logging-log4cxx-user/</archive>
+      <otherArchives>
+         <otherArchive>http://marc.info/?l=log4cxx-user</otherArchive>
+          <otherArchive>http://dir.gmane.org/gmane.comp.apache.logging.log4cxx.user</otherArchive>
+      </otherArchives>
+   </mailingList>
+   <mailingList>
+      <name>log4cxx-dev : log4cxx development</name>
+      <subscribe>log4cxx-dev-subscribe@logging.apache.org</subscribe>
+      <unsubscribe>log4cxx-dev-unsubscribe@logging.apache.org</unsubscribe>
+      <post>log4cxx-dev@logging.apache.org</post>
+      <archive>http://mail-archives.apache.org/mod_mbox/logging-log4cxx-dev/</archive>
+      <otherArchives>
+          <otherArchive>http://marc.info/?l=log4cxx-dev</otherArchive>
+          <otherArchive>http://dir.gmane.org/gmane.comp.jakarta.log4j.devel</otherArchive>
+      </otherArchives>
+   </mailingList>
 </mailingLists>
 <licenses>
         <license>
@@ -119,7 +119,7 @@
                    <replaceregexp file="target/site/source-repository.html" match="/tags/[^ &quot;&apos;&lt;]*" replace="/trunk" flags="g"/>
                 <replaceregexp match="Generated on .* for " replace="Generated for " flags="g">
                     <fileset dir="target/site/apidocs" includes="**/*.html"/>
-		</replaceregexp>
+      </replaceregexp>
                 </tasks>
             </configuration>
             <goals>
@@ -188,6 +188,12 @@
     </plugins>
 </build>
   <dependencies>
+      <dependency>
+        <groupId>junit</groupId>
+        <artifactId>junit</artifactId>
+        <version>3.8.1</version>
+        <scope>test</scope>
+      </dependency>      
   </dependencies>
   <reporting>
     <excludeDefaults>true</excludeDefaults>  

Modified: logging/log4cxx/trunk/src/main/cpp/inetaddress.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/inetaddress.cpp?rev=577550&r1=577549&r2=577550&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/inetaddress.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/inetaddress.cpp Wed Sep 19 22:05:35 2007
@@ -74,14 +74,18 @@
         // retrieve the IP address of this InetAddress.
         LogString ipAddrString;
         char *ipAddr;
-        apr_sockaddr_ip_get(&ipAddr, currentAddr);
-        Transcoder::decode(ipAddr, strlen(ipAddr), ipAddrString);
+        status = apr_sockaddr_ip_get(&ipAddr, currentAddr);
+      if (status == APR_SUCCESS) {
+         Transcoder::decode(ipAddr, strlen(ipAddr), ipAddrString);
+       }
     
         // retrieve the host name of this InetAddress.
         LogString hostNameString;
         char *hostName;
-        apr_getnameinfo(&hostName, currentAddr, 0);
-        Transcoder::decode(hostName, strlen(hostName), hostNameString);
+        status = apr_getnameinfo(&hostName, currentAddr, 0);
+      if (status == APR_SUCCESS) {
+         Transcoder::decode(hostName, strlen(hostName), hostNameString);
+      }
 
         result.push_back(new InetAddress(hostNameString, ipAddrString));
         currentAddr = currentAddr->next;

Modified: logging/log4cxx/trunk/src/test/cpp/helpers/inetaddresstestcase.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/test/cpp/helpers/inetaddresstestcase.cpp?rev=577550&r1=577549&r2=577550&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/test/cpp/helpers/inetaddresstestcase.cpp (original)
+++ logging/log4cxx/trunk/src/test/cpp/helpers/inetaddresstestcase.cpp Wed Sep 19 22:05:35 2007
@@ -29,7 +29,7 @@
                 CPPUNIT_TEST(testByNameLocal);
                 CPPUNIT_TEST(testAllByNameLocal);
                 CPPUNIT_TEST_EXCEPTION(testUnknownHost, UnknownHostException);
-//                CPPUNIT_TEST(testByNameRemote);
+                CPPUNIT_TEST(testUnreachable);
         CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -68,20 +68,18 @@
          * Tests the UnknownHostException.
          */
         void testUnknownHost() {
-           InetAddressPtr addr = InetAddress::getByName(LOG4CXX_STR("unknown.host.local"));
+           InetAddressPtr addr = InetAddress::getByName(LOG4CXX_STR("unknown.invalid"));
         }
+      
+    /**
+    * Tests an (likely) unreachable address.
+    */
+      void testUnreachable()  {
+       InetAddressPtr addr(InetAddress::getByName(LOG4CXX_STR("192.168.10.254")));
+      LogString addrStr(addr->toString());
+      CPPUNIT_ASSERT_EQUAL(addrStr.size() - 15, addrStr.find(LOG4CXX_STR("/192.168.10.254")));
+   }
 
-        /**
-         * Tests resolving a remote host name.
-         * This test is usually disabled in the test suite because it
-         * probably produces volatile data.
-         */
-        void testByNameRemote() {
-            InetAddressPtr addr = InetAddress::getByName(LOG4CXX_STR("www.apache.org"));
-
-            CPPUNIT_ASSERT(addr->getHostAddress() == LOG4CXX_STR("209.237.227.195"));
-            CPPUNIT_ASSERT(addr->getHostName() == LOG4CXX_STR("minotaur-2.apache.org"));
-        }
 };
 
 

Added: logging/log4cxx/trunk/src/test/java/org/apache/logging/log4cxx/helpers/InetAddressTestCase.java
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/test/java/org/apache/logging/log4cxx/helpers/InetAddressTestCase.java?rev=577550&view=auto
==============================================================================
--- logging/log4cxx/trunk/src/test/java/org/apache/logging/log4cxx/helpers/InetAddressTestCase.java (added)
+++ logging/log4cxx/trunk/src/test/java/org/apache/logging/log4cxx/helpers/InetAddressTestCase.java Wed Sep 19 22:05:35 2007
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+
+package org.apache.logging.log4cxx.helpers;
+
+import junit.framework.TestCase;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+/**
+ * Tests java.net.InetAddress to provide baseline
+ * for log4cxx's log4cxx::helpers::InetAddress.
+ */
+public class InetAddressTestCase extends TestCase
+{
+        /**
+         * Tests the InetAddress::getLocalHost() method.
+         */
+        public void testGetLocalHost() throws Exception {
+           InetAddress addr = InetAddress.getLocalHost();
+
+           assertFalse(addr.getHostName().length() == 0);
+        }
+
+        /**
+         * Tests the InetAddress::getByName() method with the
+         * "localhost" host name.
+         */
+        public void testByNameLocal() throws Exception {
+           InetAddress addr = InetAddress.getByName("localhost");
+
+           assertEquals("127.0.0.1", addr.getHostAddress());
+           assertFalse(addr.getHostName().length() == 0);
+        }
+
+        /**
+         * Tests the InetAddress::getAllByName() method with the
+         * "localhost" host name.
+         */
+        public void testAllByNameLocal() throws Exception {
+           InetAddress[] addr = InetAddress.getAllByName("localhost");
+           assertTrue(addr.length > 0);
+        }
+
+        /**
+         * Tests the UnknownHostException.
+         */
+        public void testUnknownHost() {
+           try {
+            InetAddress.getByName("unknown.invalid");
+            fail("Invalid address should result in UnknownHostException");
+           } catch(UnknownHostException ex) {
+           }
+        }
+
+    /**
+    * Tests an (likely) unreachable address.
+    */
+   public void testUnreachable() throws Exception {
+       InetAddress addr = InetAddress.getByName("192.168.10.254");
+       String addrStr = addr.toString();
+       assertEquals(addrStr.length() - 15, addrStr.indexOf("/192.168.10.254"));
+   }
+}
+