Package org.jruby.util.io
Class PopenExecutor
java.lang.Object
org.jruby.util.io.PopenExecutor
Port of MRI's popen+exec logic.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classstatic classprivate static classprivate static classprivate static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final byte[]private jnr.constants.platform.Errnoprivate static final Comparator<PopenExecutor.run_exec_dup2_fd_pair>private static final Comparator<PopenExecutor.run_exec_dup2_fd_pair>private static final intprivate static final String[]static final intprivate static final intprivate static final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static String[]ARGVSTR2ARGV(byte[][] argv_str) private static voidbuildEnvp(Ruby runtime, PopenExecutor.ExecArg eargp, IRubyObject envtbl) static RubyStringcheckArgv(ThreadContext context, IRubyObject[] argv) static RubyArraycheckExecEnv(ThreadContext context, RubyHash hash, PopenExecutor.ExecArg pathArg) (package private) static IRubyObjectcheckExecFds(ThreadContext context, Ruby runtime, PopenExecutor.ExecArg eargp) (package private) static intcheckExecFds1(ThreadContext context, Ruby runtime, PopenExecutor.ExecArg eargp, RubyHash h, int maxhint, IRubyObject ary) (package private) static voidcheckExecOptions(ThreadContext context, Ruby runtime, RubyHash opthash, PopenExecutor.ExecArg eargp) (package private) static voidcheckExecRedirect(ThreadContext context, Ruby runtime, IRubyObject key, IRubyObject val, PopenExecutor.ExecArg eargp) (package private) static RubyArraycheckExecRedirect1(Ruby runtime, RubyArray ary, IRubyObject key, IRubyObject param) private static voidcheckExecRedirectDefault(Ruby runtime, IRubyObject key, IRubyObject val, PopenExecutor.ExecArg eargp) (package private) static IRubyObjectcheckExecRedirectFd(Ruby runtime, IRubyObject v, boolean iskey) static IRubyObjectcheckPipeCommand(ThreadContext context, IRubyObject filenameOrCommand) private static StringdlnFindExeR(Ruby runtime, String fname, IRubyObject path) private long(package private) static intexecargAddopt(ThreadContext context, Ruby runtime, PopenExecutor.ExecArg eargp, IRubyObject key, IRubyObject val) (package private) static IRubyObjectexecargExtractOptions(ThreadContext context, Ruby runtime, PopenExecutor.ExecArg eargp, RubyHash opthash) (package private) static voidexecargFixup(ThreadContext context, Ruby runtime, PopenExecutor.ExecArg eargp) private static RubyStringexecargInit(ThreadContext context, IRubyObject[] argv, boolean accept_shell, PopenExecutor.ExecArg eargp, boolean allow_exc_opt) static PopenExecutor.ExecArgexecargNew(ThreadContext context, IRubyObject[] argv, boolean accept_shell, boolean allow_exc_opt) (package private) static voidexecargParentStart(ThreadContext context, Ruby runtime, PopenExecutor.ExecArg eargp) (package private) static voidexecargParentStart1(ThreadContext context, Ruby runtime, PopenExecutor.ExecArg eargp) (package private) intexecargRunOptions(ThreadContext context, Ruby runtime, PopenExecutor.ExecArg eargp, PopenExecutor.ExecArg sargp, String[] errmsg) (package private) static voidexecargSetenv(ThreadContext context, Ruby runtime, PopenExecutor.ExecArg eargp, IRubyObject env) private static voidexecFillarg(ThreadContext context, RubyString prog, IRubyObject[] argv, IRubyObject env, IRubyObject opthash, PopenExecutor.ExecArg eargp) private static RubyStringexecGetargs(ThreadContext context, IRubyObject[][] argv_p, boolean accept_shell, IRubyObject[] env_opt) (package private) static IRubyObjecthandleOptionsCommon(ThreadContext context, Ruby runtime, PopenExecutor.ExecArg eargp, RubyHash opthash, boolean raise) (package private) static booleanisPopenFork(Ruby runtime, RubyString prog) static booleannativePopenAvailable(Ruby runtime) Check properties and runtime state to determine whether a native popen is possible.(package private) static ChannelFDopen_func(Ruby runtime, RubyIO.Sysopen data) (package private) static voidparentRedirectClose(Ruby runtime, int fd) (package private) static ChannelFDparentRedirectOpen(Ruby runtime, RubyIO.Sysopen data) static IRubyObjectpipeOpen(ThreadContext context, IRubyObject prog, String modestr, int fmode, IOEncodable convconfig) private RubyIOpipeOpen(ThreadContext context, PopenExecutor.ExecArg eargp, String modestr, int fmode, IOEncodable convconfig) static IRubyObjectpopen(ThreadContext context, IRubyObject[] argv, RubyClass klass, Block block) private voidprepareStdioRedirects(Ruby runtime, int[] readPipe, int[] writePipe, PopenExecutor.ExecArg eargp) (package private) longprocSpawnCmd(Ruby runtime, String[] argv, String prog, PopenExecutor.ExecArg eargp) (package private) longprocSpawnCmdInternal(Ruby runtime, String[] argv, String prog, PopenExecutor.ExecArg eargp) (package private) longprocSpawnSh(Ruby runtime, String str, PopenExecutor.ExecArg eargp) private longprocSpawnSh(Ruby runtime, PopenExecutor.ExecArg eargp, String str, String[] envp) (package private) static intredirectCloexecDup(Ruby runtime, int oldfd) (package private) static voidredirectClose(Ruby runtime, PopenExecutor.ExecArg eargp, int fd) (package private) static intredirectDup(Ruby runtime, int oldfd) (package private) static voidredirectDup2(PopenExecutor.ExecArg eargp, int oldfd, int newfd) (package private) static voidredirectOpen(PopenExecutor.ExecArg eargp, int fd, String pathname, int flags, int perm) (package private) static voidrun_exec_close(Ruby runtime, RubyArray ary, PopenExecutor.ExecArg eargp) (package private) static intrun_exec_dup2(Ruby runtime, RubyArray ary, PopenExecutor.ExecArg eargp, PopenExecutor.ExecArg sargp, String[] errmsg) (package private) static voidrun_exec_dup2_child(Ruby runtime, RubyArray ary, PopenExecutor.ExecArg eargp) Add spawn configuration for duplicating descriptors in the child(package private) static voidrun_exec_open(ThreadContext context, Ruby runtime, RubyArray<RubyArray> ary, PopenExecutor.ExecArg eargp) (package private) static intrun_exec_pgroup(Ruby runtime, PopenExecutor.ExecArg eargp, PopenExecutor.ExecArg sargp, String[] errmsg) (package private) static intrun_exec_rlimit(Ruby runtime, RubyArray ary, PopenExecutor.ExecArg sargp, String[] errmsg) (package private) static intrunExecDup2TmpbufSize(int n) (package private) static voidsaveEnv(ThreadContext context, Ruby runtime, PopenExecutor.ExecArg sargp) (package private) static intsaveRedirectFd(Ruby runtime, int fd, PopenExecutor.ExecArg sargp, String[] errmsg) private static booleansearchForMetaChars(RubyString prog) Search for meta characters in the command, to know whether we should use a shell to launch.static RubyFixnumspawn(ThreadContext context, IRubyObject[] argv) (package private) longspawnProcess(ThreadContext context, Ruby runtime, PopenExecutor.ExecArg eargp, String[] errmsg) systemInternal(ThreadContext context, IRubyObject[] argv, String[] errmsg)
-
Field Details
-
SH_CHDIR_ARG_COUNT
public static final int SH_CHDIR_ARG_COUNT- See Also:
-
errno
private jnr.constants.platform.Errno errno -
ST_CONTINUE
private static final int ST_CONTINUE- See Also:
-
ST_STOP
private static final int ST_STOP- See Also:
-
posix_sh_cmd_length
private static final int posix_sh_cmd_length- See Also:
-
posix_sh_cmds
-
DUMMY_ARRAY
private static final byte[] DUMMY_ARRAY -
intcmp
-
intrcmp
-
-
Constructor Details
-
PopenExecutor
public PopenExecutor()
-
-
Method Details
-
nativePopenAvailable
Check properties and runtime state to determine whether a native popen is possible.- Parameters:
runtime- current runtime- Returns:
- true if popen can use native code, false otherwise
-
checkPipeCommand
-
spawn
-
systemInternal
-
spawnProcess
long spawnProcess(ThreadContext context, Ruby runtime, PopenExecutor.ExecArg eargp, String[] errmsg) -
procSpawnCmdInternal
-
procSpawnCmd
-
procSpawnSh
-
pipeOpen
public static IRubyObject pipeOpen(ThreadContext context, IRubyObject prog, String modestr, int fmode, IOEncodable convconfig) -
popen
public static IRubyObject popen(ThreadContext context, IRubyObject[] argv, RubyClass klass, Block block) -
execargSetenv
static void execargSetenv(ThreadContext context, Ruby runtime, PopenExecutor.ExecArg eargp, IRubyObject env) -
checkExecEnv
public static RubyArray checkExecEnv(ThreadContext context, RubyHash hash, PopenExecutor.ExecArg pathArg) -
execargExtractOptions
static IRubyObject execargExtractOptions(ThreadContext context, Ruby runtime, PopenExecutor.ExecArg eargp, RubyHash opthash) -
checkExecOptions
static void checkExecOptions(ThreadContext context, Ruby runtime, RubyHash opthash, PopenExecutor.ExecArg eargp) -
handleOptionsCommon
static IRubyObject handleOptionsCommon(ThreadContext context, Ruby runtime, PopenExecutor.ExecArg eargp, RubyHash opthash, boolean raise) -
isPopenFork
-
DO_SPAWN
private long DO_SPAWN(Ruby runtime, PopenExecutor.ExecArg eargp, String cmd, String[] args, String[] envp) -
procSpawnSh
-
ARGVSTR2ARGV
-
pipeOpen
private RubyIO pipeOpen(ThreadContext context, PopenExecutor.ExecArg eargp, String modestr, int fmode, IOEncodable convconfig) -
prepareStdioRedirects
private void prepareStdioRedirects(Ruby runtime, int[] readPipe, int[] writePipe, PopenExecutor.ExecArg eargp) -
run_exec_pgroup
static int run_exec_pgroup(Ruby runtime, PopenExecutor.ExecArg eargp, PopenExecutor.ExecArg sargp, String[] errmsg) -
run_exec_rlimit
static int run_exec_rlimit(Ruby runtime, RubyArray ary, PopenExecutor.ExecArg sargp, String[] errmsg) -
saveEnv
-
run_exec_dup2
static int run_exec_dup2(Ruby runtime, RubyArray ary, PopenExecutor.ExecArg eargp, PopenExecutor.ExecArg sargp, String[] errmsg) -
redirectDup
-
redirectCloexecDup
-
redirectDup2
-
redirectClose
-
redirectOpen
-
saveRedirectFd
-
execargRunOptions
int execargRunOptions(ThreadContext context, Ruby runtime, PopenExecutor.ExecArg eargp, PopenExecutor.ExecArg sargp, String[] errmsg) -
run_exec_close
-
run_exec_open
static void run_exec_open(ThreadContext context, Ruby runtime, RubyArray<RubyArray> ary, PopenExecutor.ExecArg eargp) -
run_exec_dup2_child
Add spawn configuration for duplicating descriptors in the child -
runExecDup2TmpbufSize
static int runExecDup2TmpbufSize(int n) -
execargFixup
-
execargParentStart
-
execargParentStart1
-
open_func
-
parentRedirectOpen
-
parentRedirectClose
-
buildEnvp
-
checkExecFds1
static int checkExecFds1(ThreadContext context, Ruby runtime, PopenExecutor.ExecArg eargp, RubyHash h, int maxhint, IRubyObject ary) -
checkExecFds
-
execargAddopt
static int execargAddopt(ThreadContext context, Ruby runtime, PopenExecutor.ExecArg eargp, IRubyObject key, IRubyObject val) -
checkExecRedirect
static void checkExecRedirect(ThreadContext context, Ruby runtime, IRubyObject key, IRubyObject val, PopenExecutor.ExecArg eargp) -
checkExecRedirectDefault
private static void checkExecRedirectDefault(Ruby runtime, IRubyObject key, IRubyObject val, PopenExecutor.ExecArg eargp) -
checkExecRedirectFd
-
checkExecRedirect1
static RubyArray checkExecRedirect1(Ruby runtime, RubyArray ary, IRubyObject key, IRubyObject param) -
execargNew
public static PopenExecutor.ExecArg execargNew(ThreadContext context, IRubyObject[] argv, boolean accept_shell, boolean allow_exc_opt) -
execargInit
private static RubyString execargInit(ThreadContext context, IRubyObject[] argv, boolean accept_shell, PopenExecutor.ExecArg eargp, boolean allow_exc_opt) -
execGetargs
private static RubyString execGetargs(ThreadContext context, IRubyObject[][] argv_p, boolean accept_shell, IRubyObject[] env_opt) -
checkArgv
-
execFillarg
private static void execFillarg(ThreadContext context, RubyString prog, IRubyObject[] argv, IRubyObject env, IRubyObject opthash, PopenExecutor.ExecArg eargp) -
searchForMetaChars
Search for meta characters in the command, to know whether we should use a shell to launch. meta characters: * Pathname Expansion ? Pathname Expansion {} Grouping Commands [] Pathname Expansion <> Redirection () Grouping Commands ~ Tilde Expansion & AND Lists, Asynchronous Lists | OR Lists, Pipelines \ Escape Character $ Parameter Expansion ; Sequential Lists ' Single-Quotes ` Command Substitution " Double-Quotes \n Lists # Comment = Assignment preceding command name % (used in Parameter Expansion) -
dlnFindExeR
-