private void swap(StandardOutputStream stdout) throws IOException, NoSuchMethodException, InstantiationException, IllegalAccessException, java.lang.reflect.InvocationTargetException { // duplicate the OS file descriptor and create FileOutputStream around it int out = GNUCLibrary.LIBC.dup(1); if (out<0) throw new IOException("Failed to dup(1)"); Constructor<FileDescriptor> c = FileDescriptor.class.getDeclaredConstructor(int.class); c.setAccessible(true); FileOutputStream fos = new FileOutputStream(c.newInstance(out)); // swap it into channel so that it'll use the new file descriptor stdout.swap(fos); // close fd=1 (stdout) and duplicate fd=2 (stderr) into fd=1 (stdout) GNUCLibrary.LIBC.close(1); GNUCLibrary.LIBC.dup2(2,1); } }
public synchronized List<String> getArguments() { if(arguments!=null) return arguments; arguments = new ArrayList<String>(argc); if (argc == 0) { return arguments; } int psize = b64 ? 8 : 4; Memory m = new Memory(psize); try { if(LOGGER.isLoggable(FINER)) LOGGER.finer("Reading "+getFile("as")); int fd = LIBC.open(getFile("as").getAbsolutePath(), 0); try { for( int n=0; n<argc; n++ ) { // read a pointer to one entry LIBC.pread(fd, m, new NativeLong(psize), new NativeLong(argp+n*psize)); long addr = b64 ? m.getLong(0) : to64(m.getInt(0)); arguments.add(readLine(fd, addr, "argv["+ n +"]")); } } finally { LIBC.close(fd); } } catch (IOException | LastErrorException e) { // failed to read. this can happen under normal circumstances (most notably permission denied) // so don't report this as an error. } arguments = Collections.unmodifiableList(arguments); return arguments; }
LIBC.close(fd);
LIBC.close(fd);
LIBC.close(fd);
private void swap(StandardOutputStream stdout) throws IOException, NoSuchMethodException, InstantiationException, IllegalAccessException, java.lang.reflect.InvocationTargetException { // duplicate the OS file descriptor and create FileOutputStream around it int out = GNUCLibrary.LIBC.dup(1); if (out<0) throw new IOException("Failed to dup(1)"); Constructor<FileDescriptor> c = FileDescriptor.class.getDeclaredConstructor(int.class); c.setAccessible(true); FileOutputStream fos = new FileOutputStream(c.newInstance(out)); // swap it into channel so that it'll use the new file descriptor stdout.swap(fos); // close fd=1 (stdout) and duplicate fd=2 (stderr) into fd=1 (stdout) GNUCLibrary.LIBC.close(1); GNUCLibrary.LIBC.dup2(2,1); } }
public synchronized List<String> getArguments() { if(arguments!=null) return arguments; arguments = new ArrayList<String>(argc); if (argc == 0) { return arguments; } int psize = b64 ? 8 : 4; Memory m = new Memory(psize); try { if(LOGGER.isLoggable(FINER)) LOGGER.finer("Reading "+getFile("as")); int fd = LIBC.open(getFile("as").getAbsolutePath(), 0); try { for( int n=0; n<argc; n++ ) { // read a pointer to one entry LIBC.pread(fd, m, new NativeLong(psize), new NativeLong(argp+n*psize)); long addr = b64 ? m.getLong(0) : to64(m.getInt(0)); arguments.add(readLine(fd, addr, "argv["+ n +"]")); } } finally { LIBC.close(fd); } } catch (IOException | LastErrorException e) { // failed to read. this can happen under normal circumstances (most notably permission denied) // so don't report this as an error. } arguments = Collections.unmodifiableList(arguments); return arguments; }