X-Git-Url: http://git.megacz.com/?p=org.ibex.jinetd.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fjinetd%2FMain.java;fp=src%2Forg%2Fibex%2Fjinetd%2FMain.java;h=8e4c41b84f6188eff3c690b9ac90c3a49d935683;hp=e45c6c33ce110371c942a7375d00faec10ac0f62;hb=501b9089d3cf777fc417d9bcddba9bc542a086f9;hpb=583587a3f34a3d2939bcc2b7bcab51b871f2b0c7 diff --git a/src/org/ibex/jinetd/Main.java b/src/org/ibex/jinetd/Main.java index e45c6c3..8e4c41b 100644 --- a/src/org/ibex/jinetd/Main.java +++ b/src/org/ibex/jinetd/Main.java @@ -11,25 +11,36 @@ import java.util.zip.*; public class Main { + // Bootup ////////////////////////////////////////////////////////////////////////////// + public static String ROOT; public static String LOGFILE; public static PrintStream LOGSTREAM; + public static String defaultDomain; - private static void configureRoot() throws Exception { - ROOT = System.getProperty("jinetd.root", null); - if (ROOT == null) { - ROOT = autoDetectRoot(); - System.setProperty("jinetd.root", ROOT); + static { + try { + System.err.println("jinetd starting..."); + ROOT = System.getProperty("jinetd.root", null); + if (ROOT == null) System.setProperty("jinetd.root", ROOT = autoDetectRoot()); + System.err.println(" jinetd.root = " + ROOT); + defaultDomain = System.getProperty("jinetd.hostname", null); + if (defaultDomain==null) try { + java.net.InetAddress localMachine = java.net.InetAddress.getLocalHost(); + defaultDomain = localMachine.getHostName(); + } catch(java.net.UnknownHostException uhe) { defaultDomain = "localhost"; } + System.err.println(" jinetd.hostname = " + defaultDomain); + LOGFILE = System.getProperty("jinetd.logfile", ROOT + File.separatorChar+"log.txt"); + System.err.println(" jinetd.logfile = " + LOGFILE); + System.err.println(" redirecting stdout/stderr to logfile." + LOGFILE); + LOGSTREAM = new PrintStream(new FileOutputStream(LOGFILE, true)); + System.setErr(LOGSTREAM); + System.setOut(LOGSTREAM); + } catch (Throwable e) { + throw new Error(e); } } - private static void configureLogging() throws Exception { - LOGFILE = System.getProperty("jinetd.logfile", ROOT + File.separatorChar+"log.txt"); - LOGSTREAM = new PrintStream(new FileOutputStream(LOGFILE, true)); - System.setErr(LOGSTREAM); - System.setOut(LOGSTREAM); - } - private static String autoDetectRoot() throws Exception { if (!(Main.class.getClassLoader() instanceof URLClassLoader)) throw new Error("unable to detect jinetd.root because my ClassLoader is not an instanceof URLClassLoader"); @@ -53,18 +64,13 @@ public class Main { " was not in any of the ClassLoader URLs"); } - static { - try { - configureRoot(); - configureLogging(); - } catch (Throwable e) { - throw new Error(e); - } + public static void reboot() { + Log.flush(); + System.exit(0); } public static void main(String[] s) throws Exception { - Log.color = true; - Root root = new Root(Root.root); + Root root = new Root(ROOT); while(true) try { if (root != null) { root.scan(); return; } Thread.sleep(100);