2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-09-02 07:15:31 +00:00

Move seize related functions into seize.[ch]

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
Cyrill Gorcunov
2011-10-13 19:18:43 +04:00
parent c2bd177330
commit a0f463c27d
4 changed files with 98 additions and 47 deletions

View File

@@ -66,6 +66,7 @@ OBJS += cr-show.o
OBJS += util.o
OBJS += rbtree.o
OBJS += elf.o
OBJS += seize.o
DEPS := $(patsubst %.o,%.d,$(OBJS))

9
include/seize.h Normal file
View File

@@ -0,0 +1,9 @@
#ifndef SEIZE_H_
#define SEIZE_H_
#include <sys/ptrace.h>
int seize_task(pid_t pid);
int unseize_task(pid_t pid);
#endif /* SEIZE_H_ */

88
seize.c Normal file
View File

@@ -0,0 +1,88 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <stdbool.h>
#include <limits.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <limits.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <dirent.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/vfs.h>
#include <sys/ptrace.h>
#include <sys/user.h>
#include <sys/wait.h>
#include "compiler.h"
#include "types.h"
#include "list.h"
#include "util.h"
#include "seize.h"
#include "crtools.h"
int unseize_task(pid_t pid)
{
return ptrace(PTRACE_DETACH, pid, NULL, NULL);
}
/*
* This routine seizes task putting it into a special
* state where we can manipulate the task via ptrace
* inteface, and finally we can detach ptrace out of
* of it so the task would not know if it was saddled
* up with someone else.
*/
int seize_task(pid_t pid)
{
siginfo_t si;
int status;
int ret = 0;
jerr_rc(ptrace(PTRACE_SEIZE, pid, NULL,
(void *)(unsigned long)PTRACE_SEIZE_DEVEL), ret, err);
jerr_rc(ptrace(PTRACE_INTERRUPT, pid, NULL, NULL), ret, err);
ret = -10;
if (wait4(pid, &status, __WALL, NULL) != pid)
goto err;
ret = -20;
if (!WIFSTOPPED(status))
goto err;
jerr_rc(ptrace(PTRACE_GETSIGINFO, pid, NULL, &si), ret, err_cont);
ret = -30;
if ((si.si_code >> 8) != PTRACE_EVENT_STOP)
goto err_cont;
jerr_rc(ptrace(PTRACE_SETOPTIONS, pid, NULL,
(void *)(unsigned long)PTRACE_O_TRACEEXIT), ret, err_cont);
err:
return ret;
err_cont:
continue_task(pid);
goto err;
}

47
util.c
View File

@@ -187,53 +187,6 @@ void printk_vma(struct vma_area *vma_area)
((vma_area->vma.status & VMA_AREA_VDSO) ? "vdso" : "n")))));
}
int unseize_task(pid_t pid)
{
return ptrace(PTRACE_DETACH, pid, NULL, NULL);
}
/*
* This routine seizes task putting it into a special
* state where we can manipulate the task via ptrace
* inteface, and finally we can detach ptrace out of
* of it so the task would not know if it was saddled
* up with someone else.
*/
int seize_task(pid_t pid)
{
siginfo_t si;
int status;
int ret = 0;
jerr_rc(ptrace(PTRACE_SEIZE, pid, NULL,
(void *)(unsigned long)PTRACE_SEIZE_DEVEL), ret, err);
jerr_rc(ptrace(PTRACE_INTERRUPT, pid, NULL, NULL), ret, err);
ret = -10;
if (wait4(pid, &status, __WALL, NULL) != pid)
goto err;
ret = -20;
if (!WIFSTOPPED(status))
goto err;
jerr_rc(ptrace(PTRACE_GETSIGINFO, pid, NULL, &si), ret, err_cont);
ret = -30;
if ((si.si_code >> 8) != PTRACE_EVENT_STOP)
goto err_cont;
jerr_rc(ptrace(PTRACE_SETOPTIONS, pid, NULL,
(void *)(unsigned long)PTRACE_O_TRACEEXIT), ret, err_cont);
err:
return ret;
err_cont:
continue_task(pid);
goto err;
}
int close_safe(int *fd)
{
int ret = 0;