Java Code Examples for org.apache.lucene.util.Constants#MAC_OS_X

The following examples show how to use org.apache.lucene.util.Constants#MAC_OS_X . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Seccomp.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
/**
 * Attempt to drop the capability to execute for the process.
 * <p>
 * This is best effort and OS and architecture dependent. It may throw any Throwable.
 * @return 0 if we can do this for application threads, 1 for the entire process
 */
static int init(Path tmpFile) throws Throwable {
    if (Constants.LINUX) {
        return linuxImpl();
    } else if (Constants.MAC_OS_X) {
        // try to enable both mechanisms if possible
        bsdImpl();
        macImpl(tmpFile);
        return 1;
    } else if (Constants.SUN_OS) {
        solarisImpl();
        return 1;
    } else if (Constants.FREE_BSD || OPENBSD) {
        bsdImpl();
        return 1;
    } else if (Constants.WINDOWS) {
        windowsImpl();
        return 1;
    } else {
        throw new UnsupportedOperationException("syscall filtering not supported for OS: '" + Constants.OS_NAME + "'");
    }
}
 
Example 2
Source File: SolrTestCaseJ4.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private static SSLTestConfig buildSSLConfig() {

    SSLRandomizer sslRandomizer =
      SSLRandomizer.getSSLRandomizerForClass(RandomizedContext.current().getTargetClass());
    
    if (Constants.MAC_OS_X) {
      // see SOLR-9039
      // If a solution is found to remove this, please make sure to also update
      // TestMiniSolrCloudClusterSSL.testSslAndClientAuth as well.
      sslRandomizer = new SSLRandomizer(sslRandomizer.ssl, 0.0D, (sslRandomizer.debug + " w/ MAC_OS_X supressed clientAuth"));
    }

    SSLTestConfig result = sslRandomizer.createSSLTestConfig();
    if (log.isInfoEnabled()) {
      log.info("Randomized ssl ({}) and clientAuth ({}) via: {}",
          result.isSSLMode(), result.isClientAuthMode(), sslRandomizer.debug);
    }
    return result;
  }
 
Example 3
Source File: Seccomp.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/** try to install our custom rule profile into sandbox_init() to block execution */
private static void macImpl(Path tmpFile) throws IOException {
    // first be defensive: we can give nice errors this way, at the very least.
    boolean supported = Constants.MAC_OS_X;
    if (supported == false) {
        throw new IllegalStateException("bug: should not be trying to initialize seatbelt for an unsupported OS");
    }

    // we couldn't link methods, could be some really ancient OS X (< Leopard) or some bug
    if (libc_mac == null) {
        throw new UnsupportedOperationException("seatbelt unavailable: could not link methods. requires Leopard or above.");
    }

    // write rules to a temporary file, which will be passed to sandbox_init()
    Path rules = Files.createTempFile(tmpFile, "es", "sb");
    Files.write(rules, Collections.singleton(SANDBOX_RULES), StandardCharsets.UTF_8);

    boolean success = false;
    try {
        PointerByReference errorRef = new PointerByReference();
        int ret = libc_mac.sandbox_init(rules.toAbsolutePath().toString(), SANDBOX_NAMED, errorRef);
        // if sandbox_init() fails, add the message from the OS (e.g. syntax error) and free the buffer
        if (ret != 0) {
            Pointer errorBuf = errorRef.getValue();
            RuntimeException e = new UnsupportedOperationException("sandbox_init(): " + errorBuf.getString(0));
            libc_mac.sandbox_free_error(errorBuf);
            throw e;
        }
        logger.debug("OS X seatbelt initialization successful");
        success = true;
    } finally {
        if (success) {
            Files.delete(rules);
        } else {
            IOUtils.deleteFilesIgnoringExceptions(rules);
        }
    }
}
 
Example 4
Source File: Seccomp.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
static void bsdImpl() {
    boolean supported = Constants.FREE_BSD || OPENBSD || Constants.MAC_OS_X;
    if (supported == false) {
        throw new IllegalStateException("bug: should not be trying to initialize RLIMIT_NPROC for an unsupported OS");
    }

    JNACLibrary.Rlimit limit = new JNACLibrary.Rlimit();
    limit.rlim_cur.setValue(0);
    limit.rlim_max.setValue(0);
    if (JNACLibrary.setrlimit(RLIMIT_NPROC, limit) != 0) {
        throw new UnsupportedOperationException("RLIMIT_NPROC unavailable: " + JNACLibrary.strerror(Native.getLastError()));
    }

    logger.debug("BSD RLIMIT_NPROC initialization successful");
}
 
Example 5
Source File: JNANatives.java    From crate with Apache License 2.0 5 votes vote down vote up
static void trySetMaxSizeVirtualMemory() {
    if (Constants.LINUX || Constants.MAC_OS_X) {
        final JNACLibrary.Rlimit rlimit = new JNACLibrary.Rlimit();
        if (JNACLibrary.getrlimit(JNACLibrary.RLIMIT_AS, rlimit) == 0) {
            MAX_SIZE_VIRTUAL_MEMORY = rlimit.rlim_cur.longValue();
        } else {
            LOGGER.warn("unable to retrieve max size virtual memory [" + JNACLibrary.strerror(Native.getLastError()) + "]");
        }
    }
}
 
Example 6
Source File: JNANatives.java    From crate with Apache License 2.0 5 votes vote down vote up
static void trySetMaxFileSize() {
    if (Constants.LINUX || Constants.MAC_OS_X) {
        final JNACLibrary.Rlimit rlimit = new JNACLibrary.Rlimit();
        if (JNACLibrary.getrlimit(JNACLibrary.RLIMIT_FSIZE, rlimit) == 0) {
            MAX_FILE_SIZE = rlimit.rlim_cur.longValue();
        } else {
            LOGGER.warn("unable to retrieve max file size [" + JNACLibrary.strerror(Native.getLastError()) + "]");
        }
    }
}
 
Example 7
Source File: JNANatives.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
static void tryMlockall() {
    int errno = Integer.MIN_VALUE;
    String errMsg = null;
    boolean rlimitSuccess = false;
    long softLimit = 0;
    long hardLimit = 0;
    
    try {
        int result = JNACLibrary.mlockall(JNACLibrary.MCL_CURRENT);
        if (result == 0) {
            LOCAL_MLOCKALL = true;
            return;
        }
        
        errno = Native.getLastError();
        errMsg = JNACLibrary.strerror(errno);
        if (Constants.LINUX || Constants.MAC_OS_X) {
            // we only know RLIMIT_MEMLOCK for these two at the moment. 
            JNACLibrary.Rlimit rlimit = new JNACLibrary.Rlimit();
            if (JNACLibrary.getrlimit(JNACLibrary.RLIMIT_MEMLOCK, rlimit) == 0) {
                rlimitSuccess = true;
                softLimit = rlimit.rlim_cur.longValue();
                hardLimit = rlimit.rlim_max.longValue();
            } else {
                logger.warn("Unable to retrieve resource limits: " + JNACLibrary.strerror(Native.getLastError()));
            }
        }
    } catch (UnsatisfiedLinkError e) {
        // this will have already been logged by CLibrary, no need to repeat it
        return;
    }

    // mlockall failed for some reason
    logger.warn("Unable to lock JVM Memory: error=" + errno + ",reason=" + errMsg);
    logger.warn("This can result in part of the JVM being swapped out.");
    if (errno == JNACLibrary.ENOMEM) {
        if (rlimitSuccess) {
            logger.warn("Increase RLIMIT_MEMLOCK, soft limit: " + rlimitToString(softLimit) + ", hard limit: " + rlimitToString(hardLimit));
            if (Constants.LINUX) {
                // give specific instructions for the linux case to make it easy
                String user = System.getProperty("user.name");
                logger.warn("These can be adjusted by modifying /etc/security/limits.conf, for example: \n" +
                            "\t# allow user '" + user + "' mlockall\n" +
                            "\t" + user + " soft memlock unlimited\n" +
                            "\t" + user + " hard memlock unlimited"
                           );
                logger.warn("If you are logged in interactively, you will have to re-login for the new limits to take effect.");
            }
        } else {
            logger.warn("Increase RLIMIT_MEMLOCK (ulimit).");
        }
    }
}
 
Example 8
Source File: JNANatives.java    From crate with Apache License 2.0 4 votes vote down vote up
static void tryMlockall() {
    int errno = Integer.MIN_VALUE;
    String errMsg = null;
    boolean rlimitSuccess = false;
    long softLimit = 0;
    long hardLimit = 0;

    try {
        int result = JNACLibrary.mlockall(JNACLibrary.MCL_CURRENT);
        if (result == 0) {
            LOCAL_MLOCKALL = true;
            return;
        }

        errno = Native.getLastError();
        errMsg = JNACLibrary.strerror(errno);
        if (Constants.LINUX || Constants.MAC_OS_X) {
            // we only know RLIMIT_MEMLOCK for these two at the moment.
            JNACLibrary.Rlimit rlimit = new JNACLibrary.Rlimit();
            if (JNACLibrary.getrlimit(JNACLibrary.RLIMIT_MEMLOCK, rlimit) == 0) {
                rlimitSuccess = true;
                softLimit = rlimit.rlim_cur.longValue();
                hardLimit = rlimit.rlim_max.longValue();
            } else {
                LOGGER.warn("Unable to retrieve resource limits: {}", JNACLibrary.strerror(Native.getLastError()));
            }
        }
    } catch (UnsatisfiedLinkError e) {
        // this will have already been logged by CLibrary, no need to repeat it
        return;
    }

    // mlockall failed for some reason
    LOGGER.warn("Unable to lock JVM Memory: error={}, reason={}", errno , errMsg);
    LOGGER.warn("This can result in part of the JVM being swapped out.");
    if (errno == JNACLibrary.ENOMEM) {
        if (rlimitSuccess) {
            LOGGER.warn("Increase RLIMIT_MEMLOCK, soft limit: {}, hard limit: {}", rlimitToString(softLimit), rlimitToString(hardLimit));
            if (Constants.LINUX) {
                // give specific instructions for the linux case to make it easy
                String user = System.getProperty("user.name");
                LOGGER.warn("These can be adjusted by modifying /etc/security/limits.conf, for example: \n" +
                            "\t# allow user '{}' mlockall\n" +
                            "\t{} soft memlock unlimited\n" +
                            "\t{} hard memlock unlimited",
                            user, user, user
                            );
                LOGGER.warn("If you are logged in interactively, you will have to re-login for the new limits to take effect.");
            }
        } else {
            LOGGER.warn("Increase RLIMIT_MEMLOCK (ulimit).");
        }
    }
}
 
Example 9
Source File: FileSystemUtils.java    From crate with Apache License 2.0 2 votes vote down vote up
/**
 * Check whether the file denoted by the given path is a desktop services store created by Finder on macOS.
 *
 * @param path the path
 * @return true if the current system is macOS and the specified file appears to be a desktop services store file
 */
public static boolean isDesktopServicesStore(final Path path) {
    return Constants.MAC_OS_X && Files.isRegularFile(path) && ".DS_Store".equals(path.getFileName().toString());
}