[rfc] netx: do not create unnecessary native directories

Deepak Bhole dbhole at redhat.com
Mon Oct 18 09:29:34 PDT 2010


* Omair Majid <omajid at redhat.com> [2010-10-08 11:47]:
> Hi,
> 
> Netx currently creates one or more directories under /tmp/ to hold
> native libraries any time it launches an application. The attached
> patch tries to reduce the clutter caused by these directories. The
> patch ensures that a directory for holding native files is only
> created if there are native libraries. The patch also installs a
> shutdown hook to delete the directory containing the native files.
> 
> Any thoughts or comments?
> 
> Cheers,
> Omair

> diff -r 4698e476b886 ChangeLog
> --- a/ChangeLog	Fri Oct 08 11:06:14 2010 -0400
> +++ b/ChangeLog	Fri Oct 08 11:33:49 2010 -0400
> @@ -1,3 +1,11 @@
> +2010-10-08  Omair Majid  <omajid at redhat.com>
> +
> +	* netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java
> +	(JNLPClassLoader): Call installShutdownHooks.
> +	(installShutdownHooks): New method. Installs a shutdown hook to
> +	recursively delete the contents of nativeDir.
> +	(activateNative): Only create a nativeDir if there are native libraries.
> +
>  2010-10-08  Omair Majid  <omajid at redhat.com>
>  
>  	* NEWS: Updated
> diff -r 4698e476b886 netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java
> --- a/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java	Fri Oct 08 11:06:14 2010 -0400
> +++ b/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java	Fri Oct 08 11:33:49 2010 -0400
> @@ -59,6 +59,7 @@
>  import net.sourceforge.jnlp.cache.UpdatePolicy;
>  import net.sourceforge.jnlp.security.SecurityWarningDialog;
>  import net.sourceforge.jnlp.tools.JarSigner;
> +import net.sourceforge.jnlp.util.FileUtils;
>  import sun.misc.JarIndex;
>  
>  /**
> @@ -169,6 +170,41 @@
>  
>          setSecurity();
>  
> +        installShutdownHooks();
> +
> +    }
> +
> +    /**
> +     * Install JVM shutdown hooks to clean up resources allocated by this
> +     * ClassLoader.
> +     */
> +    private void installShutdownHooks() {
> +        Runtime.getRuntime().addShutdownHook(new Thread() {
> +            @Override
> +            public void run() {
> +                if (JNLPRuntime.isDebug()) {
> +                    System.out.println("Cleaing up native directory" + nativeDir.getAbsolutePath());
> +                }
> +

Typo there in spelling of cleaning :)

Rest looks fine to me. Assuming you have tested this, OK for commit to
HEAD and all branches.

Cheers,
Deepak

> +                /*
> +                 * Delete only the native dir created by this classloader (if
> +                 * there is one). Other classloaders (parent, peers) will all
> +                 * cleanup things they created
> +                 */
> +                if (nativeDir != null) {
> +                    try {
> +                        FileUtils.recursiveDelete(nativeDir,
> +                                new File(System.getProperty("java.io.tmpdir")));
> +                    } catch (IOException e) {
> +                        /*
> +                         * failed to delete a file in tmpdir, no big deal (not
> +                         * to mention that the VM is shutting down at this
> +                         * point so no much we can do)
> +                         */
> +                    }
> +                }
> +            }
> +        });
>      }
>  
>      private void setSecurity() throws LaunchException {
> @@ -741,9 +777,6 @@
>          if (localFile == null)
>              return;
>  
> -        if (nativeDir == null)
> -            nativeDir = getNativeDir();
> -
>          String[] librarySuffixes = { ".so", ".dylib", ".jnilib", ".framework", ".dll" };
>  
>          try {
> @@ -770,10 +803,14 @@
>                      continue;
>                  }
>  
> +                if (nativeDir == null)
> +                    nativeDir = getNativeDir();
> +
>                  File outFile = new File(nativeDir, name);
>  
>                  CacheUtil.streamCopy(jarFile.getInputStream(e),
>                                       new FileOutputStream(outFile));
> +
>              }
>          }
>          catch (IOException ex) {




More information about the distro-pkg-dev mailing list