aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/native/drm_gbm.c
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2019-12-05 22:31:51 +0100
committerSven Gothel <[email protected]>2019-12-05 22:31:51 +0100
commitc317985db39f840f6edf9860487c604e6e31c2ba (patch)
tree304486ec789d2aa91362c7d6d80681f33a3b8aa7 /src/newt/native/drm_gbm.c
parentd693425e2e74a5e4a80c3fde552ffc7d757330f1 (diff)
Bug 1409: GNU/Linux DRM Console: Clear stdin before exit and don't act on stdin in vsync-wait-loop
User input during test from the console will also end up in stdin of the console after the java application has been closed. This is not only annoying, but also a security concern, as the input gets executed if containing a CR. Further, the vsync-wait-loop shall ignore stdin.
Diffstat (limited to 'src/newt/native/drm_gbm.c')
-rw-r--r--src/newt/native/drm_gbm.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/newt/native/drm_gbm.c b/src/newt/native/drm_gbm.c
index 7fb6ad2c8..a6c9a3f9a 100644
--- a/src/newt/native/drm_gbm.c
+++ b/src/newt/native/drm_gbm.c
@@ -27,6 +27,8 @@
*/
#include "drm_gbm.h"
+#include <unistd.h>
+#include <termios.h>
static jmethodID sizeChangedID = NULL;
static jmethodID positionChangedID = NULL;
@@ -37,13 +39,58 @@ static jmethodID windowDestroyNotifyID = NULL;
* Display
*/
+static int saved_stdin;
+
+static void setNullStdin()
+{
+ saved_stdin = dup(fileno(stdin));
+ if( 0 > saved_stdin ) {
+ ERR_PRINT("setNullStdin dup failed: %d %s\n", saved_stdin, strerror(errno));
+ return;
+ }
+ freopen("/dev/null", "r", stdin); // fake null stdin, closes stdin
+ DBG_PRINT("setNullStdin done\n");
+}
+
+static void restoreStdin()
+{
+ int null_stdin = dup(fileno(stdin)); // copy to close after restore
+ if( 0 > null_stdin ) {
+ ERR_PRINT("restoreStdin.1 dup failed: %d %s\n", null_stdin, strerror(errno));
+ return;
+ }
+ // restore
+ int restored_stdin = dup2(saved_stdin, fileno(stdin));
+ if( 0 > restored_stdin ) {
+ ERR_PRINT("restoreStdin.2 dup2 failed: %d %s\n", restored_stdin, strerror(errno));
+ return;
+ }
+ saved_stdin = -1;
+
+ // cleanup stdin before it gets executed on the console
+ tcdrain(restored_stdin);
+ tcflush(restored_stdin, TCIFLUSH);
+
+ close(null_stdin); // close fake null stdin
+ close(restored_stdin);
+ DBG_PRINT("restoreStdin done\n");
+}
+
JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_egl_gbm_DisplayDriver_initIDs
(JNIEnv *env, jclass clazz)
{
+ setNullStdin();
DBG_PRINT( "EGL_GBM.Display initIDs ok\n" );
return JNI_TRUE;
}
+JNIEXPORT void JNICALL Java_jogamp_newt_driver_egl_gbm_DisplayDriver_Shutdown0
+ (JNIEnv *env, jclass clazz)
+{
+ restoreStdin();
+ DBG_PRINT( "EGL_GBM.Display shutdown ok\n" );
+}
+
JNIEXPORT void JNICALL Java_jogamp_newt_driver_egl_gbm_DisplayDriver_DispatchMessages0
(JNIEnv *env, jclass clazz)
{