Rizin
unix-like reverse engineering framework and cli tools
main.c File Reference
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <uv.h>

Go to the source code of this file.

Functions

void cleanup_handles (uv_process_t *req, int64_t exit_status, int term_signal)
 
void invoke_cgi_script (uv_tcp_t *client)
 
void on_new_connection (uv_stream_t *server, int status)
 
int main ()
 

Variables

uv_loop_tloop
 
uv_process_t child_req
 
uv_process_options_t options
 

Function Documentation

◆ cleanup_handles()

void cleanup_handles ( uv_process_t req,
int64_t  exit_status,
int  term_signal 
)

Definition at line 11 of file main.c.

11  {
12  fprintf(stderr, "Process exited with status %" PRId64 ", signal %d\n", exit_status, term_signal);
13  uv_close((uv_handle_t*) req->data, NULL);
15 }
#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 static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec req
Definition: sflib.h:128
#define PRId64
Definition: macros.h:17
static enum exit_status_type exit_status
Exit status to use. This can be changed with set_exit_status().
Definition: main.c:17
UV_EXTERN void uv_close(uv_handle_t *handle, uv_close_cb close_cb)
Definition: core.c:108

References exit_status, NULL, PRId64, req, and uv_close().

Referenced by invoke_cgi_script().

◆ invoke_cgi_script()

void invoke_cgi_script ( uv_tcp_t client)

Definition at line 17 of file main.c.

17  {
18  size_t size = 500;
19  char path[size];
20  uv_exepath(path, &size);
21  strcpy(path + (strlen(path) - strlen("cgi")), "tick");
22 
23  char* args[2];
24  args[0] = path;
25  args[1] = NULL;
26 
27  /* ... finding the executable path and setting up arguments ... */
28 
29  options.stdio_count = 3;
30  uv_stdio_container_t child_stdio[3];
31  child_stdio[0].flags = UV_IGNORE;
32  child_stdio[1].flags = UV_INHERIT_STREAM;
33  child_stdio[1].data.stream = (uv_stream_t*) client;
34  child_stdio[2].flags = UV_IGNORE;
35  options.stdio = child_stdio;
36 
38  options.file = args[0];
39  options.args = args;
40 
41  // Set this so we can close the socket after the child process exits.
42  child_req.data = (void*) client;
43  int r;
44  if ((r = uv_spawn(loop, &child_req, &options))) {
45  fprintf(stderr, "%s\n", uv_strerror(r));
46  return;
47  }
48 }
#define r
Definition: crypto_rc6.c:12
static static fork const void static count static fd const char const char static newpath const char static path const char path
Definition: sflib.h:35
voidpf void uLong size
Definition: ioapi.h:138
const char * file
Definition: uv.h:953
uv_stdio_container_t * stdio
Definition: uv.h:986
char ** args
Definition: uv.h:960
uv_exit_cb exit_cb
Definition: uv.h:952
uv_stream_t * stream
Definition: uv.h:946
uv_stdio_flags flags
Definition: uv.h:943
union uv_stdio_container_s::@397 data
uv_process_options_t options
Definition: main.c:9
void cleanup_handles(uv_process_t *req, int64_t exit_status, int term_signal)
Definition: main.c:11
uv_loop_t * loop
Definition: main.c:7
uv_process_t child_req
Definition: main.c:8
struct Arg * args
Definition: mipsasm.c:18
UV_EXTERN int uv_exepath(char *buffer, size_t *size)
Definition: aix-common.c:60
@ UV_IGNORE
Definition: uv.h:922
@ UV_INHERIT_STREAM
Definition: uv.h:925
UV_EXTERN int uv_spawn(uv_loop_t *loop, uv_process_t *handle, const uv_process_options_t *options)
Definition: process.c:408
UV_EXTERN const char * uv_strerror(int err)
Definition: uv-common.c:212

References uv_process_options_s::args, args, child_req, cleanup_handles(), uv_stdio_container_s::data, uv_process_options_s::exit_cb, uv_process_options_s::file, uv_stdio_container_s::flags, loop, NULL, options, path, r, uv_process_options_s::stdio, uv_process_options_s::stdio_count, uv_stdio_container_s::stream, uv_exepath(), UV_IGNORE, UV_INHERIT_STREAM, uv_spawn(), and uv_strerror().

Referenced by on_new_connection().

◆ main()

int main ( void  )

Definition at line 66 of file main.c.

66  {
68 
69  uv_tcp_t server;
70  uv_tcp_init(loop, &server);
71 
72  struct sockaddr_in bind_addr;
73  uv_ip4_addr("0.0.0.0", 7000, &bind_addr);
74  uv_tcp_bind(&server, (const struct sockaddr *)&bind_addr, 0);
75  int r = uv_listen((uv_stream_t*) &server, 128, on_new_connection);
76  if (r) {
77  fprintf(stderr, "Listen error %s\n", uv_err_name(r));
78  return 1;
79  }
80  return uv_run(loop, UV_RUN_DEFAULT);
81 }
Definition: uv.h:547
void on_new_connection(uv_stream_t *server, int status)
Definition: main.c:50
UV_EXTERN int uv_ip4_addr(const char *ip, int port, struct sockaddr_in *addr)
Definition: uv-common.c:221
@ UV_RUN_DEFAULT
Definition: uv.h:255
UV_EXTERN int uv_listen(uv_stream_t *stream, int backlog, uv_connection_cb cb)
Definition: stream.c:656
UV_EXTERN int uv_run(uv_loop_t *, uv_run_mode mode)
Definition: core.c:365
UV_EXTERN const char * uv_err_name(int err)
Definition: uv-common.c:189
UV_EXTERN int uv_tcp_bind(uv_tcp_t *handle, const struct sockaddr *addr, unsigned int flags)
Definition: uv-common.c:277
UV_EXTERN int uv_tcp_init(uv_loop_t *, uv_tcp_t *handle)
Definition: tcp.c:143
UV_EXTERN uv_loop_t * uv_default_loop(void)
Definition: uv-common.c:763

References loop, on_new_connection(), r, uv_default_loop(), uv_err_name(), uv_ip4_addr(), uv_listen(), uv_run(), UV_RUN_DEFAULT, uv_tcp_bind(), and uv_tcp_init().

◆ on_new_connection()

void on_new_connection ( uv_stream_t server,
int  status 
)

Definition at line 50 of file main.c.

50  {
51  if (status == -1) {
52  // error!
53  return;
54  }
55 
56  uv_tcp_t *client = (uv_tcp_t*) malloc(sizeof(uv_tcp_t));
57  uv_tcp_init(loop, client);
58  if (uv_accept(server, (uv_stream_t*) client) == 0) {
59  invoke_cgi_script(client);
60  }
61  else {
62  uv_close((uv_handle_t*) client, NULL);
63  }
64 }
void * malloc(size_t size)
Definition: malloc.c:123
static const char struct stat static buf struct stat static buf static vhangup int status
Definition: sflib.h:145
void invoke_cgi_script(uv_tcp_t *client)
Definition: main.c:17
UV_EXTERN int uv_accept(uv_stream_t *server, uv_stream_t *client)
Definition: stream.c:591

References invoke_cgi_script(), loop, malloc(), NULL, status, uv_accept(), uv_close(), and uv_tcp_init().

Referenced by main().

Variable Documentation

◆ child_req

uv_process_t child_req

Definition at line 8 of file main.c.

Referenced by invoke_cgi_script(), and main().

◆ loop

uv_loop_t* loop

Definition at line 7 of file main.c.

Referenced by basefind_thread_runner(), basefind_thread_ui(), create_curl_context(), create_loop(), eof_timer_cb(), exit_wait_callback(), find_watcher(), init_inotify(), invoke_cgi_script(), main(), maybe_free_watcher_list(), maybe_resize(), on_new_connection(), on_resolved(), on_type(), pipe_alloc_accept(), pipe_connect_thread_proc(), pipe_shutdown_thread_proc(), qsort(), remove_sock(), rz_analysis_esil_parse(), rz_cons_canvas_line_diagonal(), rz_core_rtr_rap_thread(), search_string_thread_runner(), setup_workers(), timer_heap(), uv__async_fork(), uv__async_io(), uv__async_send(), uv__async_start(), uv__async_stop(), uv__chld(), uv__create_stdio_pipe_pair(), uv__duplicate_fd(), uv__emfile_trick(), uv__fast_poll_get_peer_socket(), uv__fast_poll_process_poll_req(), uv__fast_poll_submit_poll_req(), uv__fd_exists(), uv__fs_event(), uv__inotify_fork(), uv__inotify_read(), uv__io_check_fd(), uv__io_close(), uv__io_feed(), uv__io_fork(), uv__io_poll(), uv__io_start(), uv__io_stop(), uv__kqueue_init(), uv__loop_alive(), uv__loop_close(), uv__loop_configure(), uv__loops_add(), uv__loops_remove(), uv__metrics_set_provider_entry_time(), uv__metrics_update_idle_time(), uv__next_timeout(), uv__pipe_read_data(), uv__pipe_read_ipc(), uv__pipe_write(), uv__pipe_write_data(), uv__pipe_write_ipc(), uv__platform_invalidate_fd(), uv__platform_loop_delete(), uv__platform_loop_init(), uv__poll(), uv__poll_io(), uv__poll_wine(), uv__pollfds_add(), uv__pollfds_del(), uv__pollfds_maybe_resize(), uv__pollfds_swap(), uv__print_handles(), uv__run_closing_handles(), uv__run_pending(), uv__run_timers(), uv__send(), uv__server_io(), uv__signal_event(), uv__signal_loop_cleanup(), uv__signal_loop_fork(), uv__signal_loop_once_init(), uv__slow_poll_process_poll_req(), uv__slow_poll_submit_poll_req(), uv__stdio_create(), uv__stream_init(), uv__udp_init_ex(), uv__udp_recv_start(), uv__udp_recv_stop(), uv__wake_all_loops(), uv__work_cancel(), uv__work_done(), uv__work_submit(), uv_async_close(), uv_async_init(), uv_async_send(), uv_backend_fd(), uv_backend_timeout(), uv_cancel(), uv_close(), uv_fs_event_close(), uv_fs_event_init(), uv_fs_event_queue_readdirchanges(), uv_fs_poll_init(), uv_fs_poll_start(), uv_fs_req_init(), uv_getaddrinfo(), uv_getnameinfo(), uv_insert_pending_req(), uv_loop_alive(), uv_loop_close(), uv_loop_configure(), uv_loop_delete(), uv_loop_fork(), uv_loop_get_data(), uv_loop_init(), uv_loop_new(), uv_loop_set_data(), uv_metrics_idle_time(), uv_now(), uv_pipe_accept(), uv_pipe_bind(), uv_pipe_close(), uv_pipe_connect(), uv_pipe_endgame(), uv_pipe_init(), uv_pipe_listen(), uv_pipe_queue_accept(), uv_pipe_queue_read(), uv_pipe_read_error_or_eof(), uv_pipe_read_start(), uv_pipe_writefile_thread_proc(), uv_pipe_zero_readfile_thread_proc(), uv_poll_close(), uv_poll_init(), uv_poll_init_socket(), uv_print_active_handles(), uv_print_all_handles(), uv_process_async_wakeup_req(), uv_process_close(), uv_process_endgames(), uv_process_fs_event_req(), uv_process_init(), uv_process_pipe_accept_req(), uv_process_pipe_connect_req(), uv_process_pipe_read_req(), uv_process_pipe_shutdown_req(), uv_process_pipe_write_req(), uv_process_poll_req(), uv_process_proc_exit(), uv_process_reqs(), uv_process_signal_req(), uv_process_tcp_accept_req(), uv_process_tcp_connect_req(), uv_process_tcp_read_req(), uv_process_tcp_write_req(), uv_process_tty_read_line_req(), uv_process_tty_read_raw_req(), uv_process_tty_read_req(), uv_process_tty_write_req(), uv_process_udp_recv_req(), uv_process_udp_send_req(), uv_queue_work(), uv_random(), uv_run(), uv_set_pipe_handle(), uv_setup_args(), uv_shutdown(), uv_signal_close(), uv_signal_init(), uv_spawn(), uv_stdio_pipe_server(), uv_stop(), uv_stream_init(), uv_tcp_accept(), uv_tcp_close(), uv_tcp_endgame(), uv_tcp_init(), uv_tcp_init_ex(), uv_tcp_listen(), uv_tcp_queue_accept(), uv_tcp_queue_read(), uv_tcp_read_start(), uv_tcp_set_socket(), uv_tcp_try_connect(), uv_tcp_write(), uv_timer_init(), uv_tty_endgame(), uv_tty_init(), uv_tty_line_read_thread(), uv_tty_post_raw_read(), uv_tty_queue_read(), uv_tty_queue_read_line(), uv_tty_queue_read_raw(), uv_tty_read_start(), uv_tty_write(), uv_udp_close(), uv_udp_init(), uv_udp_init_ex(), uv_udp_queue_recv(), uv_udp_set_socket(), UV_UNUSED(), uv_update_time(), uv_walk(), uv_want_endgame(), uv_write(), and uv_write2().

◆ options

Definition at line 9 of file main.c.

Referenced by invoke_cgi_script(), and main().