1938 final byte[] bytes = new byte[10]; 1939 final Process p = new ProcessBuilder(childArgs).start(); 1940 final CountDownLatch latch = new CountDownLatch(1); 1941 final Thread thread = new Thread() { 1942 public void run() { 1943 try { 1944 latch.countDown(); 1945 int r; 1946 switch (action) { 1947 case 0: r = p.getInputStream().read(); break; 1948 case 1: r = p.getErrorStream().read(); break; 1949 case 2: r = p.getInputStream().read(bytes); break; 1950 case 3: r = p.getErrorStream().read(bytes); break; 1951 default: throw new Error(); 1952 } 1953 equal(-1, r); 1954 } catch (Throwable t) { unexpected(t); }}}; 1955 1956 thread.start(); 1957 latch.await(); 1958 Thread.sleep(10); 1959 p.destroy(); 1960 thread.join(); 1961 } 1962 } catch (Throwable t) { unexpected(t); } 1963 1964 //---------------------------------------------------------------- 1965 // Check that subprocesses which create subprocesses of their 1966 // own do not cause parent to hang waiting for file 1967 // descriptors to be closed. 1968 //---------------------------------------------------------------- 1969 try { 1970 if (Unix.is() 1971 && new File("/bin/bash").exists() 1972 && new File("/bin/sleep").exists()) { 1973 final String[] cmd = { "/bin/bash", "-c", "(/bin/sleep 6666)" }; 1974 final ProcessBuilder pb = new ProcessBuilder(cmd); 1975 final Process p = pb.start(); 1976 final InputStream stdout = p.getInputStream(); 1977 final InputStream stderr = p.getErrorStream(); 1978 final OutputStream stdin = p.getOutputStream(); | 1938 final byte[] bytes = new byte[10]; 1939 final Process p = new ProcessBuilder(childArgs).start(); 1940 final CountDownLatch latch = new CountDownLatch(1); 1941 final Thread thread = new Thread() { 1942 public void run() { 1943 try { 1944 latch.countDown(); 1945 int r; 1946 switch (action) { 1947 case 0: r = p.getInputStream().read(); break; 1948 case 1: r = p.getErrorStream().read(); break; 1949 case 2: r = p.getInputStream().read(bytes); break; 1950 case 3: r = p.getErrorStream().read(bytes); break; 1951 default: throw new Error(); 1952 } 1953 equal(-1, r); 1954 } catch (Throwable t) { unexpected(t); }}}; 1955 1956 thread.start(); 1957 latch.await(); 1958 Thread.sleep(200); 1959 StackTraceElement[] stack = thread.getStackTrace(); 1960 while (stack.length < 2 && 1961 !stack[0].getClassName().equals("java.io.FileInputStream") && 1962 !stack[0].getMethodName().startsWith("read")) { 1963 Thread.sleep(10); 1964 stack = thread.getStackTrace(); 1965 } 1966 p.destroy(); 1967 thread.join(); 1968 } 1969 } catch (Throwable t) { unexpected(t); } 1970 1971 //---------------------------------------------------------------- 1972 // Check that subprocesses which create subprocesses of their 1973 // own do not cause parent to hang waiting for file 1974 // descriptors to be closed. 1975 //---------------------------------------------------------------- 1976 try { 1977 if (Unix.is() 1978 && new File("/bin/bash").exists() 1979 && new File("/bin/sleep").exists()) { 1980 final String[] cmd = { "/bin/bash", "-c", "(/bin/sleep 6666)" }; 1981 final ProcessBuilder pb = new ProcessBuilder(cmd); 1982 final Process p = pb.start(); 1983 final InputStream stdout = p.getInputStream(); 1984 final InputStream stderr = p.getErrorStream(); 1985 final OutputStream stdin = p.getOutputStream(); |