Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import java.lang.invoke.MethodType;

public class RelaunchMainWrapper {

private static final int PARENT_READY_SIGNAL = 1;

public static void main(String[] args) throws Throwable {
String mainClassName = System.getProperty("cleanroom.relauncher.mainClass");
long parentId = Long.parseLong(System.getProperty("cleanroom.relauncher.parent"));
Expand All @@ -12,6 +15,8 @@ public static void main(String[] args) throws Throwable {
.or(thisProcess::parent)
.orElseThrow(() -> new RuntimeException("Unable to grab parent process!"));

awaitParentReady(parentProcess);

// Parent watcher (Java 9+)
parentProcess.onExit().thenRun(() -> System.exit(0));

Expand All @@ -20,4 +25,14 @@ public static void main(String[] args) throws Throwable {
.invoke((Object) args);
}

private static void awaitParentReady(ProcessHandle parentProcess) throws Exception {
int signal = System.in.read();
if (signal == -1 || !parentProcess.isAlive()) {
System.exit(0);
}
if (signal != PARENT_READY_SIGNAL) {
throw new IllegalStateException("Received an invalid parent cleanup handshake");
}
}

}
Loading