make jinetd relocatable
authoradam <adam@megacz.com>
Sat, 24 Jul 2004 05:42:22 +0000 (05:42 +0000)
committeradam <adam@megacz.com>
Sat, 24 Jul 2004 05:42:22 +0000 (05:42 +0000)
darcs-hash:20040724054222-5007d-7cd316d8e672cbcf51c2efe9053c7ff625672413.gz

src/org/ibex/jinetd/Loader.java
src/org/ibex/jinetd/Main.java
src/org/ibex/jinetd/Port.java
src/org/ibex/jinetd/Root.java

index 5c933c7..0d6ca14 100644 (file)
@@ -42,11 +42,11 @@ public class Loader extends Watcher {
             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();
index e32a32c..a8ae366 100644 (file)
@@ -5,12 +5,11 @@ import java.util.*;
 
 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); }
     }
index 2aded0a..f00e0de 100644 (file)
@@ -8,13 +8,13 @@ import java.util.zip.*;
 
 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();
@@ -86,8 +86,8 @@ public class Port extends Loader {
     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"));
index b844c9b..6b5467d 100644 (file)
@@ -6,6 +6,7 @@ import java.net.*;
 
 public class Root extends Loader {
 
+    public static String root = System.getProperty("jinetd.root", "/jinetd");
     private final Host host;
     private final Watched port;
 
@@ -32,7 +33,7 @@ public class Root extends Loader {
             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();
@@ -49,7 +50,7 @@ public class Root extends Loader {
             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);