From e92a281fd885b87275eb545b1f7eb808feb323e4 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 10 Sep 2014 02:45:21 -0700 Subject: [PATCH 1/2] Close the fd to wake the reading thread up for termination --- .../limelight/binding/input/evdev/EvdevHandler.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/com/limelight/binding/input/evdev/EvdevHandler.java b/src/com/limelight/binding/input/evdev/EvdevHandler.java index 0b2d19ce..fb1fff71 100644 --- a/src/com/limelight/binding/input/evdev/EvdevHandler.java +++ b/src/com/limelight/binding/input/evdev/EvdevHandler.java @@ -10,6 +10,7 @@ public class EvdevHandler { private String absolutePath; private EvdevListener listener; private boolean shutdown = false; + private int fd = -1; private Thread handlerThread = new Thread() { @Override @@ -19,7 +20,7 @@ public class EvdevHandler { // system-wide input problems. // Open the /dev/input/eventX file - int fd = EvdevReader.open(absolutePath); + fd = EvdevReader.open(absolutePath); if (fd == -1) { LimeLog.warning("Unable to open "+absolutePath); return; @@ -130,7 +131,6 @@ public class EvdevHandler { } } finally { // Close the file - LimeLog.warning("Evdev handler is terminating for: "+absolutePath); EvdevReader.close(fd); } } @@ -146,6 +146,13 @@ public class EvdevHandler { } public void stop() { + // Close the fd. It doesn't matter if this races + // with the handler thread. We'll close this out from + // under the thread to wake it up + if (fd != -1) { + EvdevReader.close(fd); + } + shutdown = true; handlerThread.interrupt(); From 5577d48dcfdc4b610cdf08c94f254be6a7a00275 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Mon, 15 Sep 2014 18:50:38 -0700 Subject: [PATCH 2/2] Don't crash if no files are present in /dev/input --- src/com/limelight/binding/input/evdev/EvdevWatcher.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/com/limelight/binding/input/evdev/EvdevWatcher.java b/src/com/limelight/binding/input/evdev/EvdevWatcher.java index 806901ec..0f584300 100644 --- a/src/com/limelight/binding/input/evdev/EvdevWatcher.java +++ b/src/com/limelight/binding/input/evdev/EvdevWatcher.java @@ -67,6 +67,9 @@ public class EvdevWatcher { // Rundown existing files File devInputDir = new File(PATH); File[] files = devInputDir.listFiles(); + if (files == null) { + return new File[0]; + } // Set desired permissions String[] filePaths = new String[files.length];