/** * Load the JNR implementation of the POSIX APIs for the current platform. * Runtime exceptions will be of type {@link PosixException}. * {@link IllegalStateException} will be thrown for methods not implemented on this platform. * @return some implementation (even on Windows or unsupported Unix) * @since 1.518 */ public static synchronized POSIX jnr() { if (posix == null) { posix = POSIXFactory.getPOSIX(new DefaultPOSIXHandler() { @Override public void error(Errno error, String extraData) { throw new PosixException("native error " + error.description() + " " + extraData, convert(error)); } @Override public void error(Errno error, String methodName, String extraData) { throw new PosixException("native error calling " + methodName + ": " + error.description() + " " + extraData, convert(error)); } private org.jruby.ext.posix.POSIX.ERRORS convert(Errno error) { try { return org.jruby.ext.posix.POSIX.ERRORS.valueOf(error.name()); } catch (IllegalArgumentException x) { return org.jruby.ext.posix.POSIX.ERRORS.EIO; // PosixException.message has real error anyway } } }, true); } return posix; }
public void init() throws URISyntaxException { String path = new File( WindowsService.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParent(); POSIXFactory.getPOSIX().chdir(path); System.setProperty("user.dir", path); serviceMain = new ServiceMain(); SERVICE_TABLE_ENTRY entry = new SERVICE_TABLE_ENTRY(); entry.lpServiceName = serviceName; entry.lpServiceProc = serviceMain; Advapi32.INSTANCE.StartServiceCtrlDispatcher((SERVICE_TABLE_ENTRY[]) entry.toArray(2)); }
/** * Load the JNR implementation of the POSIX APIs for the current platform. * Runtime exceptions will be of type {@link PosixException}. * {@link IllegalStateException} will be thrown for methods not implemented on this platform. * @return some implementation (even on Windows or unsupported Unix) * @since 1.518 */ public static synchronized POSIX jnr() { if (posix == null) { posix = POSIXFactory.getPOSIX(new DefaultPOSIXHandler() { @Override public void error(Errno error, String extraData) { throw new PosixException("native error " + error.description() + " " + extraData, convert(error)); } @Override public void error(Errno error, String methodName, String extraData) { throw new PosixException("native error calling " + methodName + ": " + error.description() + " " + extraData, convert(error)); } private org.jruby.ext.posix.POSIX.ERRORS convert(Errno error) { try { return org.jruby.ext.posix.POSIX.ERRORS.valueOf(error.name()); } catch (IllegalArgumentException x) { return org.jruby.ext.posix.POSIX.ERRORS.EIO; // PosixException.message has real error anyway } } }, true); } return posix; }
/** * This will use {@link DefaultPOSIXHandler} and the native POSIX implementation * * @return a POSIX implementation */ public static POSIX getPOSIX() { return getPOSIX(new DefaultPOSIXHandler(), true); }
/** * This will use {@link DefaultPOSIXHandler} and the native POSIX implementation, * falling back on the pure-Java implementation if native support is not available. * * @return a POSIX implementation, native if possible and pure-Java otherwise. */ public static POSIX getPOSIX() { return getPOSIX(new DefaultPOSIXHandler(), true); }
/** * This will use {@link DefaultPOSIXHandler} and the native POSIX implementation, * falling back on the pure-Java implementation if native support is not available. * * @return a POSIX implementation, native if possible and pure-Java otherwise. */ public static POSIX getPOSIX() { return getPOSIX(new DefaultPOSIXHandler(), true); }
public static synchronized POSIX getPOSIX() { if (posix == null) { posix = jnr.posix.POSIXFactory.getPOSIX(new DefaultPOSIXHandler(), true); } return posix; }
/** * This will use {@link DefaultPOSIXHandler} and the native POSIX implementation, * falling back on the pure-Java implementation if native support is not available. * * @return a POSIX implementation, native if possible and pure-Java otherwise. */ public static POSIX getPOSIX() { return getPOSIX(new DefaultPOSIXHandler(), true); }
/** * Open a new descriptor using the given working directory, file path, * mode flags, and file permission. This is equivalent to the open(2) * POSIX function. See org.jruby.util.io.ChannelDescriptor.open(String, String, ModeFlags, int, POSIX) * for the version that also sets file permissions. * * @param cwd the "current working directory" to use when opening the file * @param path the file path to open * @param flags the mode flags to use for opening the file * @return a new ChannelDescriptor based on the specified parameters */ @Deprecated public static ChannelDescriptor open(String cwd, String path, ModeFlags flags) throws FileNotFoundException, DirectoryAsFileException, FileExistsException, IOException { return open(cwd, path, flags, 0, POSIXFactory.getPOSIX(), null); }
/** * Open a new descriptor using the given working directory, file path, * mode flags, and file permission. This is equivalent to the open(2) * POSIX function. See org.jruby.util.io.ChannelDescriptor.open(String, String, ModeFlags, int, POSIX) * for the version that also sets file permissions. * * @param cwd the "current working directory" to use when opening the file * @param path the file path to open * @param flags the mode flags to use for opening the file * @param classLoader a ClassLoader to use for classpath: resources * @return a new ChannelDescriptor based on the specified parameters */ @Deprecated public static ChannelDescriptor open(String cwd, String path, ModeFlags flags, ClassLoader classLoader) throws FileNotFoundException, DirectoryAsFileException, FileExistsException, IOException { return open(cwd, path, flags, 0, POSIXFactory.getPOSIX(), classLoader); }
/** * Open a new descriptor using the given working directory, file path, * mode flags, and file permission. This is equivalent to the open(2) * POSIX function. See org.jruby.util.io.ChannelDescriptor.open(String, String, ModeFlags, int, POSIX) * for the version that also sets file permissions. * * @param cwd the "current working directory" to use when opening the file * @param path the file path to open * @param flags the mode flags to use for opening the file * @return a new ChannelDescriptor based on the specified parameters */ @Deprecated public static ChannelDescriptor open(String cwd, String path, ModeFlags flags) throws FileNotFoundException, DirectoryAsFileException, FileExistsException, IOException { return open(cwd, path, flags, 0, POSIXFactory.getPOSIX(), null); }
/** * Open a new descriptor using the given working directory, file path, * mode flags, and file permission. This is equivalent to the open(2) * POSIX function. See org.jruby.util.io.ChannelDescriptor.open(String, String, ModeFlags, int, POSIX) * for the version that also sets file permissions. * * @param cwd the "current working directory" to use when opening the file * @param path the file path to open * @param flags the mode flags to use for opening the file * @param classLoader a ClassLoader to use for classpath: resources * @return a new ChannelDescriptor based on the specified parameters */ @Deprecated public static ChannelDescriptor open(String cwd, String path, ModeFlags flags, ClassLoader classLoader) throws FileNotFoundException, DirectoryAsFileException, FileExistsException, IOException { return open(cwd, path, flags, 0, POSIXFactory.getPOSIX(), classLoader); }
/** * Check (using the {@link POSIX} library and <code>jnr-posix</code> library) whether we are in * an interactive environment. Amongst other things, this affects the type of console that may * be legitimately installed during system initialisation. Note that the result may vary * according to whether a <code>jnr-posix</code> native library is found along * <code>java.library.path</code>, or the pure Java fall-back is used. * * @return true if (we think) we are in an interactive environment */ public static boolean isInteractive() { // python.launcher.tty is authoratative; see http://bugs.jython.org/issue2325 String isTTY = System.getProperty("python.launcher.tty"); if (isTTY != null && isTTY.equals("true")) { return true; } if (isTTY != null && isTTY.equals("false")) { return false; } // Decide if System.in is interactive try { POSIX posix = POSIXFactory.getPOSIX(); FileDescriptor in = FileDescriptor.in; return posix.isatty(in); } catch (SecurityException ex) { return false; } }
public static void execRemote(String host, String command) { POSIX posix = POSIXFactory.getPOSIX(); String ssh = firstNonNull(getenv("AIRSHIP_SSH_COMMAND"), firstNonNull(findFileInPath("ssh", null), "/usr/bin/ssh")); String[] args; if (command == null) { args = new String[]{ssh, host}; } else { args = new String[]{ssh, host, "-t", shellQuote(command)}; } posix.execv(ssh, args); }
public static void execLocal(String command) { POSIX posix = POSIXFactory.getPOSIX(); String shell = firstNonNull(getenv("SHELL"), firstNonNull(findFileInPath("bash", null), "/bin/bash")); String[] args; if (command == null) { args = new String[]{shell, "-l"}; } else { args = new String[]{shell, "-c", shellQuote(command)}; } posix.execv(shell, args); }
public static void execLocal(String command) { POSIX posix = POSIXFactory.getPOSIX(); String shell = firstNonNull(getenv("SHELL"), firstNonNull(findFileInPath("bash", null), "/bin/bash")); String[] args; if (command == null) { args = new String[] {shell, "-l"}; } else { args = new String[] {shell, "-c", shellQuote(command)}; } posix.execv(shell, args); }
public static void execRemote(String host, String command) { POSIX posix = POSIXFactory.getPOSIX(); String ssh = firstNonNull(getenv("AIRSHIP_SSH_COMMAND"), firstNonNull(findFileInPath("ssh", null), "/usr/bin/ssh")); String[] args; if (command == null) { args = new String[] {ssh, host}; } else { args = new String[] {ssh, host, "-t", shellQuote(command)}; } posix.execv(ssh, args); }
public String start() throws Exception { authSocket = createLocalSocketAddress(); address = new UnixSocketAddress(new File(authSocket)); channel = UnixServerSocketChannel.open(); channel.configureBlocking(false); socket = channel.socket(); socket.bind(address); selector = NativeSelectorProvider.getInstance().openSelector(); channel.register(selector, SelectionKey.OP_ACCEPT, new SshAgentServerSocketHandler()); POSIXFactory.getPOSIX().chmod(authSocket, 0600); thread = new Thread(new AgentSocketAcceptor(), "SSH Agent socket acceptor " + authSocket); thread.setDaemon(true); thread.start(); return authSocket; }
posix = POSIXFactory.getPOSIX(new JRubyPOSIXHandler(this), config.isNativeEnabled()); filenoUtil = new FilenoUtil(posix);
posix = POSIXFactory.getPOSIX(new JRubyPOSIXHandler(this), config.isNativeEnabled()); filenoUtil = new FilenoUtil(posix);