60 #include <event2/event.h>
62 #include <amxc/amxc.h>
68 #define UNUSED __attribute__((unused))
70 static struct event_base*
base = NULL;
81 char buffer[1024] = {0};
82 ssize_t size = read(fd, buffer, 1023);
91 const amxc_var_t*
const data,
93 int pid = amxc_var_dyncast(int64_t, amxc_var_get_key(data,
"PID", AMXC_VAR_FLAG_DEFAULT));
94 printf(
"AMX Signal recieved : %s\n", sig_name);
95 printf(
" => process id = %d\n", pid);
96 event_base_loopbreak(
base);
102 struct event* sig_event = NULL;
104 int child_stdout_fd = -1;
105 struct event* child_stdout_event = NULL;
107 char* cmd[] = {
"ls",
"-la", NULL };
116 base = event_base_new();
125 event_add(sig_event, NULL);
128 child_stdout_event = event_new(
base, child_stdout_fd, EV_READ | EV_PERSIST,
child_stdout_cb, NULL);
129 event_add(child_stdout_event, NULL);
136 event_base_dispatch(
base);
142 event_del(sig_event);
143 event_free(sig_event);
144 event_del(child_stdout_event);
145 event_free(child_stdout_event);
146 event_base_free(
base);
Ambiorix signal manager and signal API header file.
Ambiorix slot API header file.
Ambiorix sub-proccess API header file.
Ambiorix Linux Signal Handling.
static void signal_cb(__attribute__((unused)) evutil_socket_t fd, __attribute__((unused)) short event, __attribute__((unused)) void *arg)
static void slot_proc_stop(const char *const sig_name, const amxc_var_t *const data, __attribute__((unused)) void *priv)
static struct event_base * base
static void child_stdout_cb(evutil_socket_t fd, __attribute__((unused)) short event, __attribute__((unused)) void *arg)
int amxp_slot_connect(amxp_signal_mngr_t *const sig_mngr, const char *const sig_name, const char *const expression, amxp_slot_fn_t fn, void *const priv)
Connects a slot (function) to a named signal of a signal manager.
int amxp_subproc_open_fd(amxp_subproc_t *subproc, int requested)
Opens standard file descriptor to the child process.
int amxp_subproc_new(amxp_subproc_t **subproc)
Constructor function, creates a new child process data structure.
int amxp_subproc_vstart(amxp_subproc_t *const subproc, char **argv)
Start a child process.
amxp_signal_mngr_t * amxp_subproc_get_sigmngr(const amxp_subproc_t *const subproc)
Get the Signal managers of the child process.
int amxp_subproc_delete(amxp_subproc_t **subproc)
Destructor function, deletes a child process data structure.
pid_t amxp_subproc_get_pid(const amxp_subproc_t *const subproc)
Get the PID of a child process.
int amxp_syssig_get_fd(void)
Returns a file descriptor that can be used in an eventloop.
int amxp_syssig_read(void)
Reads from the file descriptor.
Child process information structure.