From a8db919494e934f768ee8adb0d0bad75fa390e62 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 21 Sep 2015 07:26:53 +0200 Subject: Bug 1219: IOUtil.testDirExe: Satisfactory when executed, more debug options IOUtil.testDirExe(): - Satisfactory when executed Failure to execute produce an IOException right at ProcessBuilder.start(). Hence we can allow an unexpected process exit value, since we only want to learn whether executable files are allowed. - More debug options DEBUG_EXE: 'jogamp.debug.IOUtil.Exe' DEBUG_EXE_NOSTREAM: 'jogamp.debug.IOUtil.Exe.NoStream' - if DEBUG_EXE - a pre-existing 'jogamp_exe_tst'+ will be used as-is. - the test-exe will not be deleted - StreamMonitor is being used to dump stdout/stderr if !DEBUG_EXE_NOSTREAM. --- src/java/com/jogamp/common/util/IOUtil.java | 34 +++++++++++++++++++---------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'src/java/com/jogamp/common/util/IOUtil.java') diff --git a/src/java/com/jogamp/common/util/IOUtil.java b/src/java/com/jogamp/common/util/IOUtil.java index 3ed28db..9bbb09b 100644 --- a/src/java/com/jogamp/common/util/IOUtil.java +++ b/src/java/com/jogamp/common/util/IOUtil.java @@ -64,11 +64,13 @@ import com.jogamp.common.os.Platform; public class IOUtil { public static final boolean DEBUG; private static final boolean DEBUG_EXE; + private static final boolean DEBUG_EXE_NOSTREAM; static { Debug.initSingleton(); DEBUG = Debug.debug("IOUtil"); DEBUG_EXE = PropertyAccess.isPropertyDefined("jogamp.debug.IOUtil.Exe", true); + DEBUG_EXE_NOSTREAM = PropertyAccess.isPropertyDefined("jogamp.debug.IOUtil.Exe.NoStream", true); } /** Std. temporary directory property key java.io.tmpdir. */ @@ -906,8 +908,16 @@ public class IOUtil { final long t0 = debug ? System.currentTimeMillis() : 0; final File exeTestFile; + final boolean existingExe; try { - exeTestFile = File.createTempFile("jogamp_exe_tst", getExeTestFileSuffix(), dir); + final File permExeTestFile = DEBUG_EXE ? new File(dir, "jogamp_exe_tst"+getExeTestFileSuffix()) : null; + if( null != permExeTestFile && permExeTestFile.exists() ) { + exeTestFile = permExeTestFile; + existingExe = true; + } else { + exeTestFile = File.createTempFile("jogamp_exe_tst", getExeTestFileSuffix(), dir); + existingExe = false; + } } catch (final SecurityException se) { throw se; // fwd Security exception } catch (final IOException e) { @@ -918,18 +928,22 @@ public class IOUtil { } final long t1 = debug ? System.currentTimeMillis() : 0; int res = -1; - if(exeTestFile.setExecutable(true /* exec */, true /* ownerOnly */)) { + int exitValue = -1; + if( existingExe || exeTestFile.setExecutable(true /* exec */, true /* ownerOnly */) ) { try { - fillExeTestFile(exeTestFile); - + if( !existingExe ) { + fillExeTestFile(exeTestFile); + } // Using 'Process.exec(String[])' avoids StringTokenizer of 'Process.exec(String)' // and hence splitting up command by spaces! - final Process pr = Runtime.getRuntime().exec( getExeTestCommandArgs( exeTestFile.getCanonicalPath() ) ); - if( DEBUG_EXE ) { + // Note: All no-exec cases throw an IOExceptions at ProcessBuilder.start(), i.e. below exec() call! + final Process pr = Runtime.getRuntime().exec( getExeTestCommandArgs( exeTestFile.getCanonicalPath() ), null, null ); + if( DEBUG_EXE && !DEBUG_EXE_NOSTREAM ) { new StreamMonitor(new InputStream[] { pr.getInputStream(), pr.getErrorStream() }, System.err, "Exe-Tst: "); } pr.waitFor() ; - res = pr.exitValue(); + exitValue = pr.exitValue(); // Note: Bug 1219 Comment 50: On reporter's machine exit value 1 is being returned + res = 0; // file has been executed } catch (final SecurityException se) { throw se; // fwd Security exception } catch (final Throwable t) { @@ -941,14 +955,12 @@ public class IOUtil { } } final boolean ok = 0 == res; - if( !DEBUG_EXE ) { + if( !DEBUG_EXE && !existingExe ) { exeTestFile.delete(); } if( debug ) { final long t2 = System.currentTimeMillis(); - if( DEBUG_EXE ) { - System.err.println("IOUtil.testDirExec(): test-exe <"+exeTestFile.getAbsolutePath()+">"); - } + System.err.println("IOUtil.testDirExec(): test-exe <"+exeTestFile.getAbsolutePath()+">, existingFile "+existingExe+", returned "+exitValue); System.err.println("IOUtil.testDirExec(): abs-path <"+dir.getAbsolutePath()+">: res "+res+" -> "+ok); System.err.println("IOUtil.testDirExec(): total "+(t2-t0)+"ms, create "+(t1-t0)+"ms, execute "+(t2-t1)+"ms"); } -- cgit v1.2.3