public static IRubyObject pipeOpen(ThreadContext context, IRubyObject prog, String modestr, int fmode, IOEncodable convconfig) { IRubyObject[] argv = {prog}; ExecArg execArg = null; if (!isPopenFork(context.runtime, (RubyString)prog)) execArg = execargNew(context, argv, true); return new PopenExecutor().pipeOpen(context, execArg, modestr, fmode, convconfig); }
@Deprecated public static RubyArray checkExecEnv(ThreadContext context, RubyHash hash) { return PopenExecutor.checkExecEnv(context, hash, null); }
private static void checkExecRedirectDefault(Ruby runtime, IRubyObject key, IRubyObject val, ExecArg eargp) { IRubyObject tmp; IRubyObject param; tmp = val; val = TypeConverter.ioCheckIO(runtime, tmp); if (!val.isNil()) { val = checkExecRedirectFd(runtime, val, false); param = val; eargp.fd_dup2 = checkExecRedirect1(runtime, eargp.fd_dup2, key, param); } throw runtime.newArgumentError("wrong exec redirect action"); }
public static RubyFixnum spawn(ThreadContext context, IRubyObject[] argv) { Ruby runtime = context.runtime; long pid = 0; String[] errmsg = { null }; ExecArg eargp; IRubyObject fail_str; eargp = execargNew(context, argv, true); execargFixup(context, runtime, eargp); fail_str = eargp.use_shell ? eargp.command_name : eargp.command_name; PopenExecutor executor = new PopenExecutor(); pid = executor.spawnProcess(context, runtime, eargp, errmsg); if (pid == -1) { if (errmsg[0] == null) { throw runtime.newErrnoFromErrno(executor.errno, fail_str.toString()); } throw runtime.newErrnoFromErrno(executor.errno, errmsg[0]); } return runtime.newFixnum(pid); }
eargp = execargNew(context, ((RubyArray)tmp).toJavaArray(), false); ((RubyArray)tmp).clear(); } else { pname = pname.convertToString(); eargp = null; if (!isPopenFork(runtime, (RubyString)pname)) { IRubyObject[] pname_p = {pname}; eargp = execargNew(context, pname_p, true); pname = pname_p[0]; opt = execargExtractOptions(context, runtime, eargp, (RubyHash)opt); if (!env.isNil()) execargSetenv(context, runtime, eargp, env); port = new PopenExecutor().pipeOpen(context, eargp, modestr, fmode_p[0], convconfig);
RubyArray<RubyArray> ary; eargp.redirect_fds = checkExecFds(context, runtime, eargp); ChannelFD ret; open_data.errno = Errno.EINTR; ret = open_func(runtime, open_data); fd2 = RubyNumeric.num2int(fd2v); execargAddopt(context, runtime, eargp, runtime.newFixnum(fd), runtime.newFixnum(fd2)); int len = runExecDup2TmpbufSize(ary.size()); run_exec_dup2_fd_pair[] tmpbuf = new run_exec_dup2_fd_pair[len]; for (int i = 0; i < tmpbuf.length; i++) tmpbuf[i] = new run_exec_dup2_fd_pair(); envtbl = TypeConverter.convertToType(envtbl, runtime.getHash(), "to_hash"); buildEnvp(runtime, eargp, envtbl);
if (eargp != null) prepareStdioRedirects(runtime, pair, writePair, eargp); throw runtime.newErrnoFromErrno(posix.errno, prog.toString()); if (eargp != null) prepareStdioRedirects(runtime, pair, null, eargp); throw runtime.newErrnoFromErrno(posix.errno, prog.toString()); if (eargp != null) prepareStdioRedirects(runtime, null, pair, eargp); execargFixup(context, runtime, eargp); } catch (RaiseException re) { // if (state) if (writePair[0] != -1) runtime.getPosix().close(writePair[0]); if (pair[0] != -1) runtime.getPosix().close(pair[0]); if (pair[1] != -1) runtime.getPosix().close(pair[1]); execargParentEnd(runtime, eargp); throw re; execargRunOptions(context, runtime, eargp, sargp, null); if (eargp.envp_str != null) envp = eargp.envp_str; while ((pid = DO_SPAWN(runtime, eargp, cmd, args, envp)) == -1) { execargRunOptions(context, runtime, sargp, null, null); execargParentEnd(runtime, eargp);
if (id.equals("close")) { param = context.nil; eargp.fd_close = checkExecRedirect1(runtime, eargp.fd_close, key, param); eargp.fd_dup2 = checkExecRedirect1(runtime, eargp.fd_dup2, key, param); eargp.fd_dup2 = checkExecRedirect1(runtime, eargp.fd_dup2, key, param); eargp.fd_dup2 = checkExecRedirect1(runtime, eargp.fd_dup2, key, param); val = checkExecRedirectFd(runtime, val, false); eargp.fd_dup2 = checkExecRedirect1(runtime, eargp.fd_dup2, key, param); break; checkExecRedirectDefault(runtime, key, val, eargp); break; if (((RubyArray)val).size() == 2 && path instanceof RubySymbol && path.toString().equals("child")) { param = checkExecRedirectFd(runtime, ((RubyArray)val).eltOk(1), false); eargp.fd_dup2_child = checkExecRedirect1(runtime, eargp.fd_dup2_child, key, param); flags, perm); eargp.fd_open = checkExecRedirect1(runtime, eargp.fd_open, key, param); path = RubyFile.get_path(context, path); if (key instanceof RubyIO)
checkExecOptions(context, runtime, (RubyHash)opthash, eargp); eargp.env_modification = checkExecEnv(context, (RubyHash) env, eargp); abspath = dlnFindExeR(runtime, eargp.command_name.toString(), eargp.path_env); if (abspath != null) eargp.command_abspath = StringSupport.checkEmbeddedNulls(runtime, RubyString.newString(runtime, abspath));
PopenExecutor executor = new PopenExecutor(); pid = executor.spawnInternal(context, args, null);
private void prepareStdioRedirects(Ruby runtime, int[] readPipe, int[] writePipe, ExecArg eargp) { // We insert these redirects directly into fd_dup2 so that chained redirection can be // validated and set up properly by the execargFixup logic. // The closes do not appear to be part of MRI's logic (they close the fd before exec/spawn), // so rather than using execargAddopt we do them directly here. if (readPipe != null) { // dup our read pipe's write end into stdout int readPipeWriteFD = readPipe[1]; eargp.fd_dup2 = checkExecRedirect1(runtime, eargp.fd_dup2, runtime.newFixnum(1), runtime.newFixnum(readPipeWriteFD)); // close the other end of the pipe in the child int readPipeReadFD = readPipe[0]; eargp.fileActions.add(SpawnFileAction.close(readPipeReadFD)); } if (writePipe != null) { // dup our write pipe's read end into stdin int writePipeReadFD = writePipe[0]; eargp.fd_dup2 = checkExecRedirect1(runtime, eargp.fd_dup2, runtime.newFixnum(0), runtime.newFixnum(writePipeReadFD)); // close the other end of the pipe in the child int writePipeWriteFD = writePipe[1]; eargp.fileActions.add(SpawnFileAction.close(writePipeWriteFD)); } }
private static RubyString execGetargs(ThreadContext context, IRubyObject[][] argv_p, boolean accept_shell, IRubyObject[] env_opt) { Ruby runtime = context.runtime; IRubyObject hash; RubyString prog; int beg = 0; int end = argv_p[0].length; if (end >= 1) { hash = TypeConverter.checkHashType(runtime, argv_p[0][end - 1]); if (!hash.isNil()) { env_opt[1] = hash; end--; } } if (end >= 1) { hash = TypeConverter.checkHashType(runtime, argv_p[0][0]); if (!hash.isNil()) { env_opt[0] = hash; beg++; } } argv_p[0] = Arrays.copyOfRange(argv_p[0], beg, end); prog = checkArgv(context, argv_p[0]); if (prog == null) { prog = (RubyString)argv_p[0][0]; if (accept_shell && (end - beg) == 1) { argv_p[0] = IRubyObject.NULL_ARRAY; } } return prog; }
long i; maxhint = checkExecFds1(context, runtime, eargp, h, maxhint, eargp.fd_dup2); maxhint = checkExecFds1(context, runtime, eargp, h, maxhint, eargp.fd_close); maxhint = checkExecFds1(context, runtime, eargp, h, maxhint, eargp.fd_open); maxhint = checkExecFds1(context, runtime, eargp, h, maxhint, eargp.fd_dup2_child);
checkExecRedirect(context, runtime, key, val, eargp); checkExecRedirect(context, runtime, key, val, eargp); checkExecRedirect(context, runtime, key, val, eargp); case IO: case ARRAY: checkExecRedirect(context, runtime, key, val, eargp); break;
eargp = execargNew(context, ((RubyArray)tmp).toJavaArray(), false); ((RubyArray)tmp).clear(); } else { pname = pname.convertToString(); eargp = null; if (!isPopenFork(runtime, (RubyString)pname)) { IRubyObject[] pname_p = {pname}; eargp = execargNew(context, pname_p, true); pname = pname_p[0]; opt = execargExtractOptions(context, runtime, eargp, (RubyHash)opt); if (!env.isNil()) execargSetenv(context, runtime, eargp, env); port = new PopenExecutor().pipeOpen(context, eargp, modestr, fmode_p[0], convconfig);
RubyArray<RubyArray> ary; eargp.redirect_fds = checkExecFds(context, runtime, eargp); ChannelFD ret; open_data.errno = Errno.EINTR; ret = open_func(runtime, open_data); fd2 = RubyNumeric.num2int(fd2v); execargAddopt(context, runtime, eargp, runtime.newFixnum(fd), runtime.newFixnum(fd2)); int len = runExecDup2TmpbufSize(ary.size()); run_exec_dup2_fd_pair[] tmpbuf = new run_exec_dup2_fd_pair[len]; for (int i = 0; i < tmpbuf.length; i++) tmpbuf[i] = new run_exec_dup2_fd_pair(); envtbl = TypeConverter.convertToType(envtbl, runtime.getHash(), "to_hash"); buildEnvp(runtime, eargp, envtbl);
if (eargp != null) prepareStdioRedirects(runtime, pair, writePair, eargp); throw runtime.newErrnoFromErrno(posix.errno, prog.toString()); if (eargp != null) prepareStdioRedirects(runtime, pair, null, eargp); throw runtime.newErrnoFromErrno(posix.errno, prog.toString()); if (eargp != null) prepareStdioRedirects(runtime, null, pair, eargp); execargFixup(context, runtime, eargp); } catch (RaiseException re) { // if (state) if (writePair[0] != -1) runtime.getPosix().close(writePair[0]); if (pair[0] != -1) runtime.getPosix().close(pair[0]); if (pair[1] != -1) runtime.getPosix().close(pair[1]); execargParentEnd(runtime, eargp); throw re; execargRunOptions(context, runtime, eargp, sargp, null); if (eargp.envp_str != null) envp = eargp.envp_str; while ((pid = DO_SPAWN(runtime, eargp, cmd, args, envp)) == -1) { execargRunOptions(context, runtime, sargp, null, null); execargParentEnd(runtime, eargp);
public static RubyFixnum spawn(ThreadContext context, IRubyObject[] argv) { Ruby runtime = context.runtime; long pid = 0; String[] errmsg = { null }; ExecArg eargp; IRubyObject fail_str; eargp = execargNew(context, argv, true); execargFixup(context, runtime, eargp); fail_str = eargp.use_shell ? eargp.command_name : eargp.command_name; PopenExecutor executor = new PopenExecutor(); pid = executor.spawnProcess(context, runtime, eargp, errmsg); if (pid == -1) { if (errmsg[0] == null) { throw runtime.newErrnoFromErrno(executor.errno, fail_str.toString()); } throw runtime.newErrnoFromErrno(executor.errno, errmsg[0]); } return runtime.newFixnum(pid); }
if (id.equals("close")) { param = context.nil; eargp.fd_close = checkExecRedirect1(runtime, eargp.fd_close, key, param); eargp.fd_dup2 = checkExecRedirect1(runtime, eargp.fd_dup2, key, param); eargp.fd_dup2 = checkExecRedirect1(runtime, eargp.fd_dup2, key, param); eargp.fd_dup2 = checkExecRedirect1(runtime, eargp.fd_dup2, key, param); val = checkExecRedirectFd(runtime, val, false); eargp.fd_dup2 = checkExecRedirect1(runtime, eargp.fd_dup2, key, param); break; checkExecRedirectDefault(runtime, key, val, eargp); break; if (((RubyArray)val).size() == 2 && path instanceof RubySymbol && path.toString().equals("child")) { param = checkExecRedirectFd(runtime, ((RubyArray)val).eltOk(1), false); eargp.fd_dup2_child = checkExecRedirect1(runtime, eargp.fd_dup2_child, key, param); flags, perm); eargp.fd_open = checkExecRedirect1(runtime, eargp.fd_open, key, param); path = RubyFile.get_path(context, path); if (key instanceof RubyIO)
checkExecOptions(context, runtime, (RubyHash)opthash, eargp); eargp.env_modification = checkExecEnv(context, (RubyHash) env, eargp); abspath = dlnFindExeR(runtime, eargp.command_name.toString(), eargp.path_env); if (abspath != null) eargp.command_abspath = StringSupport.checkEmbeddedNulls(runtime, RubyString.newString(runtime, abspath));