Package jnr.posix

Examples of jnr.posix.POSIX


        c.fd = fd;
        this.stdio.add(c);
    }

    public void spawn(String file, String... args) throws IOException {
        POSIX posix = this.process.getPosix();

        List<String> argv = new ArrayList<>();
        for (int i = 0; i < args.length; ++i) {
            argv.add(args[i]);
        }

        Collection<SpawnFileAction> fileActions = new ArrayList<>();

        int i = 0;
        for ( StdioConfig each : this.stdio ) {
            switch (each.type) {
                case OPEN:
                    fileActions.add( SpawnFileAction.dup( each.fd, i ) );
                    ++i;
                    break;
                case CLOSE:
                    fileActions.add( SpawnFileAction.close( each.fd ) );
                    break;
            }

        }

        long result = posix.posix_spawnp(args[0], fileActions, argv, this.envp);

        this.pid = (int) result;
        this.process.getEventLoop().submitBlockingTask( new ExitWaiter(this ) );

    }
View Full Code Here


            IRubyObject keyAsStr = normalizeEnvString(RuntimeHelpers.invoke(context, key, "to_str"));
            IRubyObject valueAsStr = value.isNil() ? getRuntime().getNil() :
                    normalizeEnvString(RuntimeHelpers.invoke(context, value, "to_str"));

            if (updateRealENV) {
                POSIX posix = getRuntime().getPosix();
                String keyAsJava = keyAsStr.asJavaString();
                // libc (un)setenv is not reentrant, so we need to synchronize across the entire JVM (JRUBY-5933)
                if (valueAsStr == getRuntime().getNil()) {
                    synchronized (Object.class) { posix.unsetenv(keyAsJava); }
                } else {
                    synchronized (Object.class) { posix.setenv(keyAsJava, valueAsStr.asJavaString(), 1); }
                }
            }

            return super.op_aset(context, keyAsStr, valueAsStr);
View Full Code Here

    @JRubyMethod(name = "waitall", module = true, visibility = PRIVATE)
    public static IRubyObject waitall(ThreadContext context, IRubyObject recv) {
        return waitall(context.runtime);
    }
    public static IRubyObject waitall(Ruby runtime) {
        POSIX posix = runtime.getPosix();
        RubyArray results = runtime.newArray();
       
        int[] status = new int[1];
        int result = posix.wait(status);
        while (result != -1) {
            results.append(runtime.newArray(runtime.newFixnum(result), RubyProcess.RubyStatus.newProcessStatus(runtime, (status[0] >> 8) & 0xff, result)));
            result = posix.wait(status);
        }
       
        return results;
    }
View Full Code Here

        } else {
                throw runtime.newNotImplementedError("this signal not yet implemented in windows");
            }
            }     
    } else {   
      POSIX posix = runtime.getPosix();
      for (int i = 1; i < args.length; i++) {
        int pid = RubyNumeric.num2int(args[i]);

        // FIXME: It may be possible to killpg on systems which support it.  POSIX library
        // needs to tell whether a particular method works or not
        if (pid == 0) pid = runtime.getPosix().getpid();
        checkErrno(runtime, posix.kill(processGroupKill ? -pid : pid, signal));
      }
    }
       
        return runtime.newFixnum(args.length - 1);
View Full Code Here


    @JRubyMethod(name = "getpwuid", optional=1, module = true)
    public static IRubyObject getpwuid(IRubyObject recv, IRubyObject[] args) {
        Ruby runtime = recv.getRuntime();
        POSIX posix = runtime.getPosix();
        try {
            int uid = args.length == 0 ? posix.getuid() : RubyNumeric.fix2int(args[0]);
            Passwd pwd = posix.getpwuid(uid);
            if(pwd == null) {
                if (Platform.IS_WINDOWS) {  // MRI behavior
                    return recv.getRuntime().getNil();
                }
                throw runtime.newArgumentError("can't find user for " + uid);
View Full Code Here

    }

    @JRubyMethod(module = true)
    public static IRubyObject passwd(IRubyObject recv, Block block) {
        Ruby runtime = recv.getRuntime();
        POSIX posix = runtime.getPosix();
        try {
            // call getpwent to fail early if unsupported
            posix.getpwent();
            if(block.isGiven()) {
                ThreadContext context = runtime.getCurrentContext();
                posix.setpwent();
                Passwd pw;
                while((pw = posix.getpwent()) != null) {
                    block.yield(context, setupPasswd(runtime, pw));
                }
                posix.endpwent();
            }

            Passwd pw = posix.getpwent();
            if (pw != null) {
                return setupPasswd(runtime, pw);
            } else {
                return runtime.getNil();
            }
View Full Code Here

    }

    @JRubyMethod(name = "getgrgid", optional=1, module = true)
    public static IRubyObject getgrgid(IRubyObject recv, IRubyObject[] args) {
        Ruby runtime = recv.getRuntime();
        POSIX posix = runtime.getPosix();

        try {
            int gid = args.length == 0 ? posix.getgid() : RubyNumeric.fix2int(args[0]);
            Group gr = posix.getgrgid(gid);
            if(gr == null) {
                if (Platform.IS_WINDOWS) {  // MRI behavior
                    return runtime.getNil();
                }
                throw runtime.newArgumentError("can't find group for " + gid);
View Full Code Here

    }

    @JRubyMethod(module = true)
    public static IRubyObject group(IRubyObject recv, Block block) {
        Ruby runtime = recv.getRuntime();
        POSIX posix = runtime.getPosix();

        try {
            // try to read grent to fail fast
            posix.getgrent();
        } catch (Exception e) {
            if (runtime.getDebug().isTrue()) {
                runtime.getWarnings().warn(ID.NOT_IMPLEMENTED, "Etc.group is not supported by JRuby on this platform");
            }
        }

        if (block.isGiven()) {
            Boolean blocking = (Boolean)recv.getInternalVariables().getInternalVariable("group_blocking");
            if (blocking != null && blocking) {
                throw runtime.newRuntimeError("parallel group iteration");
            }
            try {
                recv.getInternalVariables().setInternalVariable("group_blocking", true);

                ThreadContext context = runtime.getCurrentContext();

                posix.setgrent();
                Group gr;
                while((gr = posix.getgrent()) != null) {
                    block.yield(context, setupGroup(runtime, gr));
                }
            } finally {
                posix.endgrent();
                recv.getInternalVariables().setInternalVariable("group_blocking", false);
            }
        } else {
            Group gr = posix.getgrent();
            if (gr != null) {
                return setupGroup(runtime, gr);
            } else {
                return runtime.getNil();
            }
View Full Code Here

    @JRubyMethod(name = "waitall", module = true, visibility = PRIVATE)
    public static IRubyObject waitall(ThreadContext context, IRubyObject recv) {
        return waitall(context.runtime);
    }
    public static IRubyObject waitall(Ruby runtime) {
        POSIX posix = runtime.getPosix();
        RubyArray results = runtime.newArray();
       
        int[] status = new int[1];
        int result = posix.wait(status);
        while (result != -1) {
            results.append(runtime.newArray(runtime.newFixnum(result), RubyProcess.RubyStatus.newProcessStatus(runtime, status[0], result)));
            result = posix.wait(status);
        }
       
        return results;
    }
View Full Code Here

        } else {
                throw runtime.newNotImplementedError("this signal not yet implemented in windows");
            }
            }     
    } else {   
      POSIX posix = runtime.getPosix();
      for (int i = 1; i < args.length; i++) {
        int pid = RubyNumeric.num2int(args[i]);

        // FIXME: It may be possible to killpg on systems which support it.  POSIX library
        // needs to tell whether a particular method works or not
        if (pid == 0) pid = runtime.getPosix().getpid();
        checkErrno(runtime, posix.kill(processGroupKill ? -pid : pid, signal));
      }
    }
       
        return runtime.newFixnum(args.length - 1);
View Full Code Here

TOP

Related Classes of jnr.posix.POSIX

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.