63 #include <sys/inotify.h>
68 #include <amxc/amxc.h>
69 #include <amxc/amxc_macros.h>
72 #define PROC_CHILDREN "/proc/%d/task/%d/children"
75 char* txt = (
char*) amxc_array_it_get_data(it);
84 amxc_var_set(uint32_t, &pid, proc->
proc->
pid);
92 UNUSED const amxc_var_t*
const event_data,
98 when_null(proc, leave);
100 amxc_var_set(uint32_t, &pid, proc->
proc->
pid);
107 amxc_var_clean(&pid);
119 amxc_string_init(&file, 0);
125 fp = fopen(amxc_string_get(&file, 0),
"r");
130 read = getline(&line, &len, fp);
145 amxc_string_clean(&file);
151 amxc_llist_t children;
153 amxc_llist_init(&children);
157 when_failed(retval, leave);
160 amxc_llist_iterate(it, (&children)) {
172 when_null(proc, leave);
173 when_null(cmd_build_fn, leave);
176 when_null(*proc, leave);
180 when_failed(amxc_array_init(&(*proc)->cmd, 10), leave);
181 when_failed(amxc_var_init(&(*proc)->child_proc_pids), leave);
183 (*proc)->build = cmd_build_fn;
190 ((proc != NULL) && (*proc != NULL))) {
193 amxc_array_clean(&(*proc)->cmd, NULL);
194 amxc_var_clean(&(*proc)->child_proc_pids);
202 when_null(proc, leave);
203 when_null(*proc, leave);
211 amxc_var_clean(&(*proc)->child_proc_pids);
222 when_null(proc, leave);
225 retval = proc->
build(&proc->
cmd, settings);
226 when_failed(retval, leave);
227 when_true(amxc_array_is_empty(&proc->
cmd), leave);
230 when_failed(retval, leave);
244 when_null(proc, leave);
265 when_null(proc, leave);
281 when_null(proc, leave);
285 pid_t pid = amxc_var_dyncast(uint32_t, child_pid);
296 when_null(proc, leave);
308 const amxc_llist_t* list = amxc_var_constcast(amxc_llist_t, &proc->
child_proc_pids);
309 retval = amxc_llist_size(list);
static int amxp_proc_ctrl_get_child_pids_scan_proc(amxp_proc_ctrl_t *proc)
static void amxp_proc_ctrl_timer_callback(UNUSED amxp_timer_t *const timer, void *data)
static void amxp_proc_ctrl_stopped(UNUSED const char *const event_name, UNUSED const amxc_var_t *const event_data, void *const priv)
static int amxp_proc_ctrl_get_child_pids_proc_children(amxp_proc_ctrl_t *proc)
static void amxp_proc_ctrl_free_char(amxc_array_it_t *it)
int amxp_proc_ctrl_stop(amxp_proc_ctrl_t *proc)
Stops the child process.
void amxp_proc_ctrl_set_active_duration(amxp_proc_ctrl_t *proc, uint32_t minutes)
Sets the active time durations.
int(* amxp_proc_ctrl_cmd_t)(amxc_array_t *cmd, amxc_var_t *settings)
Command builder callback function signature.
int amxp_proc_ctrl_new(amxp_proc_ctrl_t **proc, amxp_proc_ctrl_cmd_t cmd_build_fn)
Allocates and initializes an amxp_proc_ctrl_t.
int amxp_proc_ctrl_start(amxp_proc_ctrl_t *proc, uint32_t minutes, amxc_var_t *settings)
Launches the child process.
void amxp_proc_ctrl_delete(amxp_proc_ctrl_t **proc)
Clean-up and frees previously allocated memory.
void amxp_proc_ctrl_stop_childs(amxp_proc_ctrl_t *proc)
Stop all child processes of the child process.
int amxp_proc_ctrl_get_child_pids(amxp_proc_ctrl_t *proc)
Fetches the process ids of the children of the launched child process.
void amxp_proci_free_it(amxc_llist_it_t *it)
Delete a amxp_proc_info_t by it is linked list iterator.
int amxp_proci_findf(amxc_llist_t *result, const char *filter,...)
Build a linked list of running processes.
int amxp_sigmngr_emit_signal(const amxp_signal_mngr_t *const sig_mngr, const char *name, const amxc_var_t *const data)
Emits a signal.
int amxp_slot_disconnect(amxp_signal_mngr_t *const sig_mngr, const char *const sig_name, amxp_slot_fn_t fn)
Disconnects a slot from (a) signal(s).
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.
bool amxp_subproc_is_running(const amxp_subproc_t *const subproc)
Checks if the child process is running.
int amxp_subproc_new(amxp_subproc_t **subproc)
Constructor function, creates a new child process data structure.
int amxp_subproc_kill(const amxp_subproc_t *const subproc, const int sig)
Sends a Linux signal to the child process.
int amxp_subproc_wait(amxp_subproc_t *subproc, int timeout_msec)
Waits until the child process has stopped.
int amxp_subproc_astart(amxp_subproc_t *const subproc, amxc_array_t *cmd)
Start a 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_timer_start(amxp_timer_t *timer, unsigned int timeout_msec)
Starts or resets a timer.
int amxp_timer_stop(amxp_timer_t *timer)
Stops the timer.
void amxp_timer_delete(amxp_timer_t **timer)
Deletes a timer.
int amxp_timer_new(amxp_timer_t **timer, amxp_timer_cb_t cb, void *priv)
Allocate and initializes a new timer.
Structure containing the child process control.
amxp_proc_ctrl_cmd_t build
amxc_var_t child_proc_pids
Structure containing the process information.