You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2020/10/27 06:04:20 UTC
[felix-dev] branch master updated: FELIX-6308 : Bad File Descriptor
while persisting service configuration. Potential fix
This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git
The following commit(s) were added to refs/heads/master by this push:
new 36f7c12 FELIX-6308 : Bad File Descriptor while persisting service configuration. Potential fix
36f7c12 is described below
commit 36f7c12aed9fb968362020b27ba88883f3600261
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue Oct 27 07:02:45 2020 +0100
FELIX-6308 : Bad File Descriptor while persisting service configuration. Potential fix
---
.../felix/cm/file/FilePersistenceManager.java | 26 ++++++----------------
1 file changed, 7 insertions(+), 19 deletions(-)
diff --git a/configadmin/src/main/java/org/apache/felix/cm/file/FilePersistenceManager.java b/configadmin/src/main/java/org/apache/felix/cm/file/FilePersistenceManager.java
index 91c8419..bffffc5 100644
--- a/configadmin/src/main/java/org/apache/felix/cm/file/FilePersistenceManager.java
+++ b/configadmin/src/main/java/org/apache/felix/cm/file/FilePersistenceManager.java
@@ -719,7 +719,6 @@ public class FilePersistenceManager implements PersistenceManager
@SuppressWarnings("rawtypes")
private void _store( final String pid, final Dictionary props ) throws IOException
{
- OutputStream out = null;
File tmpFile = null;
try
{
@@ -729,17 +728,17 @@ public class FilePersistenceManager implements PersistenceManager
File cfgDir = cfgFile.getParentFile();
cfgDir.mkdirs();
- // write the configuration to a temporary file
- tmpFile = File.createTempFile( cfgFile.getName(), TMP_EXT, cfgDir );
- out = new FileOutputStream( tmpFile );
- ConfigurationHandler.write( out, props );
- out.close();
-
// after writing the file, rename it but ensure, that no other
// might at the same time open the new file
// see load(File)
synchronized ( this )
{
+ // write the configuration to a temporary file
+ tmpFile = File.createTempFile( cfgFile.getName(), TMP_EXT, cfgDir );
+ try(OutputStream out = new FileOutputStream( tmpFile )) {
+ ConfigurationHandler.write( out, props );
+ }
+
// make sure the cfg file does not exists (just for sanity)
if ( cfgFile.exists() )
{
@@ -756,22 +755,11 @@ public class FilePersistenceManager implements PersistenceManager
{
throw new IOException( "Failed to rename configuration file from '" + tmpFile + "' to '" + cfgFile );
}
+ tmpFile = null;
}
}
finally
{
- if ( out != null )
- {
- try
- {
- out.close();
- }
- catch ( IOException ioe )
- {
- // ignore
- }
- }
-
if (tmpFile != null && tmpFile.exists())
{
tmpFile.delete();