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

infect: Move seize_catch_task -> compel_stop_task

Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 6dc2e2de
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "log.h" #include "log.h"
#include "util.h" #include "util.h"
#include "kerndat.h" #include "kerndat.h"
#include "infect.h"
struct syscall_exec_desc { struct syscall_exec_desc {
char *name; char *name;
...@@ -135,7 +136,7 @@ int cr_exec(int pid, char **opt) ...@@ -135,7 +136,7 @@ int cr_exec(int pid, char **opt)
goto out; goto out;
} }
if (seize_catch_task(pid)) if (compel_stop_task(pid))
goto out; goto out;
/* /*
......
#ifndef __COMPEL_INFECT_H__ #ifndef __COMPEL_INFECT_H__
#define __COMPEL_INFECT_H__ #define __COMPEL_INFECT_H__
extern int compel_stop_task(int pid);
#endif #endif
...@@ -70,7 +70,6 @@ struct seize_task_status { ...@@ -70,7 +70,6 @@ struct seize_task_status {
int seccomp_mode; int seccomp_mode;
}; };
extern int seize_catch_task(pid_t pid);
extern int seize_wait_task(pid_t pid, pid_t ppid, extern int seize_wait_task(pid_t pid, pid_t ppid,
int (*get_status)(int pid, struct seize_task_status *), int (*get_status)(int pid, struct seize_task_status *),
struct seize_task_status *st); struct seize_task_status *st);
......
#include <sys/ptrace.h>
#include <errno.h>
#include "log.h"
#include "infect.h" #include "infect.h"
int compel_stop_task(int pid)
{
int ret;
ret = ptrace(PTRACE_SEIZE, pid, NULL, 0);
if (ret) {
/*
* ptrace API doesn't allow to distinguish
* attaching to zombie from other errors.
* All errors will be handled in seize_wait_task().
*/
pr_warn("Unable to interrupt task: %d (%s)\n", pid, strerror(errno));
return ret;
}
/*
* If we SEIZE-d the task stop it before going
* and reading its stat from proc. Otherwise task
* may die _while_ we're doing it and we'll have
* inconsistent seize/state pair.
*
* If task dies after we seize it but before we
* do this interrupt, we'll notice it via proc.
*/
ret = ptrace(PTRACE_INTERRUPT, pid, NULL, NULL);
if (ret < 0) {
pr_warn("SEIZE %d: can't interrupt task: %s", pid, strerror(errno));
if (ptrace(PTRACE_DETACH, pid, NULL, NULL))
pr_perror("Unable to detach from %d", pid);
}
return ret;
}
...@@ -68,40 +68,6 @@ int suspend_seccomp(pid_t pid) ...@@ -68,40 +68,6 @@ int suspend_seccomp(pid_t pid)
return 0; return 0;
} }
int seize_catch_task(pid_t pid)
{
int ret;
ret = ptrace(PTRACE_SEIZE, pid, NULL, 0);
if (ret) {
/*
* ptrace API doesn't allow to distinguish
* attaching to zombie from other errors.
* All errors will be handled in seize_wait_task().
*/
pr_warn("Unable to interrupt task: %d (%s)\n", pid, strerror(errno));
return ret;
}
/*
* If we SEIZE-d the task stop it before going
* and reading its stat from proc. Otherwise task
* may die _while_ we're doing it and we'll have
* inconsistent seize/state pair.
*
* If task dies after we seize it but before we
* do this interrupt, we'll notice it via proc.
*/
ret = ptrace(PTRACE_INTERRUPT, pid, NULL, NULL);
if (ret < 0) {
pr_warn("SEIZE %d: can't interrupt task: %s", pid, strerror(errno));
if (ptrace(PTRACE_DETACH, pid, NULL, NULL))
pr_perror("Unable to detach from %d", pid);
}
return ret;
}
static int skip_sigstop(int pid, int nr_signals) static int skip_sigstop(int pid, int nr_signals)
{ {
int i, status, ret; int i, status, ret;
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "stats.h" #include "stats.h"
#include "xmalloc.h" #include "xmalloc.h"
#include "util.h" #include "util.h"
#include "infect.h"
#define NR_ATTEMPTS 5 #define NR_ATTEMPTS 5
...@@ -128,7 +129,7 @@ static int seize_cgroup_tree(char *root_path, const char *state) ...@@ -128,7 +129,7 @@ static int seize_cgroup_tree(char *root_path, const char *state)
return -1; return -1;
} }
if (!seize_catch_task(pid)) { if (!compel_stop_task(pid)) {
pr_debug("SEIZE %d: success\n", pid); pr_debug("SEIZE %d: success\n", pid);
processes_to_wait++; processes_to_wait++;
} else if (state == frozen) { } else if (state == frozen) {
...@@ -480,7 +481,7 @@ static int collect_children(struct pstree_item *item) ...@@ -480,7 +481,7 @@ static int collect_children(struct pstree_item *item)
if (!opts.freeze_cgroup) if (!opts.freeze_cgroup)
/* fails when meets a zombie */ /* fails when meets a zombie */
seize_catch_task(pid); compel_stop_task(pid);
creds = xzalloc(sizeof(*creds)); creds = xzalloc(sizeof(*creds));
if (!creds) { if (!creds) {
...@@ -711,7 +712,7 @@ static int collect_threads(struct pstree_item *item) ...@@ -711,7 +712,7 @@ static int collect_threads(struct pstree_item *item)
pr_info("\tSeizing %d's %d thread\n", pr_info("\tSeizing %d's %d thread\n",
item->pid->real, pid); item->pid->real, pid);
if (!opts.freeze_cgroup && seize_catch_task(pid)) if (!opts.freeze_cgroup && compel_stop_task(pid))
continue; continue;
ret = seize_wait_task(pid, item_ppid(item), parse_pid_status, &t_creds.s); ret = seize_wait_task(pid, item_ppid(item), parse_pid_status, &t_creds.s);
...@@ -844,7 +845,7 @@ int collect_pstree(void) ...@@ -844,7 +845,7 @@ int collect_pstree(void)
if (opts.freeze_cgroup && freeze_processes()) if (opts.freeze_cgroup && freeze_processes())
goto err; goto err;
if (!opts.freeze_cgroup && seize_catch_task(pid)) { if (!opts.freeze_cgroup && compel_stop_task(pid)) {
set_cr_errno(ESRCH); set_cr_errno(ESRCH);
goto err; 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