X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Forg%2Fibex%2Fjinetd%2FMain.java;h=037527e861091f1a51c8b637a0f1fdc8226b004b;hb=8c3227dda12abaa856c255d27c3811e9c29167e3;hp=a8ae366ba177a3173bc9d44a95c13a74b139a262;hpb=5a70dae9ae337182636a4c4d59951019a24e9f34;p=org.ibex.jinetd.git diff --git a/src/org/ibex/jinetd/Main.java b/src/org/ibex/jinetd/Main.java index a8ae366..037527e 100644 --- a/src/org/ibex/jinetd/Main.java +++ b/src/org/ibex/jinetd/Main.java @@ -1,16 +1,80 @@ +// Copyright 2000-2005 the Contributors, as shown in the revision logs. +// Licensed under the Apache Public Source License 2.0 ("the License"). +// You may not use this file except in compliance with the License. + package org.ibex.jinetd; import org.ibex.util.*; import java.io.*; +import java.net.*; import java.util.*; +import java.util.zip.*; public class Main { + // Bootup ////////////////////////////////////////////////////////////////////////////// + + public static String ROOT; + public static String LOGFILE; + public static PrintStream LOGSTREAM; + public static String defaultDomain; + + public static void init() { + 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 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"); + URL[] urls = ((URLClassLoader)Main.class.getClassLoader()).getURLs(); + for(int i=0; i