mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-09-30 12:25:51 +00:00
Check terminal request pids
This commit is contained in:
@@ -23,6 +23,7 @@ public class TerminalLaunchExchange extends BeaconInterface<TerminalLaunchExchan
|
||||
|
||||
@Override
|
||||
public Object handle(HttpExchange exchange, Request msg) throws BeaconClientException, BeaconServerException {
|
||||
TerminalLauncherManager.verifyPid(msg.getRequest(), msg.getPid());
|
||||
var r = TerminalLauncherManager.launchExchange(msg.getRequest());
|
||||
return Response.builder().targetFile(r).build();
|
||||
}
|
||||
@@ -38,6 +39,8 @@ public class TerminalLaunchExchange extends BeaconInterface<TerminalLaunchExchan
|
||||
public static class Request {
|
||||
@NonNull
|
||||
UUID request;
|
||||
|
||||
long pid;
|
||||
}
|
||||
|
||||
@Jacksonized
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package io.xpipe.app.beacon.api;
|
||||
|
||||
import io.xpipe.app.beacon.BeaconClientException;
|
||||
import io.xpipe.app.beacon.BeaconInterface;
|
||||
import io.xpipe.app.prefs.AppPrefs;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import io.xpipe.app.terminal.TerminalLauncherManager;
|
||||
import lombok.Builder;
|
||||
import lombok.NonNull;
|
||||
import lombok.Value;
|
||||
@@ -19,7 +21,8 @@ public class TerminalPrepareExchange extends BeaconInterface<TerminalPrepareExch
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object handle(HttpExchange exchange, Request msg) {
|
||||
public Object handle(HttpExchange exchange, Request msg) throws BeaconClientException {
|
||||
TerminalLauncherManager.verifyPid(msg.getRequest(), msg.getPid());
|
||||
var term = AppPrefs.get().terminalType().getValue();
|
||||
var unicode = term.supportsUnicode();
|
||||
var escapes = term.supportsEscapes();
|
||||
|
||||
@@ -89,6 +89,25 @@ public class TerminalLauncherManager {
|
||||
req.setShellPid(shell.pid());
|
||||
}
|
||||
|
||||
public static void verifyPid(UUID request, long pid) throws BeaconClientException {
|
||||
TerminalLaunchRequest req;
|
||||
synchronized (entries) {
|
||||
req = entries.get(request);
|
||||
}
|
||||
|
||||
if (req.getShellPid() != -1) {
|
||||
ProcessHandle current = ProcessHandle.of(pid).orElseThrow();
|
||||
do {
|
||||
if (current.pid() == req.getShellPid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
current = current.parent().orElse(null);
|
||||
} while (current != null);
|
||||
}
|
||||
throw new BeaconClientException("Wrong launch context");
|
||||
}
|
||||
|
||||
public static void waitExchange(UUID request) throws BeaconServerException {
|
||||
TerminalLaunchRequest req;
|
||||
synchronized (entries) {
|
||||
|
||||
Reference in New Issue
Block a user