From a6686cbed425991304dbb94194afe7b7af74aba9 Mon Sep 17 00:00:00 2001 From: mathiasdm Date: Mon, 14 Feb 2011 17:12:12 +0000 Subject: [PATCH] Fix headless issue without reboot. --- .../src/net/i2p/desktopgui/Main.java | 3 +- .../i2p/router/web/RouterConsoleRunner.java | 57 ++++--------------- history.txt | 3 + .../src/net/i2p/router/RouterVersion.java | 2 +- 4 files changed, 18 insertions(+), 47 deletions(-) diff --git a/apps/desktopgui/src/net/i2p/desktopgui/Main.java b/apps/desktopgui/src/net/i2p/desktopgui/Main.java index 8cd1ea707d..993970e30c 100644 --- a/apps/desktopgui/src/net/i2p/desktopgui/Main.java +++ b/apps/desktopgui/src/net/i2p/desktopgui/Main.java @@ -56,9 +56,10 @@ public class Main { */ public static void beginStartup(String[] args) { try { - String headless = RouterManager.getRouterContext().getProperty("router.isHeadless"); + String headless = System.getProperty("java.awt.headless"); boolean isHeadless = Boolean.parseBoolean(headless); if(isHeadless) { + log.warn("Headless environment: not starting desktopgui!"); return; } } diff --git a/apps/routerconsole/java/src/net/i2p/router/web/RouterConsoleRunner.java b/apps/routerconsole/java/src/net/i2p/router/web/RouterConsoleRunner.java index 9f280ef2af..fe53abdb11 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/RouterConsoleRunner.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/RouterConsoleRunner.java @@ -55,50 +55,17 @@ public class RouterConsoleRunner { private static final String DEFAULT_WEBAPPS_DIR = "./webapps/"; private static final String USAGE = "Bad RouterConsoleRunner arguments, check clientApp.0.args in your clients.config file! " + "Usage: [[port host[,host]] [-s sslPort [host[,host]]] [webAppsDir]]"; - private static final String PROP_HEADLESS = "router.isHeadless"; static { System.setProperty("org.mortbay.http.Version.paranoid", "true"); //Check if we are in a headless environment, set properties accordingly - List contexts = RouterContext.listContexts(); - if(contexts != null && contexts.size() > 0) { - RouterContext context = contexts.get(0); - String headless = context.getProperty(PROP_HEADLESS); - if(headless == null) { - /* - * Let's check if we are in a headless environment. - * We do this by setting headless to false - * and trying to get the graphics environment. - * If this fails, we should be headless. - */ - System.setProperty("java.awt.headless", "false"); - try { - GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); - ge.isHeadlessInstance(); - context.setProperty(PROP_HEADLESS, "false"); - } - catch(InternalError e) { - context.setProperty(PROP_HEADLESS, "true"); - } - context.router().setConfigSetting(PROP_HEADLESS, context.getProperty(PROP_HEADLESS)); - context.router().saveConfig(); - context.router().shutdown(0); - } - boolean isHeadless = true; - try { - isHeadless = Boolean.parseBoolean(headless); - } - catch(Exception e) { - //Incorrect setting, let's choose headless for safety - isHeadless = true; - } - if(isHeadless) { - System.setProperty("java.awt.headless", "true"); - } - else { - System.setProperty("java.awt.headless", "false"); - } + String headless = "java.awt.headless"; + if(GraphicsEnvironment.isHeadless()) { + System.setProperty(headless, "true"); + } + else { + System.setProperty(headless, "false"); } } @@ -359,13 +326,13 @@ public class RouterConsoleRunner { } try { - //TODO: move away from routerconsole into a separate application. - //ApplicationManager? - VersionComparator v = new VersionComparator(); - if(v.compare(System.getProperty("java.runtime.version"), "1.6") >= 0) { + //TODO: move away from routerconsole into a separate application. + //ApplicationManager? + VersionComparator v = new VersionComparator(); + if(v.compare(System.getProperty("java.runtime.version"), "1.6") >= 0) { String[] args = new String[0]; - net.i2p.desktopgui.Main.beginStartup(args); - } + net.i2p.desktopgui.Main.beginStartup(args); + } } catch (Throwable t) { t.printStackTrace(); } diff --git a/history.txt b/history.txt index 550bf53041..967b5b7632 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,6 @@ +2011-02-14 Mathiasdm + * Fix headless issue without reboot + 2011-02-13 zzz * Connect Client: Minor NPE fix cleanup * JobQueue: Prevet NPE at shutdown (thanks liberty) diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index 7ca1a3ec2c..5a58b19bc2 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -18,7 +18,7 @@ public class RouterVersion { /** deprecated */ public final static String ID = "Monotone"; public final static String VERSION = CoreVersion.VERSION; - public final static long BUILD = 10; + public final static long BUILD = 11; /** for example "-test" */ public final static String EXTRA = "";