Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=46967 and make behaviour consi...
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 8 Apr 2009 12:59:21 +0000 (12:59 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 8 Apr 2009 12:59:21 +0000 (12:59 +0000)
Based on a patch provided by Kirk Wolf

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@763228 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/session/ManagerBase.java

index 9a46d24..5c67855 100644 (file)
@@ -223,7 +223,11 @@ public abstract class ManagerBase implements Manager, MBeanRegistration {
 
     private class PrivilegedSetRandomFile implements PrivilegedAction<DataInputStream>{
         
-        public DataInputStream run(){               
+        public PrivilegedSetRandomFile(String s) {
+            devRandomSource = s;
+        }
+        
+        public DataInputStream run(){
             try {
                 File f=new File( devRandomSource );
                 if( ! f.exists() ) return null;
@@ -233,8 +237,18 @@ public abstract class ManagerBase implements Manager, MBeanRegistration {
                     log.debug( "Opening " + devRandomSource );
                 return randomIS;
             } catch (IOException ex){
+                log.warn("Error reading " + devRandomSource, ex);
+                if (randomIS != null) {
+                    try {
+                        randomIS.close();
+                    } catch (Exception e) {
+                        log.warn("Failed to close randomIS.");
+                    }
+                }
+                devRandomSource = null;
+                randomIS=null;
                 return null;
-            }
+            }            
         }
     }
 
@@ -505,10 +519,10 @@ public abstract class ManagerBase implements Manager, MBeanRegistration {
      *  - so use it if available.
      */
     public void setRandomFile( String s ) {
-        // as a hack, you can use a static file - and genarate the same
+        // as a hack, you can use a static file - and generate the same
         // session ids ( good for strange debugging )
         if (Globals.IS_SECURITY_ENABLED){
-            randomIS = AccessController.doPrivileged(new PrivilegedSetRandomFile());
+            randomIS = AccessController.doPrivileged(new PrivilegedSetRandomFile(s));
         } else {
             try{
                 devRandomSource=s;
@@ -519,12 +533,15 @@ public abstract class ManagerBase implements Manager, MBeanRegistration {
                 if( log.isDebugEnabled() )
                     log.debug( "Opening " + devRandomSource );
             } catch( IOException ex ) {
-                try {
-                    randomIS.close();
-                } catch (Exception e) {
-                    log.warn("Failed to close randomIS.");
+                log.warn("Error reading " + devRandomSource, ex);
+                if (randomIS != null) {
+                    try {
+                        randomIS.close();
+                    } catch (Exception e) {
+                        log.warn("Failed to close randomIS.");
+                    }
                 }
-                
+                devRandomSource = null;
                 randomIS=null;
             }
         }