diff options
author | Sven Gothel <[email protected]> | 2019-12-05 22:31:51 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2019-12-05 22:31:51 +0100 |
commit | c317985db39f840f6edf9860487c604e6e31c2ba (patch) | |
tree | 304486ec789d2aa91362c7d6d80681f33a3b8aa7 /src/newt/native | |
parent | d693425e2e74a5e4a80c3fde552ffc7d757330f1 (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')
-rw-r--r-- | src/newt/native/drm_gbm.c | 47 | ||||
-rw-r--r-- | src/newt/native/drm_gbm_legacy.c | 9 |
2 files changed, 53 insertions, 3 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) { diff --git a/src/newt/native/drm_gbm_legacy.c b/src/newt/native/drm_gbm_legacy.c index 1aa8d5f82..cec3297a8 100644 --- a/src/newt/native/drm_gbm_legacy.c +++ b/src/newt/native/drm_gbm_legacy.c @@ -286,7 +286,9 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_egl_gbm_WindowDriver_NextSwapSur while (waiting_for_flip) { FD_ZERO(&fds); - FD_SET(0, &fds); +#if 0 + FD_SET(0, &fds); // STDIN_FILENO: We don't want to listen to +#endif FD_SET(drmFd, &fds); ret = select(drmFd + 1, &fds, NULL, NULL, NULL); @@ -296,9 +298,10 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_egl_gbm_WindowDriver_NextSwapSur } else if (ret == 0) { ERR_PRINT("drm.select: select timeout!\n"); return -1; +#if 0 } else if (FD_ISSET(0, &fds)) { - ERR_PRINT("drm.select: user interrupted!\n"); - return 0; + DBG_PRINT("drm.select: stdin carriage return pressed!\n"); +#endif } drmHandleEvent(drmFd, &drm_event_ctx); } |