[libbluray-devel] Improve BD-J stack initialization
hpi1
git at videolan.org
Sun Nov 1 18:52:03 CET 2015
libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Sun Nov 1 19:48:18 2015 +0200| [fef86d1dddf9fe9e5de195398dafc024b52bc6fc] | committer: hpi1
Improve BD-J stack initialization
- separate initializations that need to be done only once
- handle exceptions in non-fatal initializations
> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=fef86d1dddf9fe9e5de195398dafc024b52bc6fc
---
src/libbluray/bdj/java/org/videolan/Libbluray.java | 43 ++++++++++++++------
1 file changed, 30 insertions(+), 13 deletions(-)
diff --git a/src/libbluray/bdj/java/org/videolan/Libbluray.java b/src/libbluray/bdj/java/org/videolan/Libbluray.java
index c9db9a1..f2f6078 100644
--- a/src/libbluray/bdj/java/org/videolan/Libbluray.java
+++ b/src/libbluray/bdj/java/org/videolan/Libbluray.java
@@ -52,14 +52,7 @@ public class Libbluray {
/* hook system properties: make "user.dir" point to current Xlet home directory */
- private static boolean propertiesHooked = false;
-
private static void hookProperties() {
- if (propertiesHooked) {
- return;
- }
- propertiesHooked = true;
-
java.util.Properties p = new java.util.Properties(System.getProperties()) {
public String getProperty(String key) {
if (key.equals("user.dir")) {
@@ -74,6 +67,35 @@ public class Libbluray {
System.setProperties(p);
}
+ private static boolean initOnce = false;
+ private static void initOnce() {
+ if (initOnce) {
+ return;
+ }
+ initOnce = true;
+
+ /* hook system properties (provide Xlet-specific user.dir) */
+ try {
+ hookProperties();
+ } catch (Throwable t) {
+ System.err.println("hookProperties() failed: " + t);
+ }
+
+ /* hook class loading (fix invalid class files) */
+ try {
+ sun.misc.ClassFileTransformer.add(new BDJClassFileTransformer());
+ } catch (Throwable t) {
+ System.err.println("Adding class file transformer failed: " + t);
+ }
+
+ /* hook sockets (limit network connections) */
+ try {
+ BDJSocketFactory.init();
+ } catch (Throwable t) {
+ System.err.println("Hooking socket factory failed: " + t + "\n" + Logger.dumpStack(t));
+ }
+ }
+
private static String canonicalize(String path, boolean create) {
try {
File dir = new File(path);
@@ -91,10 +113,7 @@ public class Libbluray {
private static void init(long nativePointer, String discID, String discRoot,
String persistentRoot, String budaRoot) {
- hookProperties();
-
- /* hook calss loading */
- sun.misc.ClassFileTransformer.add(new BDJClassFileTransformer());
+ initOnce();
/* set up directories */
persistentRoot = canonicalize(persistentRoot, true);
@@ -190,8 +209,6 @@ public class Libbluray {
System.setProperty("bluray.network.connected", "YES");
- BDJSocketFactory.init();
-
try {
System.setSecurityManager(new BDJSecurityManager(discRoot, persistentRoot, budaRoot));
} catch (Exception ex) {
More information about the libbluray-devel
mailing list