Rizin
unix-like reverse engineering framework and cli tools
cmd_tasks.c File Reference
#include <rz_cmd.h>
#include <rz_core.h>
#include <cmd_descs.h>

Go to the source code of this file.

Functions

static int task_enqueue (RzCore *core, const char *cmd, bool transient)
 
static int task_output (RzCore *core, int tid)
 
static int task_break (RzCore *core, int tid)
 
RZ_IPI RzCmdStatus rz_tasks_handler (RzCore *core, int argc, const char **argv, RzOutputMode mode)
 
RZ_IPI RzCmdStatus rz_tasks_transient_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_tasks_output_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_tasks_break_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_tasks_delete_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_tasks_delete_all_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_tasks_wait_handler (RzCore *core, int argc, const char **argv)
 

Function Documentation

◆ rz_tasks_break_handler()

RZ_IPI RzCmdStatus rz_tasks_break_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 66 of file cmd_tasks.c.

66  {
67  int tid = rz_num_math(core->num, argv[1]);
68  return rz_cmd_int2status(task_break(core, tid));
69 }
static int task_break(RzCore *core, int tid)
Definition: cmd_tasks.c:36
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
Definition: unum.c:456
RzNum * num
Definition: rz_core.h:316

References argv, rz_core_t::num, rz_num_math(), and task_break().

Referenced by rzshell_cmddescs_init().

◆ rz_tasks_delete_all_handler()

RZ_IPI RzCmdStatus rz_tasks_delete_all_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 79 of file cmd_tasks.c.

79  {
81  return RZ_CMD_STATUS_OK;
82 }
@ RZ_CMD_STATUS_OK
command handler exited in the right way
Definition: rz_cmd.h:24
RZ_API void rz_core_task_del_all_done(RzCore *core)
Definition: task.c:844

References RZ_CMD_STATUS_OK, and rz_core_task_del_all_done().

Referenced by rzshell_cmddescs_init().

◆ rz_tasks_delete_handler()

RZ_IPI RzCmdStatus rz_tasks_delete_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 71 of file cmd_tasks.c.

71  {
72  int tid = rz_num_math(core->num, argv[1]);
73  if (!rz_core_task_is_cmd(core, tid)) {
74  return RZ_CMD_STATUS_ERROR;
75  }
77 }
@ RZ_CMD_STATUS_ERROR
command handler had issues while running (e.g. allocation error, etc.)
Definition: rz_cmd.h:26
RzCoreTaskScheduler tasks
Definition: rz_core.h:362
RZ_API bool rz_core_task_is_cmd(RzCore *core, int id)
Definition: task.c:834
RZ_API int rz_core_task_del(RzCoreTaskScheduler *scheduler, int id)
Definition: task.c:508

References argv, rz_core_t::num, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_task_del(), rz_core_task_is_cmd(), rz_num_math(), and rz_core_t::tasks.

Referenced by rzshell_cmddescs_init().

◆ rz_tasks_handler()

RZ_IPI RzCmdStatus rz_tasks_handler ( RzCore core,
int  argc,
const char **  argv,
RzOutputMode  mode 
)

Definition at line 47 of file cmd_tasks.c.

47  {
48  if (argc == 1) {
49  rz_core_task_list(core, mode == RZ_OUTPUT_MODE_STANDARD ? '\0' : 'j');
50  return RZ_CMD_STATUS_OK;
51  } else if (argc == 2) {
52  return rz_cmd_int2status(task_enqueue(core, argv[1], false));
53  }
54  return RZ_CMD_STATUS_ERROR;
55 }
static int task_enqueue(RzCore *core, const char *cmd, bool transient)
Definition: cmd_tasks.c:8
const char int mode
Definition: ioapi.h:137
@ RZ_OUTPUT_MODE_STANDARD
Definition: rz_types.h:39
RZ_API void rz_core_task_list(RzCore *core, int mode)
Definition: task.c:811

References argv, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_task_list(), RZ_OUTPUT_MODE_STANDARD, and task_enqueue().

Referenced by rzshell_cmddescs_init().

◆ rz_tasks_output_handler()

RZ_IPI RzCmdStatus rz_tasks_output_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 61 of file cmd_tasks.c.

61  {
62  int tid = rz_num_math(core->num, argv[1]);
63  return rz_cmd_int2status(task_output(core, tid));
64 }
static int task_output(RzCore *core, int tid)
Definition: cmd_tasks.c:18

References argv, rz_core_t::num, rz_num_math(), and task_output().

Referenced by rzshell_cmddescs_init().

◆ rz_tasks_transient_handler()

RZ_IPI RzCmdStatus rz_tasks_transient_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 57 of file cmd_tasks.c.

57  {
58  return rz_cmd_int2status(task_enqueue(core, argv[1], true));
59 }

References argv, and task_enqueue().

Referenced by rzshell_cmddescs_init().

◆ rz_tasks_wait_handler()

RZ_IPI RzCmdStatus rz_tasks_wait_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 84 of file cmd_tasks.c.

84  {
85  int tid = 0;
86  if (argc == 2) {
87  tid = rz_num_math(core->num, argv[1]);
88  }
89  if (!rz_core_task_is_cmd(core, tid)) {
90  return RZ_CMD_STATUS_ERROR;
91  }
92  rz_core_task_join(&core->tasks, core->tasks.current_task, tid ? tid : -1);
93  return RZ_CMD_STATUS_OK;
94 }
struct rz_core_task_t * current_task
Definition: rz_core.h:276
RZ_API void rz_core_task_join(RzCoreTaskScheduler *scheduler, RzCoreTask *current, int id)
Definition: task.c:96

References argv, rz_core_tasks_t::current_task, rz_core_t::num, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_task_is_cmd(), rz_core_task_join(), rz_num_math(), and rz_core_t::tasks.

Referenced by rzshell_cmddescs_init().

◆ task_break()

static int task_break ( RzCore core,
int  tid 
)
static

Definition at line 36 of file cmd_tasks.c.

36  {
37  if (!tid) {
38  return -1;
39  }
40  if (!rz_core_task_is_cmd(core, tid)) {
41  return -1;
42  }
43  rz_core_task_break(&core->tasks, tid);
44  return 0;
45 }
RZ_API void rz_core_task_break(RzCoreTaskScheduler *scheduler, int id)
Definition: task.c:483

References rz_core_task_break(), rz_core_task_is_cmd(), and rz_core_t::tasks.

Referenced by rz_tasks_break_handler().

◆ task_enqueue()

static int task_enqueue ( RzCore core,
const char *  cmd,
bool  transient 
)
static

Definition at line 8 of file cmd_tasks.c.

8  {
10  if (!task) {
11  return -1;
12  }
13  task->transient = transient;
14  rz_core_task_enqueue(&core->tasks, task);
15  return 0;
16 }
#define NULL
Definition: cris-opc.c:27
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags cmd
Definition: sflib.h:79
struct rz_core_task_t RzCoreTask
Definition: rz_core.h:254
RZ_API void rz_core_task_enqueue(RzCoreTaskScheduler *scheduler, RzCoreTask *task)
Definition: task.c:374
RZ_API RzCoreTask * rz_core_cmd_task_new(RzCore *core, const char *cmd, RzCoreCmdTaskFinished finished_cb, void *finished_cb_user)
Definition: task.c:629

References cmd, NULL, rz_core_cmd_task_new(), rz_core_task_enqueue(), and rz_core_t::tasks.

Referenced by rz_tasks_handler(), and rz_tasks_transient_handler().

◆ task_output()

static int task_output ( RzCore core,
int  tid 
)
static

Definition at line 18 of file cmd_tasks.c.

18  {
19  if (!tid) {
20  return -1;
21  }
22  RzCoreTask *task = rz_core_task_get_incref(&core->tasks, tid);
23  if (task) {
24  const char *res = rz_core_cmd_task_get_result(task);
25  if (res) {
26  rz_cons_println(res);
27  }
28  rz_core_task_decref(task);
29  } else {
30  eprintf("Cannot find task\n");
31  return -1;
32  }
33  return 0;
34 }
RZ_API void rz_cons_println(const char *str)
Definition: cons.c:233
#define eprintf(x, y...)
Definition: rlcc.c:7
RZ_API void rz_core_task_decref(RzCoreTask *task)
Definition: task.c:200
RZ_API RzCoreTask * rz_core_task_get_incref(RzCoreTaskScheduler *scheduler, int id)
Definition: task.c:461
RZ_API const char * rz_core_cmd_task_get_result(RzCoreTask *task)
Definition: task.c:646

References eprintf, rz_cons_println(), rz_core_cmd_task_get_result(), rz_core_task_decref(), rz_core_task_get_incref(), and rz_core_t::tasks.

Referenced by rz_tasks_output_handler().