|
20 | 20 | import java.io.FileInputStream; |
21 | 21 | import java.io.FileNotFoundException; |
22 | 22 | import java.io.IOException; |
| 23 | +import java.io.InputStream; |
23 | 24 | import java.lang.reflect.Constructor; |
24 | 25 | import java.lang.reflect.InvocationTargetException; |
25 | 26 | import java.util.ArrayList; |
|
36 | 37 | import org.apache.commons.daemon.Daemon; |
37 | 38 | import org.apache.commons.daemon.DaemonContext; |
38 | 39 | import org.apache.commons.daemon.DaemonInitException; |
| 40 | +import org.apache.commons.io.IOUtils; |
39 | 41 | import org.apache.commons.lang.math.NumberUtils; |
40 | 42 | import org.apache.log4j.Logger; |
41 | 43 | import org.apache.log4j.xml.DOMConfigurator; |
@@ -165,22 +167,26 @@ public void setPersistentProperty(String prefix, String name, String value) { |
165 | 167 | _storage.persist(name, value); |
166 | 168 | } |
167 | 169 |
|
168 | | - private void loadProperties() throws ConfigurationException { |
| 170 | + void loadProperties() throws ConfigurationException { |
169 | 171 | final File file = PropertiesUtil.findConfigFile("agent.properties"); |
170 | 172 | if (file == null) { |
171 | 173 | throw new ConfigurationException("Unable to find agent.properties."); |
172 | 174 | } |
173 | 175 |
|
174 | 176 | s_logger.info("agent.properties found at " + file.getAbsolutePath()); |
175 | 177 |
|
| 178 | + InputStream propertiesStream = null; |
176 | 179 | try { |
177 | | - _properties.load(new FileInputStream(file)); |
| 180 | + propertiesStream = new FileInputStream(file); |
| 181 | + _properties.load(propertiesStream); |
178 | 182 | } catch (final FileNotFoundException ex) { |
179 | 183 | throw new CloudRuntimeException("Cannot find the file: " |
180 | 184 | + file.getAbsolutePath(), ex); |
181 | 185 | } catch (final IOException ex) { |
182 | 186 | throw new CloudRuntimeException("IOException in reading " |
183 | 187 | + file.getAbsolutePath(), ex); |
| 188 | + } finally { |
| 189 | + IOUtils.closeQuietly(propertiesStream); |
184 | 190 | } |
185 | 191 | } |
186 | 192 |
|
@@ -304,7 +310,7 @@ public void init(String[] args) throws ConfigurationException { |
304 | 310 | // For KVM agent, do it specially here |
305 | 311 |
|
306 | 312 | File file = new File("/etc/cloudstack/agent/log4j-cloud.xml"); |
307 | | - if(file == null || !file.exists()) { |
| 313 | + if(!file.exists()) { |
308 | 314 | file = PropertiesUtil.findConfigFile("log4j-cloud.xml"); |
309 | 315 | } |
310 | 316 | DOMConfigurator.configureAndWatch(file.getAbsolutePath()); |
|
0 commit comments