/** * 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; }
private void sendSignalToProcess(Process process, Signal signal) { int processPid = getProcessPid(process); if (processPid != -1) { LOGGER.info("Sending signal {} to process {}", signal.intValue(), processPid); POSIXFactory.getNativePOSIX().kill(processPid, signal.intValue()); } }
private static POSIX loadNativePOSIX(POSIXHandler handler) { switch (NATIVE_PLATFORM.getOS()) { case DARWIN: return loadMacOSPOSIX(handler); case LINUX: return loadLinuxPOSIX(handler); case FREEBSD: return loadFreeBSDPOSIX(handler); case OPENBSD: return loadOpenBSDPOSIX(handler); case SOLARIS: return loadSolarisPOSIX(handler); case AIX: return loadAixPOSIX(handler); case WINDOWS: return loadWindowsPOSIX(handler); } return null; }
static POSIX loadPOSIX(POSIXHandler handler, boolean useNativePOSIX) { POSIX posix = null; if (useNativePOSIX) { try { posix = loadNativePOSIX(handler); posix = posix != null ? new CheckedPOSIX(posix, handler) : null; // ENEBO: Should printing be done through a handler+log method? if (handler.isVerbose()) { if (posix != null) { System.err.println("Successfully loaded native POSIX impl."); } else { System.err.println("Failed to load native POSIX impl; falling back on Java impl. Unsupported OS."); } } } catch (Throwable t) { if (handler.isVerbose()) { System.err.println("Failed to load native POSIX impl; falling back on Java impl. Stacktrace follows."); t.printStackTrace(); } } } if (posix == null) { posix = getJavaPOSIX(handler); } return posix; }
private static Map<LibraryOption, Object> options() { Map<LibraryOption, Object> options = new HashMap<LibraryOption, Object>(); FunctionMapper functionMapper = functionMapper(); if (functionMapper != null) { options.put(LibraryOption.FunctionMapper, functionMapper); } options.put(LibraryOption.TypeMapper, POSIXTypeMapper.INSTANCE); options.put(LibraryOption.LoadNow, Boolean.TRUE); return Collections.unmodifiableMap(options); }
/** * Get a pure-Java POSIX instance. Functionality will be limited to that which can * be provided by pure-Java/JDK features or shelling out to external commands. * * @return a pure-Java POSIX implementation */ public static POSIX getJavaPOSIX() { return getJavaPOSIX(new DefaultPOSIXHandler()); }
private static POSIX loadNativePOSIX(POSIXHandler handler) { switch (jnr.ffi.Platform.getNativePlatform().getOS()) { case DARWIN: return loadMacOSPOSIX(handler); case LINUX: return loadLinuxPOSIX(handler); case FREEBSD: return loadFreeBSDPOSIX(handler); case OPENBSD: return loadOpenBSDPOSIX(handler); case SOLARIS: return loadSolarisPOSIX(handler); case AIX: return loadAixPOSIX(handler); case WINDOWS: return loadWindowsPOSIX(handler); } return null; }
static POSIX loadPOSIX(POSIXHandler handler, boolean useNativePOSIX) { POSIX posix = null; if (useNativePOSIX) { try { posix = loadNativePOSIX(handler); posix = posix != null ? new CheckedPOSIX(posix, handler) : null; // ENEBO: Should printing be done through a handler+log method? if (handler.isVerbose()) { if (posix != null) { System.err.println("Successfully loaded native POSIX impl."); } else { System.err.println("Failed to load native POSIX impl; falling back on Java impl. Unsupported OS."); } } } catch (Throwable t) { if (handler.isVerbose()) { System.err.println("Failed to load native POSIX impl; falling back on Java impl. Stacktrace follows."); t.printStackTrace(); } } } if (posix == null) { posix = getJavaPOSIX(handler); } return posix; }
private static Map<LibraryOption, Object> options() { Map<LibraryOption, Object> options = new HashMap<LibraryOption, Object>(); FunctionMapper functionMapper = functionMapper(); if (functionMapper != null) { options.put(LibraryOption.FunctionMapper, functionMapper); } options.put(LibraryOption.TypeMapper, POSIXTypeMapper.INSTANCE); options.put(LibraryOption.LoadNow, Boolean.TRUE); return Collections.unmodifiableMap(options); }
/** * Get a pure-Java POSIX instance. Functionality will be limited to that which can * be provided by pure-Java/JDK features or shelling out to external commands. * * @return a pure-Java POSIX implementation */ public static POSIX getJavaPOSIX() { return getJavaPOSIX(new DefaultPOSIXHandler()); }
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)); }
private static POSIX loadNativePOSIX(POSIXHandler handler) { switch (jnr.ffi.Platform.getNativePlatform().getOS()) { case DARWIN: return loadMacOSPOSIX(handler); case LINUX: return loadLinuxPOSIX(handler); case FREEBSD: return loadFreeBSDPOSIX(handler); case OPENBSD: return loadOpenBSDPOSIX(handler); case SOLARIS: return loadSolarisPOSIX(handler); case AIX: return loadAixPOSIX(handler); case WINDOWS: return loadWindowsPOSIX(handler); } return null; }
static POSIX loadPOSIX(POSIXHandler handler, boolean useNativePOSIX) { POSIX posix = null; if (useNativePOSIX) { try { posix = loadNativePOSIX(handler); posix = posix != null ? new CheckedPOSIX(posix, handler) : null; // ENEBO: Should printing be done through a handler+log method? if (handler.isVerbose()) { if (posix != null) { System.err.println("Successfully loaded native POSIX impl."); } else { System.err.println("Failed to load native POSIX impl; falling back on Java impl. Unsupported OS."); } } } catch (Throwable t) { if (handler.isVerbose()) { System.err.println("Failed to load native POSIX impl; falling back on Java impl. Stacktrace follows."); t.printStackTrace(); } } } if (posix == null) { posix = getJavaPOSIX(handler); } return posix; }
/** * Get a POSIX instance. If a true native implementation can't be loaded, allow that * error to propagate rather than falling back on the pure-Java version. * * @return a native POSIX implementation, raising errors if the native version can't load */ public static POSIX getNativePOSIX() { return getNativePOSIX(new DefaultPOSIXHandler()); }
private static Map<LibraryOption, Object> options() { Map<LibraryOption, Object> options = new HashMap<LibraryOption, Object>(); FunctionMapper functionMapper = functionMapper(); if (functionMapper != null) { options.put(LibraryOption.FunctionMapper, functionMapper); } options.put(LibraryOption.TypeMapper, POSIXTypeMapper.INSTANCE); options.put(LibraryOption.LoadNow, Boolean.TRUE); return Collections.unmodifiableMap(options); }
/** * Get a pure-Java POSIX instance. Functionality will be limited to that which can * be provided by pure-Java/JDK features or shelling out to external commands. * * @return a pure-Java POSIX implementation */ public static POSIX getJavaPOSIX() { return getJavaPOSIX(new DefaultPOSIXHandler()); }
/** * 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; }
private static POSIX loadNativePOSIX(POSIXHandler handler) { switch (jnr.ffi.Platform.getNativePlatform().getOS()) { case DARWIN: return loadMacOSPOSIX(handler); case LINUX: return loadLinuxPOSIX(handler); case FREEBSD: return loadFreeBSDPOSIX(handler); case OPENBSD: return loadOpenBSDPOSIX(handler); case SOLARIS: return loadSolarisPOSIX(handler); case AIX: return loadAixPOSIX(handler); case WINDOWS: return loadWindowsPOSIX(handler); } return null; }
static POSIX loadPOSIX(POSIXHandler handler, boolean useNativePOSIX) { POSIX posix = null; if (useNativePOSIX) { try { posix = loadNativePOSIX(handler); posix = posix != null ? new CheckedPOSIX(posix, handler) : null; // ENEBO: Should printing be done through a handler+log method? if (handler.isVerbose()) { if (posix != null) { System.err.println("Successfully loaded native POSIX impl."); } else { System.err.println("Failed to load native POSIX impl; falling back on Java impl. Unsupported OS."); } } } catch (Throwable t) { if (handler.isVerbose()) { System.err.println("Failed to load native POSIX impl; falling back on Java impl. Stacktrace follows."); t.printStackTrace(); } } } if (posix == null) { posix = getJavaPOSIX(handler); } return posix; }
/** * Get a POSIX instance. If a true native implementation can't be loaded, allow that * error to propagate rather than falling back on the pure-Java version. * * @return a native POSIX implementation, raising errors if the native version can't load */ public static POSIX getNativePOSIX() { return getNativePOSIX(new DefaultPOSIXHandler()); }