< prev index next >

test/jdk/java/lang/ProcessBuilder/Basic.java

Print this page

        

*** 394,405 **** } if (failed != 0) throw new Error("null PATH"); } else if (action.equals("PATH search algorithm")) { equal(System.getenv("PATH"), "dir1:dir2:"); ! check(new File("/bin/true").exists()); ! check(new File("/bin/false").exists()); String[] cmd = {"prog"}; ProcessBuilder pb1 = new ProcessBuilder(cmd); ProcessBuilder pb2 = new ProcessBuilder(cmd); ProcessBuilder pb3 = new ProcessBuilder(cmd); pb2.environment().put("PATH", "anyOldPathIgnoredAnyways"); --- 394,405 ---- } if (failed != 0) throw new Error("null PATH"); } else if (action.equals("PATH search algorithm")) { equal(System.getenv("PATH"), "dir1:dir2:"); ! check(new File(TrueExe.path()).exists()); ! check(new File(FalseExe.path()).exists()); String[] cmd = {"prog"}; ProcessBuilder pb1 = new ProcessBuilder(cmd); ProcessBuilder pb2 = new ProcessBuilder(cmd); ProcessBuilder pb3 = new ProcessBuilder(cmd); pb2.environment().put("PATH", "anyOldPathIgnoredAnyways");
*** 436,452 **** // Report EACCES errno new File("dir1/prog").mkdirs(); checkPermissionDenied(pb); // continue searching if EACCES ! copy("/bin/true", "dir2/prog"); equal(run(pb).exitValue(), True.exitValue()); new File("dir1/prog").delete(); new File("dir2/prog").delete(); new File("dir2/prog").mkdirs(); ! copy("/bin/true", "dir1/prog"); equal(run(pb).exitValue(), True.exitValue()); // Check empty PATH component means current directory. // // While we're here, let's test different kinds of --- 436,452 ---- // Report EACCES errno new File("dir1/prog").mkdirs(); checkPermissionDenied(pb); // continue searching if EACCES ! copy(TrueExe.path(), "dir2/prog"); equal(run(pb).exitValue(), True.exitValue()); new File("dir1/prog").delete(); new File("dir2/prog").delete(); new File("dir2/prog").mkdirs(); ! copy(TrueExe.path(), "dir1/prog"); equal(run(pb).exitValue(), True.exitValue()); // Check empty PATH component means current directory. // // While we're here, let's test different kinds of
*** 458,471 **** new String[] {"./prog"}, cmd}) { pb.command(command); File prog = new File("./prog"); // "Normal" binaries ! copy("/bin/true", "./prog"); equal(run(pb).exitValue(), True.exitValue()); ! copy("/bin/false", "./prog"); equal(run(pb).exitValue(), False.exitValue()); prog.delete(); // Interpreter scripts with #! setFileContents(prog, "#!/bin/true\n"); --- 458,471 ---- new String[] {"./prog"}, cmd}) { pb.command(command); File prog = new File("./prog"); // "Normal" binaries ! copy(TrueExe.path(), "./prog"); equal(run(pb).exitValue(), True.exitValue()); ! copy(FalseExe.path(), "./prog"); equal(run(pb).exitValue(), False.exitValue()); prog.delete(); // Interpreter scripts with #! setFileContents(prog, "#!/bin/true\n");
*** 516,531 **** // parent's is used. new File("dir1/prog").delete(); new File("dir2/prog").delete(); new File("prog").delete(); new File("dir3").mkdirs(); ! copy("/bin/true", "dir1/prog"); ! copy("/bin/false", "dir3/prog"); pb.environment().put("PATH","dir3"); equal(run(pb).exitValue(), True.exitValue()); ! copy("/bin/true", "dir3/prog"); ! copy("/bin/false", "dir1/prog"); equal(run(pb).exitValue(), False.exitValue()); } finally { // cleanup new File("dir1/prog").delete(); --- 516,531 ---- // parent's is used. new File("dir1/prog").delete(); new File("dir2/prog").delete(); new File("prog").delete(); new File("dir3").mkdirs(); ! copy(TrueExe.path(), "dir1/prog"); ! copy(FalseExe.path(), "dir3/prog"); pb.environment().put("PATH","dir3"); equal(run(pb).exitValue(), True.exitValue()); ! copy(TrueExe.path(), "dir3/prog"); ! copy(FalseExe.path(), "dir1/prog"); equal(run(pb).exitValue(), False.exitValue()); } finally { // cleanup new File("dir1/prog").delete();
*** 618,627 **** --- 618,634 ---- new File("/bin/sh").exists() && new File("/bin/true").exists() && new File("/bin/false").exists()); } + static class BusyBox { + public static boolean is() { return is; } + private static final boolean is = + (! Windows.is() && + new File("/bin/busybox").exists()); + } + static class UnicodeOS { public static boolean is() { return is; } private static final String osName = System.getProperty("os.name"); private static final boolean is = // MacOS X would probably also qualify
*** 656,665 **** --- 663,711 ---- } } catch (Throwable t) { unexpected(t); return -1; } } } + // On alpine linux, /bin/true and /bin/false are just links to /bin/busybox. + // Some tests copy /bin/true and /bin/false to files with a different filename. + // However, copying the busbox executable into a file with a different name + // won't result in the expected return codes. As workaround, we create + // executable files that can be copied and produce the exepected return + // values. We use this workaround, if we find the busybox executable. + + private static class TrueExe { + public static String path() { return path; } + private static final String path = path0(); + private static String path0(){ + if (!BusyBox.is()) { + return "/bin/true"; + } + else { + File trueExe = new File("true"); + setFileContents(trueExe, "#!/bin/true\n"); + trueExe.setExecutable(true); + return trueExe.getAbsolutePath(); + } + } + } + + private static class FalseExe { + public static String path() { return path; } + private static final String path = path0(); + private static String path0(){ + if (!BusyBox.is()) { + return "/bin/false"; + } + else { + File falseExe = new File("false"); + setFileContents(falseExe, "#!/bin/false\n"); + falseExe.setExecutable(true); + return falseExe.getAbsolutePath(); + } + } + } + static class EnglishUnix { private static final Boolean is = (! Windows.is() && isEnglish("LANG") && isEnglish("LC_ALL")); private static boolean isEnglish(String envvar) {
*** 1959,1969 **** //---------------------------------------------------------------- // Parent's, not child's PATH is used //---------------------------------------------------------------- try { new File("suBdiR").mkdirs(); ! copy("/bin/true", "suBdiR/unliKely"); final ProcessBuilder pb = new ProcessBuilder(new String[]{"unliKely"}); pb.environment().put("PATH", "suBdiR"); THROWS(IOException.class, () -> pb.start()); } catch (Throwable t) { unexpected(t); --- 2005,2015 ---- //---------------------------------------------------------------- // Parent's, not child's PATH is used //---------------------------------------------------------------- try { new File("suBdiR").mkdirs(); ! copy(TrueExe.path(), "suBdiR/unliKely"); final ProcessBuilder pb = new ProcessBuilder(new String[]{"unliKely"}); pb.environment().put("PATH", "suBdiR"); THROWS(IOException.class, () -> pb.start()); } catch (Throwable t) { unexpected(t);
< prev index next >