You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2009/12/15 20:00:24 UTC

svn commit: r890942 - in /tomcat/tc6.0.x/trunk: STATUS.txt java/org/apache/catalina/connector/Connector.java java/org/apache/catalina/core/AprLifecycleListener.java webapps/docs/changelog.xml

Author: markt
Date: Tue Dec 15 19:00:23 2009
New Revision: 890942

URL: http://svn.apache.org/viewvc?rev=890942&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=48300
Only the APR lifecycle listener should try and initialise APR

Modified:
    tomcat/tc6.0.x/trunk/STATUS.txt
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/Connector.java
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/AprLifecycleListener.java
    tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml

Modified: tomcat/tc6.0.x/trunk/STATUS.txt
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=890942&r1=890941&r2=890942&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/STATUS.txt (original)
+++ tomcat/tc6.0.x/trunk/STATUS.txt Tue Dec 15 19:00:23 2009
@@ -394,12 +394,6 @@
   +1: markt
   -1: 
 
-* Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=48300
-  Only the APR lifecycle listener should try and initialise APR
-  http://people.apache.org/~markt/patches/2009-11-27-bug48300-tc6.patch
-  +1: markt, jfclere, jim
-  -1: 
-
 * Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=47342
   Fix NPE on replicated context start
   Patch provided by Keiichi Fujino

Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/Connector.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/Connector.java?rev=890942&r1=890941&r2=890942&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/Connector.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/Connector.java Tue Dec 15 19:00:23 2009
@@ -18,7 +18,6 @@
 
 package org.apache.catalina.connector;
 
-import java.lang.reflect.Method;
 import java.net.URLEncoder;
 import java.util.HashMap;
 
@@ -32,6 +31,7 @@
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.LifecycleListener;
 import org.apache.catalina.Service;
+import org.apache.catalina.core.AprLifecycleListener;
 import org.apache.catalina.core.StandardEngine;
 import org.apache.catalina.util.LifecycleSupport;
 import org.apache.catalina.util.StringManager;
@@ -605,54 +605,6 @@
 
     }
     
-    // ---------------------------------------------- APR Version Constants
-
-    private static final int TCN_REQUIRED_MAJOR = 1;
-    private static final int TCN_REQUIRED_MINOR = 1;
-    private static final int TCN_REQUIRED_PATCH = 17;
-    private static boolean aprInitialized = false;
-
-    // APR init support
-    private static synchronized void initializeAPR()
-    {
-        if (aprInitialized) {
-            return;
-        }
-        int major = 0;
-        int minor = 0;
-        int patch = 0;
-        try {
-            String methodName = "initialize";
-            Class paramTypes[] = new Class[1];
-            paramTypes[0] = String.class;
-            Object paramValues[] = new Object[1];
-            paramValues[0] = null;
-            Class clazz = Class.forName("org.apache.tomcat.jni.Library");
-            Method method = clazz.getMethod(methodName, paramTypes);
-            method.invoke(null, paramValues);
-            major = clazz.getField("TCN_MAJOR_VERSION").getInt(null);
-            minor = clazz.getField("TCN_MINOR_VERSION").getInt(null);
-            patch = clazz.getField("TCN_PATCH_VERSION").getInt(null);
-        } catch (Throwable t) {
-            return;
-        }
-        if ((major != TCN_REQUIRED_MAJOR) ||
-            (minor != TCN_REQUIRED_MINOR) ||
-            (patch <  TCN_REQUIRED_PATCH)) {
-            try {
-                // Terminate the APR in case the version
-                // is below required.
-                String methodName = "terminate";
-                Method method = Class.forName("org.apache.tomcat.jni.Library")
-                                    .getMethod(methodName, (Class [])null);
-                method.invoke(null, (Object []) null);
-            } catch (Throwable t) {
-                // Ignore
-            }
-            return;
-        }
-        aprInitialized = true;
-    }
 
     /**
      * Set the Coyote protocol which will be used by the connector.
@@ -661,10 +613,7 @@
      */
     public void setProtocol(String protocol) {
 
-        // Test APR support
-        initializeAPR();
-
-        if (aprInitialized) {
+        if (AprLifecycleListener.isAprAvailable()) {
             if ("HTTP/1.1".equals(protocol)) {
                 setProtocolHandlerClassName
                     ("org.apache.coyote.http11.Http11AprProtocol");

Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/AprLifecycleListener.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/AprLifecycleListener.java?rev=890942&r1=890941&r2=890942&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/AprLifecycleListener.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/AprLifecycleListener.java Tue Dec 15 19:00:23 2009
@@ -34,7 +34,7 @@
 /**
  * Implementation of <code>LifecycleListener</code> that will init and
  * and destroy APR.
- *
+ * 
  * @author Remy Maucherat
  * @author Filip Hanik
  * @version $Revision$ $Date$
@@ -49,7 +49,7 @@
     /**
      * The string manager for this package.
      */
-    protected StringManager sm =
+    protected static StringManager sm =
         StringManager.getManager(Constants.Package);
 
 
@@ -67,6 +67,13 @@
     protected static String SSLRandomSeed = "builtin";
     protected static boolean sslInitialized = false;
     protected static boolean aprInitialized = false;
+    protected static boolean sslAvailable = false;
+    protected static boolean aprAvailable = false;
+
+    public static boolean isAprAvailable() {
+        init();
+        return aprAvailable;
+    }
 
     // ---------------------------------------------- LifecycleListener Methods
 
@@ -78,8 +85,8 @@
     public void lifecycleEvent(LifecycleEvent event) {
 
         if (Lifecycle.INIT_EVENT.equals(event.getType())) {
-            aprInitialized = init();
-            if (aprInitialized) {
+            init();
+            if (aprAvailable) {
                 try {
                     initializeSSL();
                 } catch (Throwable t) {
@@ -91,7 +98,7 @@
                 }
             }
         } else if (Lifecycle.AFTER_STOP_EVENT.equals(event.getType())) {
-            if (!aprInitialized) {
+            if (!aprAvailable) {
                 return;
             }
             try {
@@ -117,14 +124,16 @@
         method.invoke(null, (Object []) null);
     }
 
-    private boolean init()
+    private static void init()
     {
         int major = 0;
         int minor = 0;
         int patch = 0;
         if (aprInitialized) {
-            return true;    
+            return;    
         }
+        aprInitialized = true;
+        
         try {
             String methodName = "initialize";
             Class paramTypes[] = new Class[1];
@@ -145,7 +154,7 @@
                 log.debug(sm.getString("aprListener.aprInit",
                         System.getProperty("java.library.path")), t);
             }
-            return false;
+            return;
         }
         if ((major != TCN_REQUIRED_MAJOR)  ||
             (minor != TCN_REQUIRED_MINOR) ||
@@ -162,7 +171,7 @@
             } catch (Throwable t) {
                 // Ignore
             }
-            return false;
+            return;
         }
         if (patch <  TCN_RECOMMENDED_PV) {
             if (!log.isDebugEnabled()) {
@@ -190,7 +199,7 @@
         // Log APR flags
         log.info(sm.getString("aprListener.flags", Library.APR_HAVE_IPV6, Library.APR_HAS_SENDFILE, 
                 Library.APR_HAS_SO_ACCEPTFILTER, Library.APR_HAS_RANDOM));
-        return true;
+        aprAvailable = true;
     }
 
     private static synchronized void initializeSSL()
@@ -205,6 +214,8 @@
              //only once per VM
             return;
         }
+        sslInitialized = true;
+
         String methodName = "randSet";
         Class paramTypes[] = new Class[1];
         paramTypes[0] = String.class;
@@ -220,7 +231,7 @@
         method = clazz.getMethod(methodName, paramTypes);
         method.invoke(null, paramValues);
  
-        sslInitialized = true;
+        sslAvailable = true;
     }
 
     public String getSSLEngine() {
@@ -238,4 +249,5 @@
     public void setSSLRandomSeed(String SSLRandomSeed) {
         this.SSLRandomSeed = SSLRandomSeed;
     }
+    
 }

Modified: tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml?rev=890942&r1=890941&r2=890942&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Tue Dec 15 19:00:23 2009
@@ -343,6 +343,10 @@
         Provide a workaround for CVE-2009-3555, the TLS renegotiation issue for
         the default Blocking IO Java connector.
       </fix>
+      <fix>
+        <bug>48300</bug>: Only the APR lifecycle listener should try and
+        initialise APR. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Jasper">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org