diff --git a/history.txt b/history.txt index b81345f47..90eaf47f6 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,7 @@ +2018-05-26 zzz + * Router: Fix wrapper.config path in OOM message when installed as + Debian package, but not running as a service (ticket #2223) + 2018-05-25 zzz * Console: Fix changes to wrong tunnel on /configtunnels (ticket #2227) * i2ptunnel: Fix dup tunnels clicking generate on new tunnel (ticket #2225) diff --git a/router/java/src/net/i2p/router/tasks/OOMListener.java b/router/java/src/net/i2p/router/tasks/OOMListener.java index 9631d81a0..f725f9187 100644 --- a/router/java/src/net/i2p/router/tasks/OOMListener.java +++ b/router/java/src/net/i2p/router/tasks/OOMListener.java @@ -49,26 +49,16 @@ public class OOMListener implements I2PThread.OOMEventListener { log.log(Log.CRIT, "Thread ran out of memory, shutting down I2P", oom); log.log(Log.CRIT, "free mem: " + Runtime.getRuntime().freeMemory() + " total mem: " + Runtime.getRuntime().totalMemory()); - // Can't find any System property or wrapper property that gives - // you the actual config file path, have to guess - String path; - if (SystemVersion.isLinuxService()) { - if (SystemVersion.isGentoo()) - path = "/usr/share/i2p"; - else - path = "/etc/i2p"; - } else { - path = _context.getBaseDir().toString(); - } + String path = getWrapperConfigPath(_context); if (_context.hasWrapper()) { log.log(Log.CRIT, "To prevent future shutdowns, increase wrapper.java.maxmemory in " + - path + File.separatorChar + "wrapper.config"); + path); } else if (!SystemVersion.isWindows()) { log.log(Log.CRIT, "To prevent future shutdowns, increase MAXMEMOPT in " + - path + File.separatorChar + "runplain.sh or /usr/bin/i2prouter-nowrapper"); + _context.getBaseDir() + File.separatorChar + "runplain.sh or /usr/bin/i2prouter-nowrapper"); } else { log.log(Log.CRIT, "To prevent future shutdowns, run the restartable version of I2P, and increase wrapper.java.maxmemory in " + - path + File.separatorChar + "wrapper.config"); + path); } } catch (OutOfMemoryError oome) {} try { @@ -81,4 +71,41 @@ public class OOMListener implements I2PThread.OOMEventListener { _context.router().shutdown(Router.EXIT_OOM); } catch (OutOfMemoryError oome) {} } + + /** + * Best guess if running from a Debian package + * @since 0.9.35 + */ + private static boolean isDebianPackage(RouterContext ctx) { + boolean isDebian = !SystemVersion.isWindows() && !SystemVersion.isMac() && + !SystemVersion.isGentoo() && !SystemVersion.isAndroid() && + System.getProperty("os.name").startsWith("Linux") && + (new File("/etc/debian_version")).exists(); + return isDebian && + ctx.getBaseDir().getPath().equals("/usr/share/i2p") && + ctx.getBooleanProperty("router.updateDisabled"); + } + + /** + * Best guess of wrapper.config path. + * Can't find any System property or wrapper property that gives + * you the actual config file path, have to guess. + * Does not necessarily exist. + * @since 0.9.35 consolidated from above and BloomFilterIVValidator + */ + public static String getWrapperConfigPath(RouterContext ctx) { + File path; + if (SystemVersion.isLinuxService()) { + if (SystemVersion.isGentoo()) + path = new File("/usr/share/i2p"); + else + path = new File("/etc/i2p"); + } else if (isDebianPackage(ctx)) { + path = new File("/etc/i2p"); + } else { + path = ctx.getBaseDir(); + } + path = new File(path, "wrapper.config"); + return path.getPath(); + } } diff --git a/router/java/src/net/i2p/router/tunnel/BloomFilterIVValidator.java b/router/java/src/net/i2p/router/tunnel/BloomFilterIVValidator.java index 61a52e2a3..dc71b4cb5 100644 --- a/router/java/src/net/i2p/router/tunnel/BloomFilterIVValidator.java +++ b/router/java/src/net/i2p/router/tunnel/BloomFilterIVValidator.java @@ -4,6 +4,7 @@ import java.io.File; import net.i2p.data.DataHelper; import net.i2p.router.RouterContext; +import net.i2p.router.tasks.OOMListener; import net.i2p.router.util.DecayingBloomFilter; import net.i2p.router.util.DecayingHashSet; import net.i2p.util.Log; @@ -102,27 +103,20 @@ class BloomFilterIVValidator implements IVValidator { private void warn(long maxMemory, int KBps, long recMaxMem, int threshKBps) { if (SystemVersion.isAndroid()) return; - // Can't find any System property or wrapper property that gives - // you the actual config file path, have to guess - String path; - if (SystemVersion.isLinuxService()) { - path = "/etc/i2p"; - } else { - path = _context.getBaseDir().toString(); - } + String path = OOMListener.getWrapperConfigPath(_context); String msg = "Configured for " + DataHelper.formatSize(KBps *1024L) + "Bps share bandwidth but only " + DataHelper.formatSize(maxMemory) + "B available memory."; if (_context.hasWrapper()) { msg += " Recommend increasing wrapper.java.maxmemory in " + - path + File.separatorChar + "wrapper.config"; + path; } else if (!SystemVersion.isWindows()) { msg += " Recommend increasing MAXMEMOPT in " + - path + File.separatorChar + "runplain.sh or /usr/bin/i2prouter-nowrapper"; + _context.getBaseDir() + File.separatorChar + "runplain.sh or /usr/bin/i2prouter-nowrapper"; } else { msg += " Recommend running the restartable version of I2P, and increasing wrapper.java.maxmemory in " + - path + File.separatorChar + "wrapper.config"; + path; } // getMaxMemory() returns significantly lower than wrapper config, so add 10% msg += " to at least " + (recMaxMem * 11 / 10 / (1024*1024)) + " (MB)" +