Refine search
/** * Returns the JVM's process identifier (PID) via a system call to {@code getpid}. * * @return the JVM's process identifier (PID). * @throws UnsupportedOperationException if JNR POSIX library is not loaded or {@code getpid} is * not available. */ public static int processId() { if (!isGetpidAvailable()) throw new UnsupportedOperationException( "JNR POSIX library not loaded or getpid not available"); return PosixLoader.POSIX.getpid(); } }
/** {@inheritDoc} */ @Override public int getFileSystemBlockSize(Path path) { FileStat stat = posix.stat(path.toString()); return Math.toIntExact(stat.blockSize()); }
/** * Change permissions via NIO. */ private static void _chmod(File f, int mask) throws IOException { // TODO WindowsPosix actually does something here (WindowsLibC._wchmod); should we let it? // Anyway the existing calls already skip this method if on Windows. if (File.pathSeparatorChar==';') return; // noop if (Util.NATIVE_CHMOD_MODE) { PosixAPI.jnr().chmod(f.getAbsolutePath(), mask); } else { Files.setPosixFilePermissions(fileToPath(f), Util.modeToPermissions(mask)); } }
public static IRubyObject rowned_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); JRubyFile file = file(filename); return runtime.newBoolean(file.exists() && runtime.getPosix().stat(file.getAbsolutePath()).isROwned()); }
private void inplaceEdit(ThreadContext context, String filename, String extension) throws RaiseException { File file = new File(filename); FileStat stat = runtime.getPosix().stat(filename); if (extension.length() > 0) { file.renameTo(new File(filename + extension)); } else { file.delete(); } createNewFile(file); runtime.getPosix().chmod(filename, stat.mode()); runtime.getPosix().chown(filename, stat.uid(), stat.gid()); runtime.getGlobalVariables().set("$stdout", (RubyIO) RubyFile.open(context, runtime.getFile(), new IRubyObject[]{runtime.newString(filename), runtime.newString("w")}, Block.NULL_BLOCK)); }
@JRubyMethod(required = 1) public IRubyObject chmod(ThreadContext context, IRubyObject arg) { checkClosed(context); int mode = (int) arg.convertToInteger().getLongValue(); if (!new File(path).exists()) { throw context.runtime.newErrnoENOENTError(path); } return context.runtime.newFixnum(context.runtime.getPosix().chmod(path, mode)); }
public static long waitpid(Ruby runtime, long pid, int flags) { int[] status = new int[1]; runtime.getPosix().errno(0); pid = runtime.getPosix().waitpid(pid, status, flags); raiseErrnoIfSet(runtime, ECHILD); if (pid > 0) { runtime.getCurrentContext().setLastExitStatus(RubyProcess.RubyStatus.newProcessStatus(runtime, status[0], pid)); } else { runtime.getCurrentContext().setLastExitStatus(runtime.getNil()); } return pid; }
stat_loc[0] = 0; int result = runtime.getPosix().waitpid((int)finalPid, stat_loc, 0); if (result == -1) { Errno errno = Errno.valueOf(runtime.getPosix().errno()); switch (errno) { case EINTR: runtime.getCurrentContext().pollThreadEvents(); continue retry; case ECHILD: return -1; default: throw new RuntimeException("unexpected waitpid errno: " + Errno.valueOf(runtime.getPosix().errno()));
public static IRubyObject waitpid2(Ruby runtime, IRubyObject[] args) { int pid = -1; int flags = 0; if (args.length > 0) { pid = (int)args[0].convertToInteger().getLongValue(); } if (args.length > 1) { flags = (int)args[1].convertToInteger().getLongValue(); } int[] status = new int[1]; pid = checkErrno(runtime, runtime.getPosix().waitpid(pid, status, flags), ECHILD); return runtime.newArray(runtime.newFixnum(pid), RubyProcess.RubyStatus.newProcessStatus(runtime, (status[0] >> 8) & 0xff, pid)); }
POSIX posix = runtime.getPosix(); if (posix.isNative() && !Platform.IS_WINDOWS) { IRubyObject oldExc = context.runtime.getGlobalVariables().get("$!"); // Save $! try { RubyFile.unlink(context, this); if (!(excp instanceof RubySystemCallError)) throw re; int errno = (int)((RubySystemCallError)excp).errno().convertToInteger().getLongValue(); if (errno != Errno.ENOENT.intValue() && errno != Errno.EACCES.intValue()) { throw re; context.runtime.getGlobalVariables().set("$!", oldExc); // Restore $!
public static IRubyObject getrlimit(Ruby runtime, IRubyObject arg) { if (!runtime.getPosix().isNative() || Platform.IS_WINDOWS) { runtime.getWarnings().warn("Process#getrlimit not supported on this platform"); return runtime.newFixnum(Long.MAX_VALUE); } RLimit rlimit = runtime.getPosix().getrlimit(rlimitResourceType(runtime, arg)); return runtime.newArray(runtime.newFixnum(rlimit.rlimCur()), runtime.newFixnum(rlimit.rlimMax())); }
@JRubyMethod(name = "sticky?") public IRubyObject sticky_p() { Ruby runtime = getRuntime(); if (runtime.getPosix().isNative()) { return runtime.newBoolean(stat.isSticky()); } return runtime.getNil(); }
@JRubyMethod(name = "executable_real?", required = 1, module = true) public static IRubyObject executable_real_p(IRubyObject recv, IRubyObject filename) { if (recv.getRuntime().getPosix().isNative()) { FileStat stat = fileResource(filename).stat(); return recv.getRuntime().newBoolean(stat != null && stat.isExecutableReal()); } else { return executable_p(recv, filename); } }
public long size(ChannelFD fd) { if (fd.chNative != null) { // native fd, use fstat FileStat stat = posix.allocateStat(); int ret = posix.fstat(fd.chNative.getFD(), stat); if (ret == -1) { errno = Errno.valueOf(posix.errno()); return -1; } return stat.st_size(); } else if (fd.chSeek != null) { // if it is seekable, get size directly try { return fd.chSeek.size(); } catch (IOException ioe) { errno = Helpers.errnoFromException(ioe); return -1; } } else { // otherwise just return -1 (should be rare, since size is only defined on File errno = Errno.EINVAL; return -1; } }
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()); } }