66 #include <amxc/amxc.h>
73 #include <amxc/amxc_macros.h>
76 FILE*
__wrap_fopen(
const char* pathname,
const char* mode);
88 struct signalfd_siginfo fdsi;
92 sigaddset(&
mask, SIGALRM);
94 sigprocmask(SIG_BLOCK, &
mask, NULL);
96 sfd = signalfd(-1, &
mask, 0);
97 s = read(sfd, &fdsi,
sizeof(
struct signalfd_siginfo));
98 assert_int_equal(s,
sizeof(
struct signalfd_siginfo));
99 if(fdsi.ssi_signo == SIGALRM) {
100 printf(
"Got SIGALRM\n");
102 printf(
"Read unexpected signal\n");
107 printf(
"Handling events ");
118 amxc_array_append_data(cmd, strdup(
"sleep "));
119 amxc_array_append_data(cmd, strdup(
"10m"));
130 const char* f = amxc_string_get(&
path, 0);
132 if(strcmp(pathname, f) == 0) {
167 assert_non_null(ctrl);
168 assert_non_null(ctrl->
proc);
169 assert_non_null(ctrl->
timer);
170 assert_int_equal(amxc_var_type_of(&ctrl->
child_proc_pids), AMXC_VAR_ID_NULL);
192 amxc_var_init(&settings);
219 amxc_var_clean(&settings);
229 amxc_var_init(&settings);
245 amxc_var_clean(&settings);
255 amxc_var_init(&settings);
273 amxc_var_clean(&settings);
283 amxc_var_init(&settings);
299 amxc_var_clean(&settings);
306 amxc_string_init(&
path, 0);
311 amxc_var_init(&settings);
316 amxc_string_setf(&
path,
"/proc/%d/task/%d/children", ctrl->
proc->
pid, ctrl->
proc->
pid);
321 amxc_string_clean(&
path);
322 amxc_var_clean(&settings);
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_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.
int amxp_signal_read(void)
Reads from the amxp signal file descriptor.
bool amxp_subproc_is_running(const amxp_subproc_t *const subproc)
Checks if the child process is running.
amxp_timer_state_t amxp_timer_get_state(amxp_timer_t *timer)
Get the timer's state.
void amxp_timers_check(void)
Check all timers and call the callback function when the timer is in Timer expired state.
void amxp_timers_calculate(void)
Caclulates the remaining time of all timers.
Structure containing the child process control.
amxc_var_t child_proc_pids
int __wrap_kill(pid_t pid, int sig)
static int test_cmd_builder(amxc_array_t *cmd, UNUSED amxc_var_t *settings)
int __real_amxc_var_init(amxc_var_t *const var)
int __wrap_amxc_var_init(amxc_var_t *const var)
FILE * __real_fopen(const char *pathname, const char *mode)
void test_proc_is_stopped_when_timer_expires(UNUSED void **state)
ssize_t __real_getline(char **lineptr, size_t *n, FILE *stream)
static void read_sigalrm(void)
void test_proc_ctrl_start_stop(UNUSED void **state)
void test_proc_can_stop_children(UNUSED void **state)
void test_proc_ctrl_new_delete(UNUSED void **state)
ssize_t __wrap_getline(char **lineptr, size_t *n, FILE *stream)
void test_proc_can_stop_timer(UNUSED void **state)
static amxc_string_t path
void test_proc_is_stopped_when_timer_is_set_after_start(UNUSED void **state)
static void handle_events(void)
FILE * __wrap_fopen(const char *pathname, const char *mode)