Rizin
unix-like reverse engineering framework and cli tools
|
Go to the source code of this file.
Classes | |
struct | rz_subprocess_t |
Macros | |
#define | BUFFER_SIZE 0x500 |
Variables | |
static RzPVector | subprocs |
static RzThreadLock * | subprocs_mutex |
static int | sigchld_pipe [2] |
static RzThread * | sigchld_thread |
#define BUFFER_SIZE 0x500 |
Definition at line 8 of file subprocess.c.
|
static |
Definition at line 826 of file subprocess.c.
References environ, free(), i, NULL, RZ_NEWS, rz_str_newf(), rz_sys_get_environ(), SIZE_MAX, and strdup().
Referenced by rz_subprocess_start_opt().
|
static |
Definition at line 882 of file subprocess.c.
References free().
Referenced by rz_subprocess_start_opt().
|
static |
Definition at line 732 of file subprocess.c.
References b, rz_xwrite, and sigchld_pipe.
Referenced by rz_subprocess_init().
Definition at line 1055 of file subprocess.c.
References BUFFER_SIZE, fd, read(), rz_strbuf_append_n(), and sb.
Referenced by subprocess_wait().
RZ_API RzSubprocessOutput* rz_subprocess_drain | ( | RzSubprocess * | proc | ) |
Definition at line 1260 of file subprocess.c.
References out, proc, RZ_NEW, rz_subprocess_err(), rz_subprocess_out(), subprocess_lock(), and subprocess_unlock().
Referenced by subprocess_runner().
RZ_API ut8* rz_subprocess_err | ( | RzSubprocess * | proc, |
int * | length | ||
) |
Definition at line 1312 of file subprocess.c.
References length, proc, rz_str_newlen(), rz_strbuf_fini(), and rz_strbuf_getbin().
Referenced by rz_subprocess_drain(), rz_sys_cmd_str_full(), and rz_test_run_asm_test().
RZ_API void rz_subprocess_fini | ( | void | ) |
Definition at line 814 of file subprocess.c.
References b, rz_pvector_clear(), rz_sys_pipe_close(), rz_sys_signal(), rz_th_free(), rz_th_lock_free(), rz_th_wait(), rz_xwrite, sigchld_pipe, sigchld_thread, subprocs, and subprocs_mutex.
Referenced by rz_sys_cmd_str_full(), rz_test_main(), system_exec(), and system_exec_stdin().
RZ_API void rz_subprocess_free | ( | RzSubprocess * | proc | ) |
Definition at line 1273 of file subprocess.c.
References free(), proc, rz_pvector_remove_data(), rz_strbuf_fini(), rz_sys_pipe_close(), subprocess_lock(), subprocess_unlock(), and subprocs.
Referenced by rz_sys_cmd_str_full(), rz_test_check_jq_available(), rz_test_check_json_test(), rz_test_run_asm_test(), subprocess_runner(), system_exec(), and system_exec_stdin().
Definition at line 787 of file subprocess.c.
References handle_sigchld(), NULL, rz_pvector_init(), rz_sys_pipe(), rz_sys_pipe_close(), rz_sys_signal(), rz_th_lock_free(), rz_th_lock_new(), rz_th_new(), sigchld_pipe, sigchld_th(), sigchld_thread, subprocs, and subprocs_mutex.
Referenced by rz_sys_cmd_str_full(), rz_test_main(), system_exec(), and system_exec_stdin().
RZ_API void rz_subprocess_kill | ( | RzSubprocess * | proc | ) |
Definition at line 1256 of file subprocess.c.
References kill, proc, and SIGKILL.
Referenced by rz_test_run_asm_test(), and subprocess_runner().
RZ_API ut8* rz_subprocess_out | ( | RzSubprocess * | proc, |
int * | length | ||
) |
Definition at line 1301 of file subprocess.c.
References length, proc, rz_str_newlen(), rz_strbuf_fini(), and rz_strbuf_getbin().
Referenced by rz_subprocess_drain(), rz_sys_cmd_str_full(), rz_test_run_asm_test(), system_exec(), and system_exec_stdin().
RZ_API void rz_subprocess_output_free | ( | RzSubprocessOutput * | out | ) |
RZ_API int rz_subprocess_ret | ( | RzSubprocess * | proc | ) |
Definition at line 1297 of file subprocess.c.
References proc.
Referenced by rz_test_check_jq_available(), rz_test_check_json_test(), rz_test_run_asm_test(), and system_exec().
RZ_API RzSubprocess* rz_subprocess_start | ( | const char * | file, |
const char * | args[], | ||
size_t | args_size, | ||
const char * | envvars[], | ||
const char * | envvals[], | ||
size_t | env_size | ||
) |
Start a program in a new child process with the specified parameters.
file | Name of the program to start. It is also evaluated against PATH |
args | Array of arguments to pass to the new program. It does not include argv[0] |
args_size | Number of arguments in the args array |
envvars | Name of environment variables that the newprocess has different from the parent |
envvals | Values of environment variables that the newprocess has different from the parent. Elements are evaluated in parallel with envvars , so envvals[0] specifies the value of the environment variable named envvars[0] and so on. |
env_size | Number of environment variables in arrays envvars and envvals |
Definition at line 1345 of file subprocess.c.
References args, file, rz_subprocess_opt_t::file, RZ_SUBPROCESS_PIPE_CREATE, and rz_subprocess_start_opt().
Referenced by rz_test_check_jq_available(), rz_test_check_json_test(), rz_test_run_asm_test(), and subprocess_runner().
RZ_API RzSubprocess* rz_subprocess_start_opt | ( | RzSubprocessOpt * | opt | ) |
Definition at line 893 of file subprocess.c.
References rz_subprocess_opt_t::args, rz_subprocess_opt_t::args_size, argv, calloc(), create_child_env(), destroy_child_env(), dup2, EINTR, rz_subprocess_opt_t::env_size, rz_subprocess_opt_t::envvals, rz_subprocess_opt_t::envvars, error(), F_SETFL, fcntl, rz_subprocess_opt_t::file, free(), if(), memcpy(), NULL, O_NONBLOCK, proc, RZ_NEW0, rz_pvector_push(), rz_strbuf_init(), RZ_SUBPROCESS_PIPE_CREATE, RZ_SUBPROCESS_PIPE_STDOUT, rz_sys_execvp(), rz_sys_exit(), rz_sys_fork(), rz_sys_pipe(), rz_sys_pipe_close(), rz_sys_set_environ(), STDERR_FILENO, rz_subprocess_opt_t::stderr_pipe, STDIN_FILENO, rz_subprocess_opt_t::stdin_pipe, stdin_pipe, STDOUT_FILENO, rz_subprocess_opt_t::stdout_pipe, stdout_pipe, subprocess_lock(), subprocess_unlock(), and subprocs.
Referenced by rz_subprocess_start(), rz_sys_cmd_str_full(), system_exec(), and system_exec_stdin().
Sends some data to the stdin of the subprocess and returns the number of bytes sent.
proc | Subprocess to communicate with |
buf | Data that needs to be send to the subprocess stdin |
buf_size | Number of bytes to send |
Definition at line 1206 of file subprocess.c.
References buf_size, proc, rz_sys_signal(), and write.
Referenced by rz_sys_cmd_str_full(), rz_test_check_jq_available(), rz_test_check_json_test(), and system_exec_stdin().
RZ_API RzStrBuf* rz_subprocess_stdout_read | ( | RzSubprocess * | proc, |
size_t | n, | ||
ut64 | timeout_ms | ||
) |
Read some data from the stdout of the subprocess and returns a RzStrBuf
containing it. Callers must not free the returned pointer.
proc | Subprocess to communicate with |
n | Number of bytes to read from the subprocess' stdout |
timeout_ms | Wait for at most this amount of millisecond to read subprocess' stdout |
Definition at line 1225 of file subprocess.c.
References n, proc, rz_strbuf_fini(), rz_strbuf_init(), RZ_SUBPROCESS_STDOUT, and subprocess_wait().
RZ_API RzStrBuf* rz_subprocess_stdout_readline | ( | RzSubprocess * | proc, |
ut64 | timeout_ms | ||
) |
Read one line from the stdout of the subprocess and returns a RzStrBuf
containing it. Callers must not free the returned pointer.
proc | Subprocess to communicate with |
timeout_ms | Wait for at most this amount of millisecond to read subprocess' stdout |
Definition at line 1241 of file subprocess.c.
References c, proc, rz_strbuf_fini(), rz_strbuf_get(), rz_strbuf_init(), rz_strbuf_length(), RZ_SUBPROCESS_BYTESREAD, RZ_SUBPROCESS_STDOUT, and subprocess_wait().
RZ_API RzSubprocessWaitReason rz_subprocess_wait | ( | RzSubprocess * | proc, |
ut64 | timeout_ms | ||
) |
Wait until process dies or timeout expires and collect stdout + stderr. No more input can be sent after this call.
proc | Subprocess to communicate with |
timeout_ms | Wait for at most this amount of millisecond |
Definition at line 1185 of file subprocess.c.
References proc, rz_strbuf_fini(), rz_strbuf_init(), RZ_SUBPROCESS_STDERR, RZ_SUBPROCESS_STDOUT, rz_sys_pipe_close(), and subprocess_wait().
Referenced by rz_sys_cmd_str_full(), rz_test_check_jq_available(), rz_test_check_json_test(), rz_test_run_asm_test(), subprocess_runner(), system_exec(), and system_exec_stdin().
|
static |
Definition at line 737 of file subprocess.c.
References b, EINTR, NULL, p, pid, proc, r, rd, read(), rz_pvector_foreach, rz_xwrite, sigchld_pipe, subprocess_lock(), subprocess_unlock(), and subprocs.
Referenced by rz_subprocess_init().
|
static |
Definition at line 724 of file subprocess.c.
References rz_th_lock_enter(), and subprocs_mutex.
Referenced by rz_subprocess_drain(), rz_subprocess_free(), rz_subprocess_start_opt(), and sigchld_th().
|
static |
Definition at line 728 of file subprocess.c.
References rz_th_lock_leave(), and subprocs_mutex.
Referenced by rz_subprocess_drain(), rz_subprocess_free(), rz_subprocess_start_opt(), and sigchld_th().
|
static |
Wait for subprocess to do something, for a maximum of timeout_ms
millisecond.
This function can be used to wait for some action from the subprocess, which includes terminating or sending output to stdout/stderr. If n_bytes
is not 0, the function terminates as soon as n_bytes
bytes have been read or the timeout expires.
proc | Subprocess to interact with |
timeout_ms | Number of millisecond to wait before stopping the operation. If UT64_MAX no timeout is set |
pipe_fds | One of RZ_SUBPROCESS_STDOUT , RZ_SUBPROCESS_STDERR or a combination of them. Bytes are read only from those. |
n_bytes | Number of bytes to read. If pipe_fds references multiple FDs, this indicates the number to read in either of them. |
Definition at line 1085 of file subprocess.c.
References EINTR, FD_ISSET, FD_SET, FD_ZERO, nfds, NULL, proc, r, read_to_strbuf(), RZ_SUBPROCESS_BYTESREAD, RZ_SUBPROCESS_DEAD, RZ_SUBPROCESS_STDERR, RZ_SUBPROCESS_STDOUT, RZ_SUBPROCESS_TIMEDOUT, rz_time_now_mono(), RZ_USEC_PER_MSEC, RZ_USEC_PER_SEC, select, timeout, timeval::tv_sec, timeval::tv_usec, ut64(), and UT64_MAX.
Referenced by rz_subprocess_stdout_read(), rz_subprocess_stdout_readline(), and rz_subprocess_wait().
|
static |
Definition at line 721 of file subprocess.c.
Referenced by handle_sigchld(), rz_subprocess_fini(), rz_subprocess_init(), and sigchld_th().
|
static |
Definition at line 722 of file subprocess.c.
Referenced by rz_subprocess_fini(), and rz_subprocess_init().
|
static |
Definition at line 719 of file subprocess.c.
Referenced by rz_subprocess_fini(), rz_subprocess_free(), rz_subprocess_init(), rz_subprocess_start_opt(), and sigchld_th().
|
static |
Definition at line 720 of file subprocess.c.
Referenced by rz_subprocess_fini(), rz_subprocess_init(), subprocess_lock(), and subprocess_unlock().