Commit 18248ce4 authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by Andrei Vagin

infect: Move unseize_task() into infect.c

Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 754a2d95
......@@ -193,7 +193,7 @@ int cr_exec(int pid, char **opt)
out_cure:
compel_cure(ctl);
out_unseize:
unseize_task(pid, prev_state, prev_state);
compel_unseize_task(pid, prev_state, prev_state);
out:
return exit_code;
}
......@@ -16,6 +16,7 @@ struct seize_task_status {
extern int compel_wait_task(int pid, int ppid,
int (*get_status)(int pid, struct seize_task_status *),
struct seize_task_status *st);
extern int compel_unseize_task(pid_t pid, int orig_state, int state);
/*
* FIXME -- these should be mapped to pid.h's
......
......@@ -63,7 +63,6 @@
#define SI_EVENT(_si_code) (((_si_code) & 0xFFFF) >> 8)
extern int suspend_seccomp(pid_t pid);
extern int unseize_task(pid_t pid, int orig_state, int state);
extern int ptrace_peek_area(pid_t pid, void *dst, void *addr, long bytes);
extern int ptrace_poke_area(pid_t pid, void *src, void *addr, long bytes);
extern int ptrace_swap_area(pid_t pid, void *dst, void *src, long bytes);
......
......@@ -241,6 +241,41 @@ err:
return -1;
}
int compel_unseize_task(pid_t pid, int orig_st, int st)
{
pr_debug("\tUnseizing %d into %d\n", pid, st);
if (st == TASK_DEAD) {
kill(pid, SIGKILL);
return 0;
} else if (st == TASK_STOPPED) {
/*
* Task might have had STOP in queue. We detected such
* guy as TASK_STOPPED, but cleared signal to run the
* parasite code. hus after detach the task will become
* running. That said -- STOP everyone regardless of
* the initial state.
*/
kill(pid, SIGSTOP);
} else if (st == TASK_ALIVE) {
/*
* Same as in the comment above -- there might be a
* task with STOP in queue that would get lost after
* detach, so stop it again.
*/
if (orig_st == TASK_STOPPED)
kill(pid, SIGSTOP);
} else
pr_err("Unknown final state %d\n", st);
if (ptrace(PTRACE_DETACH, pid, NULL, NULL)) {
pr_perror("Unable to detach from %d", pid);
return -1;
}
return 0;
}
static int gen_parasite_saddr(struct sockaddr_un *saddr, int key)
{
int sun_len;
......
......@@ -23,41 +23,6 @@
#include "seccomp.h"
#include "cr_options.h"
int unseize_task(pid_t pid, int orig_st, int st)
{
pr_debug("\tUnseizing %d into %d\n", pid, st);
if (st == TASK_DEAD) {
kill(pid, SIGKILL);
return 0;
} else if (st == TASK_STOPPED) {
/*
* Task might have had STOP in queue. We detected such
* guy as TASK_STOPPED, but cleared signal to run the
* parasite code. hus after detach the task will become
* running. That said -- STOP everyone regardless of
* the initial state.
*/
kill(pid, SIGSTOP);
} else if (st == TASK_ALIVE) {
/*
* Same as in the comment above -- there might be a
* task with STOP in queue that would get lost after
* detach, so stop it again.
*/
if (orig_st == TASK_STOPPED)
kill(pid, SIGSTOP);
} else
pr_err("Unknown final state %d\n", st);
if (ptrace(PTRACE_DETACH, pid, NULL, NULL)) {
pr_perror("Unable to detach from %d", pid);
return -1;
}
return 0;
}
int suspend_seccomp(pid_t pid)
{
if (ptrace(PTRACE_SETOPTIONS, pid, NULL, PTRACE_O_SUSPEND_SECCOMP) < 0) {
......
......@@ -538,7 +538,7 @@ static void unseize_task_and_threads(const struct pstree_item *item, int st)
* the item->state is the state task was in when we seized one.
*/
unseize_task(item->pid->real, item->pid->state, st);
compel_unseize_task(item->pid->real, item->pid->state, st);
if (st == TASK_DEAD)
return;
......
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