-
Notifications
You must be signed in to change notification settings - Fork 133
IEP-1762: Eim gui cli launch fixes #1457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,11 @@ public MacOsEimLauncherStrategy(Display display, MessageConsoleStream standardCo | |
| @Override | ||
| public LaunchResult launch(String eimPath) throws IOException | ||
| { | ||
| if (!isAppBundle(eimPath)) | ||
| { | ||
| return launchCliDirect(eimPath); | ||
| } | ||
|
|
||
| String appBundlePath = deriveAppBundlePath(eimPath); | ||
| String execPath = deriveExecPath(eimPath, appBundlePath); | ||
| String bundleId = readBundleId(appBundlePath); | ||
|
|
@@ -108,6 +113,41 @@ public LaunchResult launch(String eimPath) throws IOException | |
| "osascript exit=" + exit + "\n" + out); //$NON-NLS-1$ //$NON-NLS-2$ | ||
| } | ||
|
|
||
| private LaunchResult launchCliDirect(String eimPath) throws IOException | ||
| { | ||
| String quotedPath = ProcessUtils.bashSingleQuote(eimPath); | ||
| String bashCmd = "nohup " + quotedPath + " > /dev/null 2>&1 & echo $!"; //$NON-NLS-1$ //$NON-NLS-2$ | ||
|
|
||
| Process launcher = new ProcessBuilder("bash", "-lc", bashCmd) //$NON-NLS-1$ //$NON-NLS-2$ | ||
| .redirectErrorStream(true).start(); | ||
|
|
||
| String out = ProcessUtils.readAll(launcher.getInputStream()); | ||
| Long pid = ProcessUtils.parseFirstLongLine(out); | ||
|
|
||
| if (pid == null) | ||
| { | ||
| Logger.log("macOS CLI launcher output was:\n" + out); //$NON-NLS-1$ | ||
| throw new IOException("No PID found in launcher output. Output was:\n" + out); //$NON-NLS-1$ | ||
| } | ||
|
|
||
| return LaunchResult.ofPid(pid.longValue(), eimPath, out); | ||
| } | ||
|
Comment on lines
+116
to
+134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reap the launcher process and harden Two related concerns in
Consider separating stderr (don't redirect), or print the PID with a marker (e.g. ♻️ Suggested hardening- String bashCmd = "nohup " + quotedPath + " > /dev/null 2>&1 & echo $!"; //$NON-NLS-1$ //$NON-NLS-2$
-
- Process launcher = new ProcessBuilder("bash", "-lc", bashCmd) //$NON-NLS-1$ //$NON-NLS-2$
- .redirectErrorStream(true).start();
-
- String out = ProcessUtils.readAll(launcher.getInputStream());
+ String bashCmd = "nohup " + quotedPath + " > /dev/null 2>&1 & echo EIM_PID:$!"; //$NON-NLS-1$ //$NON-NLS-2$
+
+ ProcessBuilder pb = new ProcessBuilder("bash", "-c", bashCmd); //$NON-NLS-1$ //$NON-NLS-2$
+ Process launcher = pb.start();
+
+ String out = ProcessUtils.readAll(launcher.getInputStream());
+ try
+ {
+ launcher.waitFor();
+ }
+ catch (InterruptedException e)
+ {
+ Thread.currentThread().interrupt();
+ }🤖 Prompt for AI Agents |
||
|
|
||
| private boolean isAppBundle(String eimPath) | ||
| { | ||
| Path p = Paths.get(eimPath).toAbsolutePath().normalize(); | ||
| while (p != null) | ||
| { | ||
| String name = p.getFileName() != null ? p.getFileName().toString() : ""; //$NON-NLS-1$ | ||
| if (name.endsWith(".app")) //$NON-NLS-1$ | ||
| { | ||
| return true; | ||
| } | ||
| p = p.getParent(); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public IStatus waitForExit(LaunchResult launchResult, IProgressMonitor monitor) | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isEimGuiCapablecan deadlock and report false negatives — drain the process output.redirectErrorStream(true)is set, but the combined stdout/stderr stream is never read. Ifeim gui --helpever writes more than the OS pipe buffer (typically 16–64 KB on Linux/macOS), the child process blocks onwrite(),waitFor(5, SECONDS)returnsfalse, the process is force-killed, and the method returnsfalse— incorrectly reporting a GUI‑capable binary as CLI‑only. Even if today's help text is small, this is a fragile contract for an external CLI whose output you don't control.Drain the stream while waiting (or before
exitValue()), and close it explicitly:🛡️ Proposed fix
try { ProcessBuilder pb = new ProcessBuilder(eimPath, "gui", "--help"); //$NON-NLS-1$ //$NON-NLS-2$ pb.redirectErrorStream(true); Process process = pb.start(); + // Drain output on a background thread so the child doesn't block on a full pipe buffer. + Thread drainer = new Thread(() -> { + try (var in = process.getInputStream()) + { + in.transferTo(OutputStream.nullOutputStream()); + } + catch (IOException ignored) + { + // process exit will be observed via waitFor + } + }, "eim-gui-help-drain"); //$NON-NLS-1$ + drainer.setDaemon(true); + drainer.start(); boolean finished = process.waitFor(5, TimeUnit.SECONDS); if (!finished) { process.destroyForcibly(); return false; } return process.exitValue() == 0; }🤖 Prompt for AI Agents