Commit f09ec0c2 authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by Andrei Vagin

compel: Handier API for stopping tasks for infection

Now we have two routines one of which needs a callback for
proc parsing. This is complex, but needed by CRIU. For others
let's have a single "stop" call that would to everything.

travis-ci: success for compel: Contrinue improving library
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent c7a717c1
......@@ -12,7 +12,7 @@
#define PARASITE_START_AREA_MIN (4096)
extern int compel_stop_task(int pid);
extern int compel_interrupt_task(int pid);
struct seize_task_status {
char state;
......
......@@ -62,7 +62,66 @@ static inline void close_safe(int *pfd)
}
}
static int parse_pid_status(int pid, struct seize_task_status *ss)
{
char aux[128];
FILE *f;
sprintf(aux, "/proc/%d/status", pid);
f = fopen(aux, "r");
if (!f)
return -1;
ss->ppid = -1; /* Not needed at this point */
ss->seccomp_mode = SECCOMP_MODE_DISABLED;
while (fgets(aux, sizeof(aux), f)) {
if (!strncmp(aux, "State:", 6)) {
ss->state = aux[7];
continue;
}
if (!strncmp(aux, "Seccomp:", 8)) {
if (sscanf(aux + 9, "%d", &ss->seccomp_mode) != 1)
goto err_parse;
continue;
}
if (!strncmp(aux, "ShdPnd:", 7)) {
if (sscanf(aux + 7, "%llx", &ss->shdpnd) != 1)
goto err_parse;
continue;
}
if (!strncmp(aux, "SigPnd:", 7)) {
if (sscanf(aux + 7, "%llx", &ss->sigpnd) != 1)
goto err_parse;
continue;
}
}
fclose(f);
return 0;
err_parse:
fclose(f);
return -1;
}
int compel_stop_task(int pid)
{
int ret;
struct seize_task_status ss;
ret = compel_interrupt_task(pid);
if (ret == 0)
ret = compel_wait_task(pid, -1, parse_pid_status, &ss);
return ret;
}
int compel_interrupt_task(int pid)
{
int ret;
......
......@@ -137,7 +137,7 @@ int cr_exec(int pid, char **opt)
goto out;
}
if (compel_stop_task(pid))
if (compel_interrupt_task(pid))
goto out;
/*
......
......@@ -130,7 +130,7 @@ static int seize_cgroup_tree(char *root_path, const char *state)
return -1;
}
if (!compel_stop_task(pid)) {
if (!compel_interrupt_task(pid)) {
pr_debug("SEIZE %d: success\n", pid);
processes_to_wait++;
} else if (state == frozen) {
......@@ -482,7 +482,7 @@ static int collect_children(struct pstree_item *item)
if (!opts.freeze_cgroup)
/* fails when meets a zombie */
compel_stop_task(pid);
compel_interrupt_task(pid);
creds = xzalloc(sizeof(*creds));
if (!creds) {
......@@ -713,7 +713,7 @@ static int collect_threads(struct pstree_item *item)
pr_info("\tSeizing %d's %d thread\n",
item->pid->real, pid);
if (!opts.freeze_cgroup && compel_stop_task(pid))
if (!opts.freeze_cgroup && compel_interrupt_task(pid))
continue;
ret = compel_wait_task(pid, item_ppid(item), parse_pid_status, &t_creds.s);
......@@ -846,7 +846,7 @@ int collect_pstree(void)
if (opts.freeze_cgroup && freeze_processes())
goto err;
if (!opts.freeze_cgroup && compel_stop_task(pid)) {
if (!opts.freeze_cgroup && compel_interrupt_task(pid)) {
set_cr_errno(ESRCH);
goto err;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment