File bindir = new File(this.path + File.separatorChar + "BIN"); bindir.mkdirs();
File libdir = new File(this.path + File.separatorChar + "LIB");
String classpath = System.getProperty("java.class.path");
- String [] l = new File("/jinetd/LIB/").list();
+ String [] l = new File(Root.root + "/LIB/").list();
for(int i=0; i<l.length; i++) {
if (!l[i].endsWith(".jar")) continue;
classpath += File.pathSeparatorChar;
- classpath += "/jinetd/LIB/" + l[i];
+ classpath += Root.root + "/LIB/" + l[i];
}
String bootclasspath = System.getProperty("sun.boot.class.path", "");
Vec args = new Vec();
public class Main {
- public static Root root = new Root(System.getProperty("jinetd.root", "/jinetd"));
public static void main(String[] s) throws Exception {
Log.color = true;
+ Root root = new Root(Root.root);
while(true) try {
Thread.sleep(1000);
- //Log.info(Main.class, "scanning...");
if (root != null) root.scan();
} catch (Exception e) { Log.error(Main.class, e); }
}
public class Port extends Loader {
- private final NetworkInterface iface;
+ private final InetAddress bindTo;
private final int port;
private final Thread listener;
- public Port(String path, NetworkInterface iface, int port) {
+ public Port(String path, InetAddress bindTo, int port) {
super(path);
- this.iface = iface;
+ this.bindTo = bindTo;
this.port = port;
this.listener = new PortThread();
listener.start();
private class PortThread extends Thread {
public void run() {
try {
- Log.warn(this, "Now listening on interface " + iface + ", port " + port);
- ServerSocket ss = new ServerSocket(port);
+ Log.warn(this, "Now listening on address " + bindTo + ", port " + port);
+ ServerSocket ss = bindTo == null ? new ServerSocket(port) : new ServerSocket(port, 0, bindTo);
for(Socket s = ss.accept(); ; s = ss.accept()) try {
Log.warn(this, "accepted connection on port " + port);
dispatch(new Connection(s, "megacz.com"));
public class Root extends Loader {
+ public static String root = System.getProperty("jinetd.root", "/jinetd");
private final Host host;
private final Watched port;
Log.warn(this, "/host changed");
} else if (w.part.equals("port")) {
Log.warn(this, "/port changed");
- } else if (w.getAbsolutePath().startsWith("/jinetd/LIB/")) {
+ } else if (w.getAbsolutePath().startsWith(Root.root + "/LIB/")) {
if (w.lastModifiedAtLastScan != -1) {
Log.error(this, "jinetd upgraded; bouncing the JVM....");
reboot();
String portnum = part.indexOf(':') == -1 ? part : part.substring(part.indexOf(':') + 1);
try {
return new Port(this.path + File.separatorChar + part,
- ipaddr == null ? null : NetworkInterface.getByInetAddress(InetAddress.getByName(ipaddr)),
+ ipaddr == null ? null : InetAddress.getByName(ipaddr),
portnum.equals("*") ? 0 : Integer.parseInt(portnum));
} catch (UnknownHostException e) { Log.warn(this, "can't resolve host for port directory: " + part);
} catch (NumberFormatException e) { Log.warn(this, "invalid port directory: " + part);