Skip to content

A free, open-source alternative to Burp Suite: an intercepting proxy and web app security testing suite with Repeater, Intruder, Collaborator and a built-in OWASP ZAP scanner. Linux, AGPL-3.0.

Restart from a packaged Linux build

scottsturrockb60b283a9102
diff --git a/src/opensuite/ui/UiScale.java b/src/opensuite/ui/UiScale.java
index bd5c629..edb0665 100644
--- a/src/opensuite/ui/UiScale.java
+++ b/src/opensuite/ui/UiScale.java
@@ -73,6 +73,45 @@ public final class UiScale {
*
* @return true if a relaunch was started (caller should return/stop).
*/
+ /**
+ * Inside an AppImage the program runs from a mount that is taken away the moment this
+ * process ends, so a copy started from there dies with it, or lives on without its files.
+ * The image itself is started again instead: it makes a mount of its own, and its start
+ * script works out the scale and the memory limit from the settings as on any start.
+ */
+ /**
+ * The packaged launcher sets this for itself before it loads Java. A launcher that finds it
+ * already set takes its arguments for Java's own and reads no settings of the package: a copy
+ * started with it either prints Java's usage and ends, or refuses the first argument.
+ */
+ static final String LAUNCHER_MARK = "_JPACKAGE_LAUNCHER";
+
+ private static boolean relaunchAppImage(String[] args) throws java.io.IOException {
+ String image = System.getenv("APPIMAGE");
+ if (image == null || image.isBlank() || opensuite.core.Os.WINDOWS || opensuite.core.Os.MAC) return false;
+ java.io.File file = new java.io.File(image);
+ if (!file.isFile() || !file.canExecute()) return false;
+ List<String> cmd = new ArrayList<>();
+ cmd.add(file.getPath());
+ if (args != null) java.util.Collections.addAll(cmd, args);
+ ProcessBuilder pb = new ProcessBuilder(cmd).inheritIO();
+ java.util.Map<String, String> env = pb.environment();
+ String opts = withoutOwnScale(env.get("JAVA_TOOL_OPTIONS"));
+ if (opts.isEmpty()) env.remove("JAVA_TOOL_OPTIONS"); else env.put("JAVA_TOOL_OPTIONS", opts);
+ // What the first start set for its own mount means nothing to the next one.
+ for (String k : new String[]{"APPDIR", "ARGV0", "OWD", LAUNCHER_MARK}) env.remove(k);
+ pb.start();
+ return true;
+ }
+
+ /** The options without the scale the start script put there, so that the next start chooses it afresh. */
+ static String withoutOwnScale(String options) {
+ if (options == null) return "";
+ if (!options.contains("-Dopensuite.scaled=")) return options.trim();
+ return options.replaceAll("-Dsun\\.java2d\\.uiScale=\\S+", "").replaceAll("-Dopensuite\\.scaled=\\S+", "")
+ .trim().replaceAll("\\s+", " ");
+ }
+
public static boolean relaunchWith(double scale, String[] args) {
double s = clamp(scale);
// Re-exec the exact command that launched this process, whether that was
@@ -82,6 +121,7 @@ public final class UiScale {
// old approach) only worked from a plain jar; inside a self-contained app
// it failed silently and the UI came up unscaled.
try {
+ if (relaunchAppImage(args)) return true;
ProcessHandle.Info info = ProcessHandle.current().info();
List<String> cmd = new ArrayList<>();
// Windows tells a process its program but not its arguments, which is all a
@@ -106,6 +146,7 @@ public final class UiScale {
// The packaged Windows launcher is handed the project it was opened with again.
if (opensuite.core.Os.WINDOWS && info.arguments().isEmpty() && !bareJava && args != null) java.util.Collections.addAll(cmd, args);
ProcessBuilder pb = new ProcessBuilder(cmd).inheritIO();
+ pb.environment().remove(LAUNCHER_MARK);
// On a Mac the scale is applied to the font size instead (Theme.baseFontSize).
String opts = ((Math.abs(s - 1.0) > 0.001 || chosen()) && !opensuite.core.Os.MAC ? "-Dsun.java2d.uiScale=" + s + " " : "")
+ "-Dopensuite.scaled=" + s;
diff --git a/tests/RunTests.java b/tests/RunTests.java
index ef9d31e..86262c0 100644
--- a/tests/RunTests.java
+++ b/tests/RunTests.java
@@ -67,6 +67,7 @@ public final class RunTests {
new opensuite.engine.SeenElsewhereTest().run();
new opensuite.ui.SendToComparerTest().run();
new opensuite.ui.ThemePaletteTest().run();
+ new opensuite.ui.RestartOptionsTest().run();
new opensuite.ui.EditorKeysTest().run();
new opensuite.ui.PrettyPrintTest().run();
new opensuite.target.LinkFinderTest().run();
diff --git a/tests/opensuite/ui/RestartOptionsTest.java b/tests/opensuite/ui/RestartOptionsTest.java
new file mode 100644
index 0000000..a862f5f
--- /dev/null
+++ b/tests/opensuite/ui/RestartOptionsTest.java
@@ -0,0 +1,25 @@
+package opensuite.ui;
+
+import opensuite.testkit.Expect;
+import opensuite.testkit.Harness;
+
+/**
+ * A restart from inside a packaged Linux build starts the package again, and its start script
+ * chooses the scale afresh. For that the scale the script set the first time has to come out
+ * of the options handed on, while anything the user set themselves stays.
+ */
+public final class RestartOptionsTest {
+ public void run() {
+ Harness.suite("restart options");
+
+ Harness.test("the start script's own scale is taken out", () -> {
+ Expect.equal(UiScale.withoutOwnScale("-Dfoo=1 -Dsun.java2d.uiScale=2 -Dopensuite.scaled=2 -Xmx900m"), "-Dfoo=1 -Xmx900m", "pair removed, the rest kept");
+ Expect.equal(UiScale.withoutOwnScale("-Dsun.java2d.uiScale=1.5 -Dopensuite.scaled=1.5"), "", "nothing left");
+ });
+
+ Harness.test("a scale the user set by hand is kept", () -> {
+ Expect.equal(UiScale.withoutOwnScale("-Dsun.java2d.uiScale=2"), "-Dsun.java2d.uiScale=2", "no marker of ours, so it is theirs");
+ Expect.equal(UiScale.withoutOwnScale(null), "", "no options at all");
+ });
+ }
+}