detect changes to /etc/hosts and warn user (#4738)

This commit is contained in:
Ben Fry
2016-11-09 11:52:48 -05:00
parent cc8a12cf81
commit b42ac594f8
2 changed files with 33 additions and 4 deletions

View File

@@ -34,6 +34,8 @@ import java.awt.GraphicsEnvironment;
import java.awt.Point;
import java.io.*;
import java.net.ConnectException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
import com.sun.jdi.*;
@@ -82,6 +84,8 @@ public class Runner implements MessageConsumer {
// this.sketch = sketch;
this.build = build;
checkLocalHost();
if (listener instanceof Editor) {
this.editor = (Editor) listener;
sketchErr = editor.getConsole().getErr();
@@ -116,6 +120,29 @@ public class Runner implements MessageConsumer {
}
/**
* Has the user screwed up their hosts file?
* https://github.com/processing/processing/issues/4738
*/
private void checkLocalHost() throws SketchException {
try {
InetAddress address = InetAddress.getByName("localhost");
if (!address.getHostAddress().equals("127.0.0.1")) {
System.err.println("Your computer is not properly mapping 'localhost' to '127.0.0.1',");
System.err.println("which prevents sketches from working properly because 'localhost'");
System.err.println("is needed to connect the PDE to your sketch while it's running.");
System.err.println("If you don't recall making this change, or know how to fix it:");
System.err.println("https://www.google.com/search?q=add+localhost+to+hosts+file+" + Platform.getName());
throw new SketchException("Cannot run due to changes in your 'hosts' file. " +
"See the console for details.", false);
}
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
public VirtualMachine launch(String[] args) {
if (launchVirtualMachine(false, args)) {
generateTrace();